Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 function test_histedit_no_op {
20 local testroot=`test_init histedit_no_op`
22 local orig_commit=`git_show_head $testroot/repo`
24 echo "modified alpha on master" > $testroot/repo/alpha
25 (cd $testroot/repo && git rm -q beta)
26 echo "new file on master" > $testroot/repo/epsilon/new
27 (cd $testroot/repo && git add epsilon/new)
28 git_commit $testroot/repo -m "committing changes"
29 local old_commit1=`git_show_head $testroot/repo`
31 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
32 git_commit $testroot/repo -m "committing to zeta on master"
33 local old_commit2=`git_show_head $testroot/repo`
35 got diff -r $testroot/repo $orig_commit $old_commit2 \
36 > $testroot/diff.expected
38 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
39 ret="$?"
40 if [ "$ret" != "0" ]; then
41 test_done "$testroot" "$ret"
42 return 1
43 fi
45 echo "pick $old_commit1" > $testroot/histedit-script
46 echo "pick $old_commit2" >> $testroot/histedit-script
48 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
49 > $testroot/stdout)
51 local new_commit1=`git_show_parent_commit $testroot/repo`
52 local new_commit2=`git_show_head $testroot/repo`
54 local short_old_commit1=`trim_obj_id 28 $old_commit1`
55 local short_old_commit2=`trim_obj_id 28 $old_commit2`
56 local short_new_commit1=`trim_obj_id 28 $new_commit1`
57 local short_new_commit2=`trim_obj_id 28 $new_commit2`
59 echo "G alpha" > $testroot/stdout.expected
60 echo "D beta" >> $testroot/stdout.expected
61 echo "A epsilon/new" >> $testroot/stdout.expected
62 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
63 >> $testroot/stdout.expected
64 echo "G epsilon/zeta" >> $testroot/stdout.expected
65 echo -n "$short_old_commit2 -> $short_new_commit2: " \
66 >> $testroot/stdout.expected
67 echo "committing to zeta on master" >> $testroot/stdout.expected
68 echo "Switching work tree to refs/heads/master" \
69 >> $testroot/stdout.expected
71 cmp -s $testroot/stdout.expected $testroot/stdout
72 ret="$?"
73 if [ "$ret" != "0" ]; then
74 diff -u $testroot/stdout.expected $testroot/stdout
75 test_done "$testroot" "$ret"
76 return 1
77 fi
79 echo "modified alpha on master" > $testroot/content.expected
80 cat $testroot/wt/alpha > $testroot/content
81 cmp -s $testroot/content.expected $testroot/content
82 ret="$?"
83 if [ "$ret" != "0" ]; then
84 diff -u $testroot/content.expected $testroot/content
85 test_done "$testroot" "$ret"
86 return 1
87 fi
89 if [ -e $testroot/wt/beta ]; then
90 echo "removed file beta still exists on disk" >&2
91 test_done "$testroot" "1"
92 return 1
93 fi
95 echo "new file on master" > $testroot/content.expected
96 cat $testroot/wt/epsilon/new > $testroot/content
97 cmp -s $testroot/content.expected $testroot/content
98 ret="$?"
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/content.expected $testroot/content
101 test_done "$testroot" "$ret"
102 return 1
103 fi
105 (cd $testroot/wt && got status > $testroot/stdout)
107 echo -n > $testroot/stdout.expected
108 cmp -s $testroot/stdout.expected $testroot/stdout
109 ret="$?"
110 if [ "$ret" != "0" ]; then
111 diff -u $testroot/stdout.expected $testroot/stdout
112 test_done "$testroot" "$ret"
113 return 1
114 fi
116 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
117 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
118 echo "commit $new_commit1" >> $testroot/stdout.expected
119 echo "commit $orig_commit" >> $testroot/stdout.expected
120 cmp -s $testroot/stdout.expected $testroot/stdout
121 ret="$?"
122 if [ "$ret" != "0" ]; then
123 diff -u $testroot/stdout.expected $testroot/stdout
124 test_done "$testroot" "$ret"
125 return 1
126 fi
128 got diff -r $testroot/repo $orig_commit $new_commit2 \
129 > $testroot/diff
130 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
131 cmp -s $testroot/diff.expected $testroot/diff
132 ret="$?"
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/diff.expected $testroot/diff
135 fi
136 test_done "$testroot" "$ret"
139 function test_histedit_swap {
140 local testroot=`test_init histedit_swap`
142 local orig_commit=`git_show_head $testroot/repo`
144 echo "modified alpha on master" > $testroot/repo/alpha
145 (cd $testroot/repo && git rm -q beta)
146 echo "new file on master" > $testroot/repo/epsilon/new
147 (cd $testroot/repo && git add epsilon/new)
148 git_commit $testroot/repo -m "committing changes"
149 local old_commit1=`git_show_head $testroot/repo`
151 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
152 git_commit $testroot/repo -m "committing to zeta on master"
153 local old_commit2=`git_show_head $testroot/repo`
155 got diff -r $testroot/repo $orig_commit $old_commit2 \
156 > $testroot/diff.expected
158 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
159 ret="$?"
160 if [ "$ret" != "0" ]; then
161 test_done "$testroot" "$ret"
162 return 1
163 fi
165 echo "pick $old_commit2" > $testroot/histedit-script
166 echo "pick $old_commit1" >> $testroot/histedit-script
168 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
169 > $testroot/stdout)
171 local new_commit2=`git_show_parent_commit $testroot/repo`
172 local new_commit1=`git_show_head $testroot/repo`
174 local short_old_commit1=`trim_obj_id 28 $old_commit1`
175 local short_old_commit2=`trim_obj_id 28 $old_commit2`
176 local short_new_commit1=`trim_obj_id 28 $new_commit1`
177 local short_new_commit2=`trim_obj_id 28 $new_commit2`
179 echo "G epsilon/zeta" > $testroot/stdout.expected
180 echo -n "$short_old_commit2 -> $short_new_commit2: " \
181 >> $testroot/stdout.expected
182 echo "committing to zeta on master" >> $testroot/stdout.expected
183 echo "G alpha" >> $testroot/stdout.expected
184 echo "D beta" >> $testroot/stdout.expected
185 echo "A epsilon/new" >> $testroot/stdout.expected
186 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
187 >> $testroot/stdout.expected
188 echo "Switching work tree to refs/heads/master" \
189 >> $testroot/stdout.expected
191 cmp -s $testroot/stdout.expected $testroot/stdout
192 ret="$?"
193 if [ "$ret" != "0" ]; then
194 diff -u $testroot/stdout.expected $testroot/stdout
195 test_done "$testroot" "$ret"
196 return 1
197 fi
199 echo "modified alpha on master" > $testroot/content.expected
200 cat $testroot/wt/alpha > $testroot/content
201 cmp -s $testroot/content.expected $testroot/content
202 ret="$?"
203 if [ "$ret" != "0" ]; then
204 diff -u $testroot/content.expected $testroot/content
205 test_done "$testroot" "$ret"
206 return 1
207 fi
209 if [ -e $testroot/wt/beta ]; then
210 echo "removed file beta still exists on disk" >&2
211 test_done "$testroot" "1"
212 return 1
213 fi
215 echo "new file on master" > $testroot/content.expected
216 cat $testroot/wt/epsilon/new > $testroot/content
217 cmp -s $testroot/content.expected $testroot/content
218 ret="$?"
219 if [ "$ret" != "0" ]; then
220 diff -u $testroot/content.expected $testroot/content
221 test_done "$testroot" "$ret"
222 return 1
223 fi
225 (cd $testroot/wt && got status > $testroot/stdout)
227 echo -n > $testroot/stdout.expected
228 cmp -s $testroot/stdout.expected $testroot/stdout
229 ret="$?"
230 if [ "$ret" != "0" ]; then
231 diff -u $testroot/stdout.expected $testroot/stdout
232 test_done "$testroot" "$ret"
233 return 1
234 fi
236 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
237 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
238 echo "commit $new_commit2" >> $testroot/stdout.expected
239 echo "commit $orig_commit" >> $testroot/stdout.expected
240 cmp -s $testroot/stdout.expected $testroot/stdout
241 ret="$?"
242 if [ "$ret" != "0" ]; then
243 diff -u $testroot/stdout.expected $testroot/stdout
244 test_done "$testroot" "$ret"
245 return 1
246 fi
248 got diff -r $testroot/repo $orig_commit $new_commit1 \
249 > $testroot/diff
250 sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
251 cmp -s $testroot/diff.expected $testroot/diff
252 ret="$?"
253 if [ "$ret" != "0" ]; then
254 diff -u $testroot/diff.expected $testroot/diff
255 fi
256 test_done "$testroot" "$ret"
259 function test_histedit_drop {
260 local testroot=`test_init histedit_drop`
261 local orig_commit=`git_show_head $testroot/repo`
263 echo "modified alpha on master" > $testroot/repo/alpha
264 (cd $testroot/repo && git rm -q beta)
265 echo "new file on master" > $testroot/repo/epsilon/new
266 (cd $testroot/repo && git add epsilon/new)
267 git_commit $testroot/repo -m "committing changes"
268 local old_commit1=`git_show_head $testroot/repo`
270 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
271 git_commit $testroot/repo -m "committing to zeta on master"
272 local old_commit2=`git_show_head $testroot/repo`
274 got diff -r $testroot/repo $old_commit1 $old_commit2 \
275 > $testroot/diff.expected
277 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
278 ret="$?"
279 if [ "$ret" != "0" ]; then
280 test_done "$testroot" "$ret"
281 return 1
282 fi
284 echo "drop $old_commit1" > $testroot/histedit-script
285 echo "pick $old_commit2" >> $testroot/histedit-script
287 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
288 > $testroot/stdout)
290 local new_commit2=`git_show_head $testroot/repo`
292 local short_old_commit1=`trim_obj_id 28 $old_commit1`
293 local short_old_commit2=`trim_obj_id 28 $old_commit2`
294 local short_new_commit2=`trim_obj_id 28 $new_commit2`
296 echo "$short_old_commit1 -> drop commit: committing changes" \
297 > $testroot/stdout.expected
298 echo "G epsilon/zeta" >> $testroot/stdout.expected
299 echo -n "$short_old_commit2 -> $short_new_commit2: " \
300 >> $testroot/stdout.expected
301 echo "committing to zeta on master" >> $testroot/stdout.expected
302 echo "Switching work tree to refs/heads/master" \
303 >> $testroot/stdout.expected
305 cmp -s $testroot/stdout.expected $testroot/stdout
306 ret="$?"
307 if [ "$ret" != "0" ]; then
308 diff -u $testroot/stdout.expected $testroot/stdout
309 test_done "$testroot" "$ret"
310 return 1
311 fi
313 for f in alpha beta; do
314 echo "$f" > $testroot/content.expected
315 cat $testroot/wt/$f > $testroot/content
316 cmp -s $testroot/content.expected $testroot/content
317 ret="$?"
318 if [ "$ret" != "0" ]; then
319 diff -u $testroot/content.expected $testroot/content
320 test_done "$testroot" "$ret"
321 return 1
322 fi
323 done
325 if [ -e $testroot/wt/new ]; then
326 echo "file new exists on disk but should not" >&2
327 test_done "$testroot" "1"
328 return 1
329 fi
331 (cd $testroot/wt && got status > $testroot/stdout)
333 echo -n > $testroot/stdout.expected
334 cmp -s $testroot/stdout.expected $testroot/stdout
335 ret="$?"
336 if [ "$ret" != "0" ]; then
337 diff -u $testroot/stdout.expected $testroot/stdout
338 test_done "$testroot" "$ret"
339 return 1
340 fi
342 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
343 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
344 echo "commit $orig_commit" >> $testroot/stdout.expected
345 cmp -s $testroot/stdout.expected $testroot/stdout
346 ret="$?"
347 if [ "$ret" != "0" ]; then
348 diff -u $testroot/stdout.expected $testroot/stdout
349 test_done "$testroot" "$ret"
350 return 1
351 fi
353 got diff -r $testroot/repo $orig_commit $new_commit2 \
354 > $testroot/diff
355 sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
356 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
357 cmp -s $testroot/diff.expected $testroot/diff
358 ret="$?"
359 if [ "$ret" != "0" ]; then
360 diff -u $testroot/diff.expected $testroot/diff
361 fi
362 test_done "$testroot" "$ret"
365 function test_histedit_fold {
366 local testroot=`test_init histedit_fold`
368 local orig_commit=`git_show_head $testroot/repo`
370 echo "modified alpha on master" > $testroot/repo/alpha
371 (cd $testroot/repo && git rm -q beta)
372 echo "new file on master" > $testroot/repo/epsilon/new
373 (cd $testroot/repo && git add epsilon/new)
374 git_commit $testroot/repo -m "committing changes"
375 local old_commit1=`git_show_head $testroot/repo`
377 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
378 git_commit $testroot/repo -m "committing to zeta on master"
379 local old_commit2=`git_show_head $testroot/repo`
381 echo "modified delta on master" > $testroot/repo/gamma/delta
382 git_commit $testroot/repo -m "committing to delta on master"
383 local old_commit3=`git_show_head $testroot/repo`
385 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
386 ret="$?"
387 if [ "$ret" != "0" ]; then
388 test_done "$testroot" "$ret"
389 return 1
390 fi
392 echo "fold $old_commit1" > $testroot/histedit-script
393 echo "drop $old_commit2" >> $testroot/histedit-script
394 echo "pick $old_commit3" >> $testroot/histedit-script
395 echo "mesg committing folded changes" >> $testroot/histedit-script
397 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
398 > $testroot/stdout)
400 local new_commit1=`git_show_parent_commit $testroot/repo`
401 local new_commit2=`git_show_head $testroot/repo`
403 local short_old_commit1=`trim_obj_id 28 $old_commit1`
404 local short_old_commit2=`trim_obj_id 28 $old_commit2`
405 local short_old_commit3=`trim_obj_id 28 $old_commit3`
406 local short_new_commit1=`trim_obj_id 28 $new_commit1`
407 local short_new_commit2=`trim_obj_id 28 $new_commit2`
409 echo "G alpha" > $testroot/stdout.expected
410 echo "D beta" >> $testroot/stdout.expected
411 echo "A epsilon/new" >> $testroot/stdout.expected
412 echo "$short_old_commit1 -> fold commit: committing changes" \
413 >> $testroot/stdout.expected
414 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
415 echo "drop commit: committing to zeta on master" \
416 >> $testroot/stdout.expected
417 echo "G gamma/delta" >> $testroot/stdout.expected
418 echo -n "$short_old_commit3 -> $short_new_commit2: " \
419 >> $testroot/stdout.expected
420 echo "committing folded changes" >> $testroot/stdout.expected
421 echo "Switching work tree to refs/heads/master" \
422 >> $testroot/stdout.expected
424 cmp -s $testroot/stdout.expected $testroot/stdout
425 ret="$?"
426 if [ "$ret" != "0" ]; then
427 diff -u $testroot/stdout.expected $testroot/stdout
428 test_done "$testroot" "$ret"
429 return 1
430 fi
432 echo "modified alpha on master" > $testroot/content.expected
433 cat $testroot/wt/alpha > $testroot/content
434 cmp -s $testroot/content.expected $testroot/content
435 ret="$?"
436 if [ "$ret" != "0" ]; then
437 diff -u $testroot/content.expected $testroot/content
438 test_done "$testroot" "$ret"
439 return 1
440 fi
442 if [ -e $testroot/wt/beta ]; then
443 echo "removed file beta still exists on disk" >&2
444 test_done "$testroot" "1"
445 return 1
446 fi
448 echo "new file on master" > $testroot/content.expected
449 cat $testroot/wt/epsilon/new > $testroot/content
450 cmp -s $testroot/content.expected $testroot/content
451 ret="$?"
452 if [ "$ret" != "0" ]; then
453 diff -u $testroot/content.expected $testroot/content
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 (cd $testroot/wt && got status > $testroot/stdout)
460 echo -n > $testroot/stdout.expected
461 cmp -s $testroot/stdout.expected $testroot/stdout
462 ret="$?"
463 if [ "$ret" != "0" ]; then
464 diff -u $testroot/stdout.expected $testroot/stdout
465 test_done "$testroot" "$ret"
466 return 1
467 fi
469 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
470 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
471 echo "commit $orig_commit" >> $testroot/stdout.expected
472 cmp -s $testroot/stdout.expected $testroot/stdout
473 ret="$?"
474 if [ "$ret" != "0" ]; then
475 diff -u $testroot/stdout.expected $testroot/stdout
476 fi
477 test_done "$testroot" "$ret"
480 function test_histedit_edit {
481 local testroot=`test_init histedit_edit`
483 local orig_commit=`git_show_head $testroot/repo`
485 echo "modified alpha on master" > $testroot/repo/alpha
486 (cd $testroot/repo && git rm -q beta)
487 echo "new file on master" > $testroot/repo/epsilon/new
488 (cd $testroot/repo && git add epsilon/new)
489 git_commit $testroot/repo -m "committing changes"
490 local old_commit1=`git_show_head $testroot/repo`
492 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
493 git_commit $testroot/repo -m "committing to zeta on master"
494 local old_commit2=`git_show_head $testroot/repo`
496 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
497 ret="$?"
498 if [ "$ret" != "0" ]; then
499 test_done "$testroot" "$ret"
500 return 1
501 fi
503 echo "edit $old_commit1" > $testroot/histedit-script
504 echo "mesg committing changes" >> $testroot/histedit-script
505 echo "pick $old_commit2" >> $testroot/histedit-script
507 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
508 > $testroot/stdout)
510 local short_old_commit1=`trim_obj_id 28 $old_commit1`
511 local short_old_commit2=`trim_obj_id 28 $old_commit2`
513 echo "G alpha" > $testroot/stdout.expected
514 echo "D beta" >> $testroot/stdout.expected
515 echo "A epsilon/new" >> $testroot/stdout.expected
516 echo "Stopping histedit for amending commit $old_commit1" \
517 >> $testroot/stdout.expected
518 cmp -s $testroot/stdout.expected $testroot/stdout
519 ret="$?"
520 if [ "$ret" != "0" ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 test_done "$testroot" "$ret"
523 return 1
524 fi
526 echo "edited modified alpha on master" > $testroot/wt/alpha
528 (cd $testroot/wt && got histedit -c > $testroot/stdout)
530 local new_commit1=`git_show_parent_commit $testroot/repo`
531 local new_commit2=`git_show_head $testroot/repo`
533 local short_new_commit1=`trim_obj_id 28 $new_commit1`
534 local short_new_commit2=`trim_obj_id 28 $new_commit2`
536 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
537 > $testroot/stdout.expected
538 echo "G epsilon/zeta" >> $testroot/stdout.expected
539 echo -n "$short_old_commit2 -> $short_new_commit2: " \
540 >> $testroot/stdout.expected
541 echo "committing to zeta on master" >> $testroot/stdout.expected
542 echo "Switching work tree to refs/heads/master" \
543 >> $testroot/stdout.expected
545 cmp -s $testroot/stdout.expected $testroot/stdout
546 ret="$?"
547 if [ "$ret" != "0" ]; then
548 diff -u $testroot/stdout.expected $testroot/stdout
549 test_done "$testroot" "$ret"
550 return 1
551 fi
553 echo "edited modified alpha on master" > $testroot/content.expected
554 cat $testroot/wt/alpha > $testroot/content
555 cmp -s $testroot/content.expected $testroot/content
556 ret="$?"
557 if [ "$ret" != "0" ]; then
558 diff -u $testroot/content.expected $testroot/content
559 test_done "$testroot" "$ret"
560 return 1
561 fi
563 if [ -e $testroot/wt/beta ]; then
564 echo "removed file beta still exists on disk" >&2
565 test_done "$testroot" "1"
566 return 1
567 fi
569 echo "new file on master" > $testroot/content.expected
570 cat $testroot/wt/epsilon/new > $testroot/content
571 cmp -s $testroot/content.expected $testroot/content
572 ret="$?"
573 if [ "$ret" != "0" ]; then
574 diff -u $testroot/content.expected $testroot/content
575 test_done "$testroot" "$ret"
576 return 1
577 fi
579 (cd $testroot/wt && got status > $testroot/stdout)
581 echo -n > $testroot/stdout.expected
582 cmp -s $testroot/stdout.expected $testroot/stdout
583 ret="$?"
584 if [ "$ret" != "0" ]; then
585 diff -u $testroot/stdout.expected $testroot/stdout
586 test_done "$testroot" "$ret"
587 return 1
588 fi
590 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
591 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
592 echo "commit $new_commit1" >> $testroot/stdout.expected
593 echo "commit $orig_commit" >> $testroot/stdout.expected
594 cmp -s $testroot/stdout.expected $testroot/stdout
595 ret="$?"
596 if [ "$ret" != "0" ]; then
597 diff -u $testroot/stdout.expected $testroot/stdout
598 fi
599 test_done "$testroot" "$ret"
602 function test_histedit_fold_last_commit {
603 local testroot=`test_init histedit_fold_last_commit`
605 local orig_commit=`git_show_head $testroot/repo`
607 echo "modified alpha on master" > $testroot/repo/alpha
608 (cd $testroot/repo && git rm -q beta)
609 echo "new file on master" > $testroot/repo/epsilon/new
610 (cd $testroot/repo && git add epsilon/new)
611 git_commit $testroot/repo -m "committing changes"
612 local old_commit1=`git_show_head $testroot/repo`
614 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
615 git_commit $testroot/repo -m "committing to zeta on master"
616 local old_commit2=`git_show_head $testroot/repo`
618 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
619 ret="$?"
620 if [ "$ret" != "0" ]; then
621 test_done "$testroot" "$ret"
622 return 1
623 fi
625 echo "pick $old_commit1" > $testroot/histedit-script
626 echo "fold $old_commit2" >> $testroot/histedit-script
627 echo "mesg committing folded changes" >> $testroot/histedit-script
629 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
630 > $testroot/stdout 2> $testroot/stderr)
632 ret="$?"
633 if [ "$ret" == "0" ]; then
634 echo "histedit succeeded unexpectedly" >&2
635 test_done "$testroot" "1"
636 return 1
637 fi
639 echo "got: last commit in histedit script cannot be folded" \
640 > $testroot/stderr.expected
642 cmp -s $testroot/stderr.expected $testroot/stderr
643 ret="$?"
644 if [ "$ret" != "0" ]; then
645 diff -u $testroot/stderr.expected $testroot/stderr
646 fi
647 test_done "$testroot" "$ret"
650 function test_histedit_missing_commit {
651 local testroot=`test_init histedit_missing_commit`
653 local orig_commit=`git_show_head $testroot/repo`
655 echo "modified alpha on master" > $testroot/repo/alpha
656 (cd $testroot/repo && git rm -q beta)
657 echo "new file on master" > $testroot/repo/epsilon/new
658 (cd $testroot/repo && git add epsilon/new)
659 git_commit $testroot/repo -m "committing changes"
660 local old_commit1=`git_show_head $testroot/repo`
662 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
663 git_commit $testroot/repo -m "committing to zeta on master"
664 local old_commit2=`git_show_head $testroot/repo`
666 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
667 ret="$?"
668 if [ "$ret" != "0" ]; then
669 test_done "$testroot" "$ret"
670 return 1
671 fi
673 echo "pick $old_commit1" > $testroot/histedit-script
674 echo "mesg committing changes" >> $testroot/histedit-script
676 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
677 > $testroot/stdout 2> $testroot/stderr)
679 ret="$?"
680 if [ "$ret" == "0" ]; then
681 echo "histedit succeeded unexpectedly" >&2
682 test_done "$testroot" "1"
683 return 1
684 fi
686 echo "got: commit $old_commit2 missing from histedit script" \
687 > $testroot/stderr.expected
689 cmp -s $testroot/stderr.expected $testroot/stderr
690 ret="$?"
691 if [ "$ret" != "0" ]; then
692 diff -u $testroot/stderr.expected $testroot/stderr
693 fi
694 test_done "$testroot" "$ret"
697 function test_histedit_abort {
698 local testroot=`test_init histedit_abort`
700 local orig_commit=`git_show_head $testroot/repo`
702 echo "modified alpha on master" > $testroot/repo/alpha
703 (cd $testroot/repo && git rm -q beta)
704 echo "new file on master" > $testroot/repo/epsilon/new
705 (cd $testroot/repo && git add epsilon/new)
706 git_commit $testroot/repo -m "committing changes"
707 local old_commit1=`git_show_head $testroot/repo`
709 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
710 git_commit $testroot/repo -m "committing to zeta on master"
711 local old_commit2=`git_show_head $testroot/repo`
713 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
714 ret="$?"
715 if [ "$ret" != "0" ]; then
716 test_done "$testroot" "$ret"
717 return 1
718 fi
720 echo "edit $old_commit1" > $testroot/histedit-script
721 echo "mesg committing changes" >> $testroot/histedit-script
722 echo "pick $old_commit2" >> $testroot/histedit-script
724 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
725 > $testroot/stdout)
727 local short_old_commit1=`trim_obj_id 28 $old_commit1`
728 local short_old_commit2=`trim_obj_id 28 $old_commit2`
730 echo "G alpha" > $testroot/stdout.expected
731 echo "D beta" >> $testroot/stdout.expected
732 echo "A epsilon/new" >> $testroot/stdout.expected
733 echo "Stopping histedit for amending commit $old_commit1" \
734 >> $testroot/stdout.expected
735 cmp -s $testroot/stdout.expected $testroot/stdout
736 ret="$?"
737 if [ "$ret" != "0" ]; then
738 diff -u $testroot/stdout.expected $testroot/stdout
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 echo "edited modified alpha on master" > $testroot/wt/alpha
745 (cd $testroot/wt && got histedit -a > $testroot/stdout)
747 local new_commit1=`git_show_parent_commit $testroot/repo`
748 local new_commit2=`git_show_head $testroot/repo`
750 echo "Switching work tree to refs/heads/master" \
751 > $testroot/stdout.expected
752 echo "R alpha" >> $testroot/stdout.expected
753 echo "R beta" >> $testroot/stdout.expected
754 echo "R epsilon/new" >> $testroot/stdout.expected
755 echo "Histedit of refs/heads/master aborted" \
756 >> $testroot/stdout.expected
758 cmp -s $testroot/stdout.expected $testroot/stdout
759 ret="$?"
760 if [ "$ret" != "0" ]; then
761 diff -u $testroot/stdout.expected $testroot/stdout
762 test_done "$testroot" "$ret"
763 return 1
764 fi
766 for f in alpha beta; do
767 echo "$f" > $testroot/content.expected
768 cat $testroot/wt/$f > $testroot/content
769 cmp -s $testroot/content.expected $testroot/content
770 ret="$?"
771 if [ "$ret" != "0" ]; then
772 diff -u $testroot/content.expected $testroot/content
773 test_done "$testroot" "$ret"
774 return 1
775 fi
776 done
778 echo "new file on master" > $testroot/content.expected
779 cat $testroot/wt/epsilon/new > $testroot/content
780 cmp -s $testroot/content.expected $testroot/content
781 ret="$?"
782 if [ "$ret" != "0" ]; then
783 diff -u $testroot/content.expected $testroot/content
784 test_done "$testroot" "$ret"
785 return 1
786 fi
788 (cd $testroot/wt && got status > $testroot/stdout)
790 echo "? epsilon/new" > $testroot/stdout.expected
791 cmp -s $testroot/stdout.expected $testroot/stdout
792 ret="$?"
793 if [ "$ret" != "0" ]; then
794 diff -u $testroot/stdout.expected $testroot/stdout
795 test_done "$testroot" "$ret"
796 return 1
797 fi
799 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
800 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
801 echo "commit $new_commit1" >> $testroot/stdout.expected
802 echo "commit $orig_commit" >> $testroot/stdout.expected
803 cmp -s $testroot/stdout.expected $testroot/stdout
804 ret="$?"
805 if [ "$ret" != "0" ]; then
806 diff -u $testroot/stdout.expected $testroot/stdout
807 fi
808 test_done "$testroot" "$ret"
811 function test_histedit_path_prefix_drop {
812 local testroot=`test_init histedit_path_prefix_drop`
813 local orig_commit=`git_show_head $testroot/repo`
815 echo "modified zeta" > $testroot/repo/epsilon/zeta
816 git_commit $testroot/repo -m "changing zeta"
817 local old_commit1=`git_show_head $testroot/repo`
819 got checkout -c $orig_commit -p gamma $testroot/repo \
820 $testroot/wt > /dev/null
821 ret="$?"
822 if [ "$ret" != "0" ]; then
823 test_done "$testroot" "$ret"
824 return 1
825 fi
827 echo "drop $old_commit1" > $testroot/histedit-script
829 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
830 > $testroot/stdout 2> $testroot/stderr)
832 ret="$?"
833 if [ "$ret" == "0" ]; then
834 echo "histedit succeeded unexpectedly" >&2
835 test_done "$testroot" "1"
836 return 1
837 fi
839 echo -n "got: cannot edit branch history which contains changes " \
840 > $testroot/stderr.expected
841 echo "outside of this work tree's path prefix" \
842 >> $testroot/stderr.expected
844 cmp -s $testroot/stderr.expected $testroot/stderr
845 ret="$?"
846 if [ "$ret" != "0" ]; then
847 diff -u $testroot/stderr.expected $testroot/stderr
848 test_done "$testroot" "$ret"
849 return 1
850 fi
852 rm -rf $testroot/wt
853 got checkout -c $orig_commit -p epsilon $testroot/repo \
854 $testroot/wt > /dev/null
855 ret="$?"
856 if [ "$ret" != "0" ]; then
857 test_done "$testroot" "$ret"
858 return 1
859 fi
860 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
861 > $testroot/stdout)
863 local short_old_commit1=`trim_obj_id 28 $old_commit1`
864 local short_old_commit2=`trim_obj_id 28 $old_commit2`
866 echo "$short_old_commit1 -> drop commit: changing zeta" \
867 > $testroot/stdout.expected
868 echo "Switching work tree to refs/heads/master" \
869 >> $testroot/stdout.expected
871 cmp -s $testroot/stdout.expected $testroot/stdout
872 ret="$?"
873 if [ "$ret" != "0" ]; then
874 diff -u $testroot/stdout.expected $testroot/stdout
875 test_done "$testroot" "$ret"
876 return 1
877 fi
879 echo "zeta" > $testroot/content.expected
880 cat $testroot/wt/zeta > $testroot/content
881 cmp -s $testroot/content.expected $testroot/content
882 ret="$?"
883 if [ "$ret" != "0" ]; then
884 diff -u $testroot/content.expected $testroot/content
885 test_done "$testroot" "$ret"
886 return 1
887 fi
890 (cd $testroot/wt && got status > $testroot/stdout)
892 echo -n > $testroot/stdout.expected
893 cmp -s $testroot/stdout.expected $testroot/stdout
894 ret="$?"
895 if [ "$ret" != "0" ]; then
896 diff -u $testroot/stdout.expected $testroot/stdout
897 test_done "$testroot" "$ret"
898 return 1
899 fi
901 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
902 echo "commit $orig_commit (master)" > $testroot/stdout.expected
903 cmp -s $testroot/stdout.expected $testroot/stdout
904 ret="$?"
905 if [ "$ret" != "0" ]; then
906 diff -u $testroot/stdout.expected $testroot/stdout
907 fi
908 test_done "$testroot" "$ret"
911 function test_histedit_path_prefix_edit {
912 local testroot=`test_init histedit_path_prefix_edit`
913 local orig_commit=`git_show_head $testroot/repo`
915 echo "modified zeta" > $testroot/repo/epsilon/zeta
916 git_commit $testroot/repo -m "changing zeta"
917 local old_commit1=`git_show_head $testroot/repo`
919 got diff -r $testroot/repo $orig_commit $old_commit1 \
920 > $testroot/diff.expected
922 got checkout -c $orig_commit -p gamma $testroot/repo \
923 $testroot/wt > /dev/null
924 ret="$?"
925 if [ "$ret" != "0" ]; then
926 test_done "$testroot" "$ret"
927 return 1
928 fi
930 echo "edit $old_commit1" > $testroot/histedit-script
931 echo "mesg modified zeta" >> $testroot/histedit-script
933 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
934 > $testroot/stdout 2> $testroot/stderr)
936 ret="$?"
937 if [ "$ret" == "0" ]; then
938 echo "histedit succeeded unexpectedly" >&2
939 test_done "$testroot" "1"
940 return 1
941 fi
943 echo -n "got: cannot edit branch history which contains changes " \
944 > $testroot/stderr.expected
945 echo "outside of this work tree's path prefix" \
946 >> $testroot/stderr.expected
948 cmp -s $testroot/stderr.expected $testroot/stderr
949 ret="$?"
950 if [ "$ret" != "0" ]; then
951 diff -u $testroot/stderr.expected $testroot/stderr
952 test_done "$testroot" "$ret"
953 return 1
954 fi
956 rm -rf $testroot/wt
957 got checkout -c $orig_commit -p epsilon $testroot/repo \
958 $testroot/wt > /dev/null
959 ret="$?"
960 if [ "$ret" != "0" ]; then
961 test_done "$testroot" "$ret"
962 return 1
963 fi
964 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
965 > $testroot/stdout)
967 local short_old_commit1=`trim_obj_id 28 $old_commit1`
969 echo "G zeta" > $testroot/stdout.expected
970 echo "Stopping histedit for amending commit $old_commit1" \
971 >> $testroot/stdout.expected
972 cmp -s $testroot/stdout.expected $testroot/stdout
973 ret="$?"
974 if [ "$ret" != "0" ]; then
975 diff -u $testroot/stdout.expected $testroot/stdout
976 test_done "$testroot" "$ret"
977 return 1
978 fi
980 echo "modified zeta" > $testroot/content.expected
981 cat $testroot/wt/zeta > $testroot/content
982 cmp -s $testroot/content.expected $testroot/content
983 ret="$?"
984 if [ "$ret" != "0" ]; then
985 diff -u $testroot/content.expected $testroot/content
986 test_done "$testroot" "$ret"
987 return 1
988 fi
990 (cd $testroot/wt && got status > $testroot/stdout)
992 echo "M zeta"> $testroot/stdout.expected
993 cmp -s $testroot/stdout.expected $testroot/stdout
994 ret="$?"
995 if [ "$ret" != "0" ]; then
996 diff -u $testroot/stdout.expected $testroot/stdout
997 test_done "$testroot" "$ret"
998 return 1
999 fi
1001 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1003 local new_commit1=`git_show_head $testroot/repo`
1004 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1006 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1007 > $testroot/stdout.expected
1008 echo "modified zeta" >> $testroot/stdout.expected
1009 echo "Switching work tree to refs/heads/master" \
1010 >> $testroot/stdout.expected
1012 cmp -s $testroot/stdout.expected $testroot/stdout
1013 ret="$?"
1014 if [ "$ret" != "0" ]; then
1015 diff -u $testroot/stdout.expected $testroot/stdout
1016 test_done "$testroot" "$ret"
1017 return 1
1020 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1021 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1022 echo "commit $orig_commit" >> $testroot/stdout.expected
1023 cmp -s $testroot/stdout.expected $testroot/stdout
1024 ret="$?"
1025 if [ "$ret" != "0" ]; then
1026 diff -u $testroot/stdout.expected $testroot/stdout
1027 test_done "$testroot" "$ret"
1028 return 1
1031 got diff -r $testroot/repo $orig_commit $new_commit1 \
1032 > $testroot/diff
1033 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1034 cmp -s $testroot/diff.expected $testroot/diff
1035 ret="$?"
1036 if [ "$ret" != "0" ]; then
1037 diff -u $testroot/diff.expected $testroot/diff
1039 test_done "$testroot" "$ret"
1042 run_test test_histedit_no_op
1043 run_test test_histedit_swap
1044 run_test test_histedit_drop
1045 run_test test_histedit_fold
1046 run_test test_histedit_edit
1047 run_test test_histedit_fold_last_commit
1048 run_test test_histedit_missing_commit
1049 run_test test_histedit_abort
1050 run_test test_histedit_path_prefix_drop
1051 run_test test_histedit_path_prefix_edit