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 # test interaction of 'got stage' and histedit -c
529 (cd $testroot/wt && got stage alpha > /dev/null)
530 (cd $testroot/wt && got histedit -c > $testroot/stdout \
531 2> $testroot/stderr)
532 ret="$?"
533 if [ "$ret" == "0" ]; then
534 echo "histedit succeeded unexpectedly" >&2
535 test_done "$testroot" "1"
536 return 1
537 fi
538 echo -n "got: work tree contains files with staged changes; " \
539 > $testroot/stderr.expected
540 echo "these changes must be committed or unstaged first" \
541 >> $testroot/stderr.expected
542 cmp -s $testroot/stderr.expected $testroot/stderr
543 ret="$?"
544 if [ "$ret" != "0" ]; then
545 diff -u $testroot/stderr.expected $testroot/stderr
546 test_done "$testroot" "$ret"
547 return 1
548 fi
550 (cd $testroot/wt && got unstage alpha > /dev/null)
551 (cd $testroot/wt && got histedit -c > $testroot/stdout)
553 local new_commit1=`git_show_parent_commit $testroot/repo`
554 local new_commit2=`git_show_head $testroot/repo`
556 local short_new_commit1=`trim_obj_id 28 $new_commit1`
557 local short_new_commit2=`trim_obj_id 28 $new_commit2`
559 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
560 > $testroot/stdout.expected
561 echo "G epsilon/zeta" >> $testroot/stdout.expected
562 echo -n "$short_old_commit2 -> $short_new_commit2: " \
563 >> $testroot/stdout.expected
564 echo "committing to zeta on master" >> $testroot/stdout.expected
565 echo "Switching work tree to refs/heads/master" \
566 >> $testroot/stdout.expected
568 cmp -s $testroot/stdout.expected $testroot/stdout
569 ret="$?"
570 if [ "$ret" != "0" ]; then
571 diff -u $testroot/stdout.expected $testroot/stdout
572 test_done "$testroot" "$ret"
573 return 1
574 fi
576 echo "edited modified alpha on master" > $testroot/content.expected
577 cat $testroot/wt/alpha > $testroot/content
578 cmp -s $testroot/content.expected $testroot/content
579 ret="$?"
580 if [ "$ret" != "0" ]; then
581 diff -u $testroot/content.expected $testroot/content
582 test_done "$testroot" "$ret"
583 return 1
584 fi
586 if [ -e $testroot/wt/beta ]; then
587 echo "removed file beta still exists on disk" >&2
588 test_done "$testroot" "1"
589 return 1
590 fi
592 echo "new file on master" > $testroot/content.expected
593 cat $testroot/wt/epsilon/new > $testroot/content
594 cmp -s $testroot/content.expected $testroot/content
595 ret="$?"
596 if [ "$ret" != "0" ]; then
597 diff -u $testroot/content.expected $testroot/content
598 test_done "$testroot" "$ret"
599 return 1
600 fi
602 (cd $testroot/wt && got status > $testroot/stdout)
604 echo -n > $testroot/stdout.expected
605 cmp -s $testroot/stdout.expected $testroot/stdout
606 ret="$?"
607 if [ "$ret" != "0" ]; then
608 diff -u $testroot/stdout.expected $testroot/stdout
609 test_done "$testroot" "$ret"
610 return 1
611 fi
613 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
614 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
615 echo "commit $new_commit1" >> $testroot/stdout.expected
616 echo "commit $orig_commit" >> $testroot/stdout.expected
617 cmp -s $testroot/stdout.expected $testroot/stdout
618 ret="$?"
619 if [ "$ret" != "0" ]; then
620 diff -u $testroot/stdout.expected $testroot/stdout
621 fi
622 test_done "$testroot" "$ret"
625 function test_histedit_fold_last_commit {
626 local testroot=`test_init histedit_fold_last_commit`
628 local orig_commit=`git_show_head $testroot/repo`
630 echo "modified alpha on master" > $testroot/repo/alpha
631 (cd $testroot/repo && git rm -q beta)
632 echo "new file on master" > $testroot/repo/epsilon/new
633 (cd $testroot/repo && git add epsilon/new)
634 git_commit $testroot/repo -m "committing changes"
635 local old_commit1=`git_show_head $testroot/repo`
637 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
638 git_commit $testroot/repo -m "committing to zeta on master"
639 local old_commit2=`git_show_head $testroot/repo`
641 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
642 ret="$?"
643 if [ "$ret" != "0" ]; then
644 test_done "$testroot" "$ret"
645 return 1
646 fi
648 echo "pick $old_commit1" > $testroot/histedit-script
649 echo "fold $old_commit2" >> $testroot/histedit-script
650 echo "mesg committing folded changes" >> $testroot/histedit-script
652 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
653 > $testroot/stdout 2> $testroot/stderr)
655 ret="$?"
656 if [ "$ret" == "0" ]; then
657 echo "histedit succeeded unexpectedly" >&2
658 test_done "$testroot" "1"
659 return 1
660 fi
662 echo "got: last commit in histedit script cannot be folded" \
663 > $testroot/stderr.expected
665 cmp -s $testroot/stderr.expected $testroot/stderr
666 ret="$?"
667 if [ "$ret" != "0" ]; then
668 diff -u $testroot/stderr.expected $testroot/stderr
669 fi
670 test_done "$testroot" "$ret"
673 function test_histedit_missing_commit {
674 local testroot=`test_init histedit_missing_commit`
676 local orig_commit=`git_show_head $testroot/repo`
678 echo "modified alpha on master" > $testroot/repo/alpha
679 (cd $testroot/repo && git rm -q beta)
680 echo "new file on master" > $testroot/repo/epsilon/new
681 (cd $testroot/repo && git add epsilon/new)
682 git_commit $testroot/repo -m "committing changes"
683 local old_commit1=`git_show_head $testroot/repo`
685 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
686 git_commit $testroot/repo -m "committing to zeta on master"
687 local old_commit2=`git_show_head $testroot/repo`
689 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
690 ret="$?"
691 if [ "$ret" != "0" ]; then
692 test_done "$testroot" "$ret"
693 return 1
694 fi
696 echo "pick $old_commit1" > $testroot/histedit-script
697 echo "mesg committing changes" >> $testroot/histedit-script
699 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
700 > $testroot/stdout 2> $testroot/stderr)
702 ret="$?"
703 if [ "$ret" == "0" ]; then
704 echo "histedit succeeded unexpectedly" >&2
705 test_done "$testroot" "1"
706 return 1
707 fi
709 echo "got: commit $old_commit2 missing from histedit script" \
710 > $testroot/stderr.expected
712 cmp -s $testroot/stderr.expected $testroot/stderr
713 ret="$?"
714 if [ "$ret" != "0" ]; then
715 diff -u $testroot/stderr.expected $testroot/stderr
716 fi
717 test_done "$testroot" "$ret"
720 function test_histedit_abort {
721 local testroot=`test_init histedit_abort`
723 local orig_commit=`git_show_head $testroot/repo`
725 echo "modified alpha on master" > $testroot/repo/alpha
726 (cd $testroot/repo && git rm -q beta)
727 echo "new file on master" > $testroot/repo/epsilon/new
728 (cd $testroot/repo && git add epsilon/new)
729 git_commit $testroot/repo -m "committing changes"
730 local old_commit1=`git_show_head $testroot/repo`
732 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
733 git_commit $testroot/repo -m "committing to zeta on master"
734 local old_commit2=`git_show_head $testroot/repo`
736 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
737 ret="$?"
738 if [ "$ret" != "0" ]; then
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 echo "edit $old_commit1" > $testroot/histedit-script
744 echo "mesg committing changes" >> $testroot/histedit-script
745 echo "pick $old_commit2" >> $testroot/histedit-script
747 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
748 > $testroot/stdout)
750 local short_old_commit1=`trim_obj_id 28 $old_commit1`
751 local short_old_commit2=`trim_obj_id 28 $old_commit2`
753 echo "G alpha" > $testroot/stdout.expected
754 echo "D beta" >> $testroot/stdout.expected
755 echo "A epsilon/new" >> $testroot/stdout.expected
756 echo "Stopping histedit for amending commit $old_commit1" \
757 >> $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 echo "edited modified alpha on master" > $testroot/wt/alpha
768 (cd $testroot/wt && got histedit -a > $testroot/stdout)
770 local new_commit1=`git_show_parent_commit $testroot/repo`
771 local new_commit2=`git_show_head $testroot/repo`
773 echo "Switching work tree to refs/heads/master" \
774 > $testroot/stdout.expected
775 echo "R alpha" >> $testroot/stdout.expected
776 echo "R beta" >> $testroot/stdout.expected
777 echo "R epsilon/new" >> $testroot/stdout.expected
778 echo "Histedit of refs/heads/master aborted" \
779 >> $testroot/stdout.expected
781 cmp -s $testroot/stdout.expected $testroot/stdout
782 ret="$?"
783 if [ "$ret" != "0" ]; then
784 diff -u $testroot/stdout.expected $testroot/stdout
785 test_done "$testroot" "$ret"
786 return 1
787 fi
789 for f in alpha beta; do
790 echo "$f" > $testroot/content.expected
791 cat $testroot/wt/$f > $testroot/content
792 cmp -s $testroot/content.expected $testroot/content
793 ret="$?"
794 if [ "$ret" != "0" ]; then
795 diff -u $testroot/content.expected $testroot/content
796 test_done "$testroot" "$ret"
797 return 1
798 fi
799 done
801 echo "new file on master" > $testroot/content.expected
802 cat $testroot/wt/epsilon/new > $testroot/content
803 cmp -s $testroot/content.expected $testroot/content
804 ret="$?"
805 if [ "$ret" != "0" ]; then
806 diff -u $testroot/content.expected $testroot/content
807 test_done "$testroot" "$ret"
808 return 1
809 fi
811 (cd $testroot/wt && got status > $testroot/stdout)
813 echo "? epsilon/new" > $testroot/stdout.expected
814 cmp -s $testroot/stdout.expected $testroot/stdout
815 ret="$?"
816 if [ "$ret" != "0" ]; then
817 diff -u $testroot/stdout.expected $testroot/stdout
818 test_done "$testroot" "$ret"
819 return 1
820 fi
822 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
823 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
824 echo "commit $new_commit1" >> $testroot/stdout.expected
825 echo "commit $orig_commit" >> $testroot/stdout.expected
826 cmp -s $testroot/stdout.expected $testroot/stdout
827 ret="$?"
828 if [ "$ret" != "0" ]; then
829 diff -u $testroot/stdout.expected $testroot/stdout
830 fi
831 test_done "$testroot" "$ret"
834 function test_histedit_path_prefix_drop {
835 local testroot=`test_init histedit_path_prefix_drop`
836 local orig_commit=`git_show_head $testroot/repo`
838 echo "modified zeta" > $testroot/repo/epsilon/zeta
839 git_commit $testroot/repo -m "changing zeta"
840 local old_commit1=`git_show_head $testroot/repo`
842 got checkout -c $orig_commit -p gamma $testroot/repo \
843 $testroot/wt > /dev/null
844 ret="$?"
845 if [ "$ret" != "0" ]; then
846 test_done "$testroot" "$ret"
847 return 1
848 fi
850 echo "drop $old_commit1" > $testroot/histedit-script
852 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
853 > $testroot/stdout 2> $testroot/stderr)
855 ret="$?"
856 if [ "$ret" == "0" ]; then
857 echo "histedit succeeded unexpectedly" >&2
858 test_done "$testroot" "1"
859 return 1
860 fi
862 echo -n "got: cannot edit branch history which contains changes " \
863 > $testroot/stderr.expected
864 echo "outside of this work tree's path prefix" \
865 >> $testroot/stderr.expected
867 cmp -s $testroot/stderr.expected $testroot/stderr
868 ret="$?"
869 if [ "$ret" != "0" ]; then
870 diff -u $testroot/stderr.expected $testroot/stderr
871 test_done "$testroot" "$ret"
872 return 1
873 fi
875 rm -rf $testroot/wt
876 got checkout -c $orig_commit -p epsilon $testroot/repo \
877 $testroot/wt > /dev/null
878 ret="$?"
879 if [ "$ret" != "0" ]; then
880 test_done "$testroot" "$ret"
881 return 1
882 fi
883 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
884 > $testroot/stdout)
886 local short_old_commit1=`trim_obj_id 28 $old_commit1`
887 local short_old_commit2=`trim_obj_id 28 $old_commit2`
889 echo "$short_old_commit1 -> drop commit: changing zeta" \
890 > $testroot/stdout.expected
891 echo "Switching work tree to refs/heads/master" \
892 >> $testroot/stdout.expected
894 cmp -s $testroot/stdout.expected $testroot/stdout
895 ret="$?"
896 if [ "$ret" != "0" ]; then
897 diff -u $testroot/stdout.expected $testroot/stdout
898 test_done "$testroot" "$ret"
899 return 1
900 fi
902 echo "zeta" > $testroot/content.expected
903 cat $testroot/wt/zeta > $testroot/content
904 cmp -s $testroot/content.expected $testroot/content
905 ret="$?"
906 if [ "$ret" != "0" ]; then
907 diff -u $testroot/content.expected $testroot/content
908 test_done "$testroot" "$ret"
909 return 1
910 fi
913 (cd $testroot/wt && got status > $testroot/stdout)
915 echo -n > $testroot/stdout.expected
916 cmp -s $testroot/stdout.expected $testroot/stdout
917 ret="$?"
918 if [ "$ret" != "0" ]; then
919 diff -u $testroot/stdout.expected $testroot/stdout
920 test_done "$testroot" "$ret"
921 return 1
922 fi
924 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
925 echo "commit $orig_commit (master)" > $testroot/stdout.expected
926 cmp -s $testroot/stdout.expected $testroot/stdout
927 ret="$?"
928 if [ "$ret" != "0" ]; then
929 diff -u $testroot/stdout.expected $testroot/stdout
930 fi
931 test_done "$testroot" "$ret"
934 function test_histedit_path_prefix_edit {
935 local testroot=`test_init histedit_path_prefix_edit`
936 local orig_commit=`git_show_head $testroot/repo`
938 echo "modified zeta" > $testroot/repo/epsilon/zeta
939 git_commit $testroot/repo -m "changing zeta"
940 local old_commit1=`git_show_head $testroot/repo`
942 got diff -r $testroot/repo $orig_commit $old_commit1 \
943 > $testroot/diff.expected
945 got checkout -c $orig_commit -p gamma $testroot/repo \
946 $testroot/wt > /dev/null
947 ret="$?"
948 if [ "$ret" != "0" ]; then
949 test_done "$testroot" "$ret"
950 return 1
951 fi
953 echo "edit $old_commit1" > $testroot/histedit-script
954 echo "mesg modified zeta" >> $testroot/histedit-script
956 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
957 > $testroot/stdout 2> $testroot/stderr)
959 ret="$?"
960 if [ "$ret" == "0" ]; then
961 echo "histedit succeeded unexpectedly" >&2
962 test_done "$testroot" "1"
963 return 1
964 fi
966 echo -n "got: cannot edit branch history which contains changes " \
967 > $testroot/stderr.expected
968 echo "outside of this work tree's path prefix" \
969 >> $testroot/stderr.expected
971 cmp -s $testroot/stderr.expected $testroot/stderr
972 ret="$?"
973 if [ "$ret" != "0" ]; then
974 diff -u $testroot/stderr.expected $testroot/stderr
975 test_done "$testroot" "$ret"
976 return 1
977 fi
979 rm -rf $testroot/wt
980 got checkout -c $orig_commit -p epsilon $testroot/repo \
981 $testroot/wt > /dev/null
982 ret="$?"
983 if [ "$ret" != "0" ]; then
984 test_done "$testroot" "$ret"
985 return 1
986 fi
987 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
988 > $testroot/stdout)
990 local short_old_commit1=`trim_obj_id 28 $old_commit1`
992 echo "G zeta" > $testroot/stdout.expected
993 echo "Stopping histedit for amending commit $old_commit1" \
994 >> $testroot/stdout.expected
995 cmp -s $testroot/stdout.expected $testroot/stdout
996 ret="$?"
997 if [ "$ret" != "0" ]; then
998 diff -u $testroot/stdout.expected $testroot/stdout
999 test_done "$testroot" "$ret"
1000 return 1
1003 echo "modified zeta" > $testroot/content.expected
1004 cat $testroot/wt/zeta > $testroot/content
1005 cmp -s $testroot/content.expected $testroot/content
1006 ret="$?"
1007 if [ "$ret" != "0" ]; then
1008 diff -u $testroot/content.expected $testroot/content
1009 test_done "$testroot" "$ret"
1010 return 1
1013 (cd $testroot/wt && got status > $testroot/stdout)
1015 echo "M zeta"> $testroot/stdout.expected
1016 cmp -s $testroot/stdout.expected $testroot/stdout
1017 ret="$?"
1018 if [ "$ret" != "0" ]; then
1019 diff -u $testroot/stdout.expected $testroot/stdout
1020 test_done "$testroot" "$ret"
1021 return 1
1024 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1026 local new_commit1=`git_show_head $testroot/repo`
1027 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1029 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1030 > $testroot/stdout.expected
1031 echo "modified zeta" >> $testroot/stdout.expected
1032 echo "Switching work tree to refs/heads/master" \
1033 >> $testroot/stdout.expected
1035 cmp -s $testroot/stdout.expected $testroot/stdout
1036 ret="$?"
1037 if [ "$ret" != "0" ]; then
1038 diff -u $testroot/stdout.expected $testroot/stdout
1039 test_done "$testroot" "$ret"
1040 return 1
1043 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1044 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1045 echo "commit $orig_commit" >> $testroot/stdout.expected
1046 cmp -s $testroot/stdout.expected $testroot/stdout
1047 ret="$?"
1048 if [ "$ret" != "0" ]; then
1049 diff -u $testroot/stdout.expected $testroot/stdout
1050 test_done "$testroot" "$ret"
1051 return 1
1054 got diff -r $testroot/repo $orig_commit $new_commit1 \
1055 > $testroot/diff
1056 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1057 cmp -s $testroot/diff.expected $testroot/diff
1058 ret="$?"
1059 if [ "$ret" != "0" ]; then
1060 diff -u $testroot/diff.expected $testroot/diff
1062 test_done "$testroot" "$ret"
1065 function test_histedit_outside_refs_heads {
1066 local testroot=`test_init histedit_outside_refs_heads`
1067 local commit1=`git_show_head $testroot/repo`
1069 got checkout $testroot/repo $testroot/wt > /dev/null
1070 ret="$?"
1071 if [ "$ret" != "0" ]; then
1072 echo "got checkout failed unexpectedly"
1073 test_done "$testroot" "$ret"
1074 return 1
1077 echo "modified alpha" > $testroot/wt/alpha
1079 (cd $testroot/wt && got commit -m 'change alpha' \
1080 > $testroot/stdout 2> $testroot/stderr)
1081 ret="$?"
1082 if [ "$ret" != "0" ]; then
1083 echo "got commit failed unexpectedly" >&2
1084 test_done "$testroot" "1"
1085 return 1
1087 local commit2=`git_show_head $testroot/repo`
1089 got ref -r $testroot/repo -c master refs/remotes/origin/master
1090 ret="$?"
1091 if [ "$ret" != "0" ]; then
1092 echo "got ref failed unexpectedly" >&2
1093 test_done "$testroot" "1"
1094 return 1
1097 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1098 ret="$?"
1099 if [ "$ret" != "0" ]; then
1100 echo "got update failed unexpectedly"
1101 test_done "$testroot" "$ret"
1102 return 1
1105 echo "edit $commit2" > $testroot/histedit-script
1106 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1107 2> $testroot/stderr)
1109 echo -n "got: will not edit commit history of a branch outside the " \
1110 > $testroot/stderr.expected
1111 echo '"refs/heads/" reference namespace' \
1112 >> $testroot/stderr.expected
1113 cmp -s $testroot/stderr.expected $testroot/stderr
1114 ret="$?"
1115 if [ "$ret" != "0" ]; then
1116 diff -u $testroot/stderr.expected $testroot/stderr
1118 test_done "$testroot" "$ret"
1121 function test_histedit_fold_last_commit_swap {
1122 local testroot=`test_init histedit_fold_last_commit_swap`
1124 local orig_commit=`git_show_head $testroot/repo`
1126 echo "modified alpha on master" > $testroot/repo/alpha
1127 (cd $testroot/repo && git rm -q beta)
1128 echo "new file on master" > $testroot/repo/epsilon/new
1129 (cd $testroot/repo && git add epsilon/new)
1130 git_commit $testroot/repo -m "committing changes"
1131 local old_commit1=`git_show_head $testroot/repo`
1133 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1134 git_commit $testroot/repo -m "committing to zeta on master"
1135 local old_commit2=`git_show_head $testroot/repo`
1137 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1138 ret="$?"
1139 if [ "$ret" != "0" ]; then
1140 test_done "$testroot" "$ret"
1141 return 1
1144 # fold commit2 into commit1 (requires swapping commits)
1145 echo "fold $old_commit2" > $testroot/histedit-script
1146 echo "pick $old_commit1" >> $testroot/histedit-script
1147 echo "mesg committing folded changes" >> $testroot/histedit-script
1149 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1150 > $testroot/stdout 2> $testroot/stderr)
1152 ret="$?"
1153 if [ "$ret" != "0" ]; then
1154 echo "histedit failed unexpectedly" >&2
1155 test_done "$testroot" "$ret"
1156 return 1
1159 local new_commit=`git_show_head $testroot/repo`
1161 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1162 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1163 local short_new_commit=`trim_obj_id 28 $new_commit`
1165 echo "G epsilon/zeta" >> $testroot/stdout.expected
1166 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1167 >> $testroot/stdout.expected
1168 echo "on master" >> $testroot/stdout.expected
1169 echo "G alpha" >> $testroot/stdout.expected
1170 echo "D beta" >> $testroot/stdout.expected
1171 echo "A epsilon/new" >> $testroot/stdout.expected
1172 echo -n "$short_old_commit1 -> $short_new_commit: " \
1173 >> $testroot/stdout.expected
1174 echo "committing folded changes" >> $testroot/stdout.expected
1175 echo "Switching work tree to refs/heads/master" \
1176 >> $testroot/stdout.expected
1178 cmp -s $testroot/stdout.expected $testroot/stdout
1179 ret="$?"
1180 if [ "$ret" != "0" ]; then
1181 diff -u $testroot/stdout.expected $testroot/stdout
1183 test_done "$testroot" "$ret"
1186 function test_histedit_split_commit {
1187 local testroot=`test_init histedit_split_commit`
1189 local orig_commit=`git_show_head $testroot/repo`
1191 echo "modified alpha on master" > $testroot/repo/alpha
1192 (cd $testroot/repo && git rm -q beta)
1193 echo "new file on master" > $testroot/repo/epsilon/new
1194 (cd $testroot/repo && git add epsilon/new)
1195 git_commit $testroot/repo -m "committing changes 1"
1196 local old_commit1=`git_show_head $testroot/repo`
1197 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1199 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1200 git_commit $testroot/repo -m "committing changes 2"
1201 local old_commit2=`git_show_head $testroot/repo`
1202 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1204 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1205 ret="$?"
1206 if [ "$ret" != "0" ]; then
1207 test_done "$testroot" "$ret"
1208 return 1
1211 # split commit1 into commitA and commitB and commitC
1212 echo "e $old_commit1" > $testroot/histedit-script
1213 echo "p $old_commit2" >> $testroot/histedit-script
1215 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1216 > $testroot/stdout 2> $testroot/stderr)
1217 ret="$?"
1218 if [ "$ret" != "0" ]; then
1219 echo "histedit failed unexpectedly:" >&2
1220 cat $testroot/stderr >&2
1221 test_done "$testroot" "$ret"
1222 return 1
1225 echo "G alpha" > $testroot/stdout.expected
1226 echo "D beta" >> $testroot/stdout.expected
1227 echo "A epsilon/new" >> $testroot/stdout.expected
1228 echo "Stopping histedit for amending commit $old_commit1" \
1229 >> $testroot/stdout.expected
1231 cmp -s $testroot/stdout.expected $testroot/stdout
1232 ret="$?"
1233 if [ "$ret" != "0" ]; then
1234 diff -u $testroot/stdout.expected $testroot/stdout
1235 test_done "$testroot" "$ret"
1236 return 1
1239 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1240 ret="$?"
1241 if [ "$ret" != "0" ]; then
1242 echo "commit failed unexpectedly" >&2
1243 test_done "$testroot" "$ret"
1244 return 1
1247 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1248 ret="$?"
1249 if [ "$ret" != "0" ]; then
1250 echo "commit failed unexpectedly" >&2
1251 test_done "$testroot" "$ret"
1252 return 1
1255 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1256 ret="$?"
1257 if [ "$ret" != "0" ]; then
1258 echo "commit failed unexpectedly" >&2
1259 test_done "$testroot" "$ret"
1260 return 1
1263 (cd $testroot/wt && got histedit -c \
1264 > $testroot/stdout 2> $testroot/stderr)
1265 ret="$?"
1266 if [ "$ret" != "0" ]; then
1267 echo "histedit failed unexpectedly:" >&2
1268 cat $testroot/stderr >&2
1269 test_done "$testroot" "$ret"
1270 return 1
1272 local new_commit2=`git_show_head $testroot/repo`
1273 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1275 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1276 > $testroot/stdout.expected
1277 echo "G epsilon/zeta" >> $testroot/stdout.expected
1278 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1279 >> $testroot/stdout.expected
1280 echo "Switching work tree to refs/heads/master" \
1281 >> $testroot/stdout.expected
1283 cmp -s $testroot/stdout.expected $testroot/stdout
1284 ret="$?"
1285 if [ "$ret" != "0" ]; then
1286 diff -u $testroot/stdout.expected $testroot/stdout
1288 test_done "$testroot" "$ret"
1292 function test_histedit_duplicate_commit_in_script {
1293 local testroot=`test_init histedit_duplicate_commit_in_script`
1295 local orig_commit=`git_show_head $testroot/repo`
1297 echo "modified alpha on master" > $testroot/repo/alpha
1298 (cd $testroot/repo && git rm -q beta)
1299 echo "new file on master" > $testroot/repo/epsilon/new
1300 (cd $testroot/repo && git add epsilon/new)
1301 git_commit $testroot/repo -m "committing changes 1"
1302 local old_commit1=`git_show_head $testroot/repo`
1304 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1305 git_commit $testroot/repo -m "committing changes 2"
1306 local old_commit2=`git_show_head $testroot/repo`
1308 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1309 ret="$?"
1310 if [ "$ret" != "0" ]; then
1311 test_done "$testroot" "$ret"
1312 return 1
1315 # This histedit script lists commit1 more than once
1316 echo "p $old_commit1" > $testroot/histedit-script
1317 echo "p $old_commit1" >> $testroot/histedit-script
1318 echo "p $old_commit2" >> $testroot/histedit-script
1320 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1321 > $testroot/stdout 2> $testroot/stderr)
1322 ret="$?"
1323 if [ "$ret" == "0" ]; then
1324 echo "histedit succeeded unexpectedly:" >&2
1325 cat $testroot/stdout >&2
1326 test_done "$testroot" "$ret"
1327 return 1
1330 echo -n "got: commit $old_commit1 is listed more than once " \
1331 > $testroot/stderr.expected
1332 echo "in histedit script" >> $testroot/stderr.expected
1334 cmp -s $testroot/stderr.expected $testroot/stderr
1335 ret="$?"
1336 if [ "$ret" != "0" ]; then
1337 diff -u $testroot/stderr.expected $testroot/stderr
1339 test_done "$testroot" "$ret"
1343 run_test test_histedit_no_op
1344 run_test test_histedit_swap
1345 run_test test_histedit_drop
1346 run_test test_histedit_fold
1347 run_test test_histedit_edit
1348 run_test test_histedit_fold_last_commit
1349 run_test test_histedit_missing_commit
1350 run_test test_histedit_abort
1351 run_test test_histedit_path_prefix_drop
1352 run_test test_histedit_path_prefix_edit
1353 run_test test_histedit_outside_refs_heads
1354 run_test test_histedit_fold_last_commit_swap
1355 run_test test_histedit_split_commit
1356 run_test test_histedit_duplicate_commit_in_script