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 test_histedit_no_op() {
20 local testroot=`test_init histedit_no_op`
22 local orig_commit=`git_show_head $testroot/repo`
23 local orig_author_time=`git_show_author_time $testroot/repo`
25 echo "modified alpha on master" > $testroot/repo/alpha
26 (cd $testroot/repo && git rm -q beta)
27 echo "new file on master" > $testroot/repo/epsilon/new
28 (cd $testroot/repo && git add epsilon/new)
29 git_commit $testroot/repo -m "committing changes"
30 local old_commit1=`git_show_head $testroot/repo`
31 local old_author_time1=`git_show_author_time $testroot/repo`
33 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
34 git_commit $testroot/repo -m "committing to zeta on master"
35 local old_commit2=`git_show_head $testroot/repo`
36 local old_author_time2=`git_show_author_time $testroot/repo`
38 got diff -r $testroot/repo $orig_commit $old_commit2 \
39 > $testroot/diff.expected
41 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
42 ret=$?
43 if [ $ret -ne 0 ]; then
44 test_done "$testroot" "$ret"
45 return 1
46 fi
48 echo "pick $old_commit1" > $testroot/histedit-script
49 echo "pick $old_commit2" >> $testroot/histedit-script
51 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
52 > $testroot/stdout)
54 local new_commit1=`git_show_parent_commit $testroot/repo`
55 local new_commit2=`git_show_head $testroot/repo`
56 local new_author_time2=`git_show_author_time $testroot/repo`
58 local short_old_commit1=`trim_obj_id 28 $old_commit1`
59 local short_old_commit2=`trim_obj_id 28 $old_commit2`
60 local short_new_commit1=`trim_obj_id 28 $new_commit1`
61 local short_new_commit2=`trim_obj_id 28 $new_commit2`
63 echo "G alpha" > $testroot/stdout.expected
64 echo "D beta" >> $testroot/stdout.expected
65 echo "A epsilon/new" >> $testroot/stdout.expected
66 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
67 >> $testroot/stdout.expected
68 echo "G epsilon/zeta" >> $testroot/stdout.expected
69 echo -n "$short_old_commit2 -> $short_new_commit2: " \
70 >> $testroot/stdout.expected
71 echo "committing to zeta on master" >> $testroot/stdout.expected
72 echo "Switching work tree to refs/heads/master" \
73 >> $testroot/stdout.expected
75 cmp -s $testroot/stdout.expected $testroot/stdout
76 ret=$?
77 if [ $ret -ne 0 ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
80 return 1
81 fi
83 echo "modified alpha on master" > $testroot/content.expected
84 cat $testroot/wt/alpha > $testroot/content
85 cmp -s $testroot/content.expected $testroot/content
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 diff -u $testroot/content.expected $testroot/content
89 test_done "$testroot" "$ret"
90 return 1
91 fi
93 if [ -e $testroot/wt/beta ]; then
94 echo "removed file beta still exists on disk" >&2
95 test_done "$testroot" "1"
96 return 1
97 fi
99 echo "new file on master" > $testroot/content.expected
100 cat $testroot/wt/epsilon/new > $testroot/content
101 cmp -s $testroot/content.expected $testroot/content
102 ret=$?
103 if [ $ret -ne 0 ]; then
104 diff -u $testroot/content.expected $testroot/content
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 (cd $testroot/wt && got status > $testroot/stdout)
111 echo -n > $testroot/stdout.expected
112 cmp -s $testroot/stdout.expected $testroot/stdout
113 ret=$?
114 if [ $ret -ne 0 ]; then
115 diff -u $testroot/stdout.expected $testroot/stdout
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
121 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
122 echo "commit $new_commit1" >> $testroot/stdout.expected
123 echo "commit $orig_commit" >> $testroot/stdout.expected
124 cmp -s $testroot/stdout.expected $testroot/stdout
125 ret=$?
126 if [ $ret -ne 0 ]; then
127 diff -u $testroot/stdout.expected $testroot/stdout
128 test_done "$testroot" "$ret"
129 return 1
130 fi
132 got diff -r $testroot/repo $orig_commit $new_commit2 \
133 > $testroot/diff
134 sed -i '' -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
135 cmp -s $testroot/diff.expected $testroot/diff
136 ret=$?
137 if [ $ret -ne 0 ]; then
138 diff -u $testroot/diff.expected $testroot/diff
139 test_done "$testroot" "$ret"
140 return 1
141 fi
143 (cd $testroot/wt && got update > $testroot/stdout)
145 echo 'Already up-to-date' > $testroot/stdout.expected
146 cmp -s $testroot/stdout.expected $testroot/stdout
147 ret=$?
148 if [ $ret -ne 0 ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
150 test_done "$testroot" "$ret"
151 return 1
152 fi
154 # We should have a backup of old commits
155 (cd $testroot/repo && got histedit -l > $testroot/stdout)
156 d_orig1=`date -u -d "@$old_author_time1" +"%G-%m-%d"`
158 local prev_LC_TIME="$LC_TIME"
159 export LC_TIME=C
160 d_orig2=`date -u -d "@$old_author_time2" +"%a %b %e %X %Y UTC"`
161 export LC_TIME="$prev_LC_TIME"
162 d_new2=`date -u -d "@$new_author_time2" +"%G-%m-%d"`
163 d_orig=`date -u -d "@$orig_author_time" +"%G-%m-%d"`
164 cat > $testroot/stdout.expected <<EOF
165 -----------------------------------------------
166 commit $old_commit2 (formerly master)
167 from: $GOT_AUTHOR
168 date: $d_orig2
170 committing to zeta on master
172 has become commit $new_commit2 (master)
173 $d_new2 $GOT_AUTHOR_11 committing to zeta on master
174 EOF
176 local is_forked=true d_fork fork_commit fork_commit_msg
178 if [ "$old_commit1" = "$new_commit1" ]; then
179 if [ "$old_commit2" = "$new_commit2" ]; then
180 is_forked=false
181 else
182 d_fork=$d_orig1
183 fork_commit=$new_commit1
184 fork_commit_msg="committing changes"
185 fi
186 else
187 d_fork=$d_orig
188 fork_commit=$orig_commit
189 fork_commit_msg="adding the test tree"
190 fi
192 $is_forked && cat >> $testroot/stdout.expected <<EOF
193 history forked at $fork_commit
194 $d_fork $GOT_AUTHOR_11 $fork_commit_msg
195 EOF
197 cmp -s $testroot/stdout.expected $testroot/stdout
198 ret=$?
199 if [ $ret -ne 0 ]; then
200 diff -u $testroot/stdout.expected $testroot/stdout
201 test_done "$testroot" "$ret"
202 return 1
203 fi
205 (cd $testroot/repo && got histedit -X master \
206 > $testroot/stdout 2> $testroot/stderr)
207 echo -n "Deleted refs/got/backup/histedit/master/$new_commit2: " \
208 > $testroot/stdout.expected
209 echo "$old_commit2" >> $testroot/stdout.expected
210 echo -n > $testroot/stderr.expected
211 cmp -s $testroot/stdout.expected $testroot/stdout
212 ret=$?
213 if [ $ret -ne 0 ]; then
214 diff -u $testroot/stdout.expected $testroot/stdout
215 test_done "$testroot" "$ret"
216 return 1
217 fi
218 cmp -s $testroot/stderr.expected $testroot/stderr
219 ret=$?
220 if [ $ret -ne 0 ]; then
221 diff -u $testroot/stderr.expected $testroot/stderr
222 test_done "$testroot" "$ret"
223 return 1
224 fi
226 (cd $testroot/repo && got histedit -l > $testroot/stdout)
227 echo -n > $testroot/stdout.expected
228 cmp -s $testroot/stdout.expected $testroot/stdout
229 ret=$?
230 if [ $ret -ne 0 ]; then
231 diff -u $testroot/stdout.expected $testroot/stdout
232 fi
233 test_done "$testroot" "$ret"
236 test_histedit_swap() {
237 local testroot=`test_init histedit_swap`
239 local orig_commit=`git_show_head $testroot/repo`
241 echo "modified alpha on master" > $testroot/repo/alpha
242 (cd $testroot/repo && git rm -q beta)
243 echo "new file on master" > $testroot/repo/epsilon/new
244 (cd $testroot/repo && git add epsilon/new)
245 git_commit $testroot/repo -m "committing changes"
246 local old_commit1=`git_show_head $testroot/repo`
248 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
249 git_commit $testroot/repo -m "committing to zeta on master"
250 local old_commit2=`git_show_head $testroot/repo`
252 got diff -r $testroot/repo $orig_commit $old_commit2 \
253 > $testroot/diff.expected
255 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
256 ret=$?
257 if [ $ret -ne 0 ]; then
258 test_done "$testroot" "$ret"
259 return 1
260 fi
262 echo "pick $old_commit2" > $testroot/histedit-script
263 echo "pick $old_commit1" >> $testroot/histedit-script
265 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
266 > $testroot/stdout)
268 local new_commit2=`git_show_parent_commit $testroot/repo`
269 local new_commit1=`git_show_head $testroot/repo`
271 local short_old_commit1=`trim_obj_id 28 $old_commit1`
272 local short_old_commit2=`trim_obj_id 28 $old_commit2`
273 local short_new_commit1=`trim_obj_id 28 $new_commit1`
274 local short_new_commit2=`trim_obj_id 28 $new_commit2`
276 echo "G epsilon/zeta" > $testroot/stdout.expected
277 echo -n "$short_old_commit2 -> $short_new_commit2: " \
278 >> $testroot/stdout.expected
279 echo "committing to zeta on master" >> $testroot/stdout.expected
280 echo "G alpha" >> $testroot/stdout.expected
281 echo "D beta" >> $testroot/stdout.expected
282 echo "A epsilon/new" >> $testroot/stdout.expected
283 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
284 >> $testroot/stdout.expected
285 echo "Switching work tree to refs/heads/master" \
286 >> $testroot/stdout.expected
288 cmp -s $testroot/stdout.expected $testroot/stdout
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 diff -u $testroot/stdout.expected $testroot/stdout
292 test_done "$testroot" "$ret"
293 return 1
294 fi
296 echo "modified alpha on master" > $testroot/content.expected
297 cat $testroot/wt/alpha > $testroot/content
298 cmp -s $testroot/content.expected $testroot/content
299 ret=$?
300 if [ $ret -ne 0 ]; then
301 diff -u $testroot/content.expected $testroot/content
302 test_done "$testroot" "$ret"
303 return 1
304 fi
306 if [ -e $testroot/wt/beta ]; then
307 echo "removed file beta still exists on disk" >&2
308 test_done "$testroot" "1"
309 return 1
310 fi
312 echo "new file on master" > $testroot/content.expected
313 cat $testroot/wt/epsilon/new > $testroot/content
314 cmp -s $testroot/content.expected $testroot/content
315 ret=$?
316 if [ $ret -ne 0 ]; then
317 diff -u $testroot/content.expected $testroot/content
318 test_done "$testroot" "$ret"
319 return 1
320 fi
322 (cd $testroot/wt && got status > $testroot/stdout)
324 echo -n > $testroot/stdout.expected
325 cmp -s $testroot/stdout.expected $testroot/stdout
326 ret=$?
327 if [ $ret -ne 0 ]; then
328 diff -u $testroot/stdout.expected $testroot/stdout
329 test_done "$testroot" "$ret"
330 return 1
331 fi
333 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
334 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
335 echo "commit $new_commit2" >> $testroot/stdout.expected
336 echo "commit $orig_commit" >> $testroot/stdout.expected
337 cmp -s $testroot/stdout.expected $testroot/stdout
338 ret=$?
339 if [ $ret -ne 0 ]; then
340 diff -u $testroot/stdout.expected $testroot/stdout
341 test_done "$testroot" "$ret"
342 return 1
343 fi
345 got diff -r $testroot/repo $orig_commit $new_commit1 \
346 > $testroot/diff
347 sed -i '' -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
348 cmp -s $testroot/diff.expected $testroot/diff
349 ret=$?
350 if [ $ret -ne 0 ]; then
351 diff -u $testroot/diff.expected $testroot/diff
352 fi
353 test_done "$testroot" "$ret"
356 test_histedit_drop() {
357 local testroot=`test_init histedit_drop`
358 local orig_commit=`git_show_head $testroot/repo`
360 echo "modified alpha on master" > $testroot/repo/alpha
361 (cd $testroot/repo && git rm -q beta)
362 echo "new file on master" > $testroot/repo/epsilon/new
363 (cd $testroot/repo && git add epsilon/new)
364 git_commit $testroot/repo -m "committing changes"
365 local old_commit1=`git_show_head $testroot/repo`
367 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
368 git_commit $testroot/repo -m "committing to zeta on master"
369 local old_commit2=`git_show_head $testroot/repo`
371 got diff -r $testroot/repo $old_commit1 $old_commit2 \
372 > $testroot/diff.expected
374 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
375 ret=$?
376 if [ $ret -ne 0 ]; then
377 test_done "$testroot" "$ret"
378 return 1
379 fi
381 echo "drop $old_commit1" > $testroot/histedit-script
382 echo "pick $old_commit2" >> $testroot/histedit-script
384 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
385 > $testroot/stdout)
387 local new_commit2=`git_show_head $testroot/repo`
389 local short_old_commit1=`trim_obj_id 28 $old_commit1`
390 local short_old_commit2=`trim_obj_id 28 $old_commit2`
391 local short_new_commit2=`trim_obj_id 28 $new_commit2`
393 echo "$short_old_commit1 -> drop commit: committing changes" \
394 > $testroot/stdout.expected
395 echo "G epsilon/zeta" >> $testroot/stdout.expected
396 echo -n "$short_old_commit2 -> $short_new_commit2: " \
397 >> $testroot/stdout.expected
398 echo "committing to zeta on master" >> $testroot/stdout.expected
399 echo "Switching work tree to refs/heads/master" \
400 >> $testroot/stdout.expected
402 cmp -s $testroot/stdout.expected $testroot/stdout
403 ret=$?
404 if [ $ret -ne 0 ]; then
405 diff -u $testroot/stdout.expected $testroot/stdout
406 test_done "$testroot" "$ret"
407 return 1
408 fi
410 for f in alpha beta; do
411 echo "$f" > $testroot/content.expected
412 cat $testroot/wt/$f > $testroot/content
413 cmp -s $testroot/content.expected $testroot/content
414 ret=$?
415 if [ $ret -ne 0 ]; then
416 diff -u $testroot/content.expected $testroot/content
417 test_done "$testroot" "$ret"
418 return 1
419 fi
420 done
422 if [ -e $testroot/wt/new ]; then
423 echo "file new exists on disk but should not" >&2
424 test_done "$testroot" "1"
425 return 1
426 fi
428 (cd $testroot/wt && got status > $testroot/stdout)
430 echo -n > $testroot/stdout.expected
431 cmp -s $testroot/stdout.expected $testroot/stdout
432 ret=$?
433 if [ $ret -ne 0 ]; then
434 diff -u $testroot/stdout.expected $testroot/stdout
435 test_done "$testroot" "$ret"
436 return 1
437 fi
439 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
440 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
441 echo "commit $orig_commit" >> $testroot/stdout.expected
442 cmp -s $testroot/stdout.expected $testroot/stdout
443 ret=$?
444 if [ $ret -ne 0 ]; then
445 diff -u $testroot/stdout.expected $testroot/stdout
446 test_done "$testroot" "$ret"
447 return 1
448 fi
450 got diff -r $testroot/repo $orig_commit $new_commit2 \
451 > $testroot/diff
452 sed -i '' -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
453 sed -i '' -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
454 cmp -s $testroot/diff.expected $testroot/diff
455 ret=$?
456 if [ $ret -ne 0 ]; then
457 diff -u $testroot/diff.expected $testroot/diff
458 fi
459 test_done "$testroot" "$ret"
462 test_histedit_fold() {
463 local testroot=`test_init histedit_fold`
465 local orig_commit=`git_show_head $testroot/repo`
467 echo "modified alpha on master" > $testroot/repo/alpha
468 (cd $testroot/repo && git rm -q beta)
469 echo "new file on master" > $testroot/repo/epsilon/new
470 (cd $testroot/repo && git add epsilon/new)
471 git_commit $testroot/repo -m "committing changes"
472 local old_commit1=`git_show_head $testroot/repo`
474 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
475 git_commit $testroot/repo -m "committing to zeta on master"
476 local old_commit2=`git_show_head $testroot/repo`
478 echo "modified delta on master" > $testroot/repo/gamma/delta
479 git_commit $testroot/repo -m "committing to delta on master"
480 local old_commit3=`git_show_head $testroot/repo`
482 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
483 ret=$?
484 if [ $ret -ne 0 ]; then
485 test_done "$testroot" "$ret"
486 return 1
487 fi
489 echo "fold $old_commit1" > $testroot/histedit-script
490 echo "drop $old_commit2" >> $testroot/histedit-script
491 echo "pick $old_commit3" >> $testroot/histedit-script
492 echo "mesg committing folded changes" >> $testroot/histedit-script
494 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
495 > $testroot/stdout)
497 local new_commit1=`git_show_parent_commit $testroot/repo`
498 local new_commit2=`git_show_head $testroot/repo`
500 local short_old_commit1=`trim_obj_id 28 $old_commit1`
501 local short_old_commit2=`trim_obj_id 28 $old_commit2`
502 local short_old_commit3=`trim_obj_id 28 $old_commit3`
503 local short_new_commit1=`trim_obj_id 28 $new_commit1`
504 local short_new_commit2=`trim_obj_id 28 $new_commit2`
506 echo "G alpha" > $testroot/stdout.expected
507 echo "D beta" >> $testroot/stdout.expected
508 echo "A epsilon/new" >> $testroot/stdout.expected
509 echo "$short_old_commit1 -> fold commit: committing changes" \
510 >> $testroot/stdout.expected
511 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
512 echo "drop commit: committing to zeta on master" \
513 >> $testroot/stdout.expected
514 echo "G gamma/delta" >> $testroot/stdout.expected
515 echo -n "$short_old_commit3 -> $short_new_commit2: " \
516 >> $testroot/stdout.expected
517 echo "committing folded changes" >> $testroot/stdout.expected
518 echo "Switching work tree to refs/heads/master" \
519 >> $testroot/stdout.expected
521 cmp -s $testroot/stdout.expected $testroot/stdout
522 ret=$?
523 if [ $ret -ne 0 ]; then
524 diff -u $testroot/stdout.expected $testroot/stdout
525 test_done "$testroot" "$ret"
526 return 1
527 fi
529 echo "modified alpha on master" > $testroot/content.expected
530 cat $testroot/wt/alpha > $testroot/content
531 cmp -s $testroot/content.expected $testroot/content
532 ret=$?
533 if [ $ret -ne 0 ]; then
534 diff -u $testroot/content.expected $testroot/content
535 test_done "$testroot" "$ret"
536 return 1
537 fi
539 if [ -e $testroot/wt/beta ]; then
540 echo "removed file beta still exists on disk" >&2
541 test_done "$testroot" "1"
542 return 1
543 fi
545 echo "new file on master" > $testroot/content.expected
546 cat $testroot/wt/epsilon/new > $testroot/content
547 cmp -s $testroot/content.expected $testroot/content
548 ret=$?
549 if [ $ret -ne 0 ]; then
550 diff -u $testroot/content.expected $testroot/content
551 test_done "$testroot" "$ret"
552 return 1
553 fi
555 (cd $testroot/wt && got status > $testroot/stdout)
557 echo -n > $testroot/stdout.expected
558 cmp -s $testroot/stdout.expected $testroot/stdout
559 ret=$?
560 if [ $ret -ne 0 ]; then
561 diff -u $testroot/stdout.expected $testroot/stdout
562 test_done "$testroot" "$ret"
563 return 1
564 fi
566 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
567 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
568 echo "commit $orig_commit" >> $testroot/stdout.expected
569 cmp -s $testroot/stdout.expected $testroot/stdout
570 ret=$?
571 if [ $ret -ne 0 ]; then
572 diff -u $testroot/stdout.expected $testroot/stdout
573 fi
574 test_done "$testroot" "$ret"
577 test_histedit_edit() {
578 local testroot=`test_init histedit_edit`
580 local orig_commit=`git_show_head $testroot/repo`
582 echo "modified alpha on master" > $testroot/repo/alpha
583 (cd $testroot/repo && git rm -q beta)
584 echo "new file on master" > $testroot/repo/epsilon/new
585 (cd $testroot/repo && git add epsilon/new)
586 git_commit $testroot/repo -m "committing changes"
587 local old_commit1=`git_show_head $testroot/repo`
589 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
590 git_commit $testroot/repo -m "committing to zeta on master"
591 local old_commit2=`git_show_head $testroot/repo`
593 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
594 ret=$?
595 if [ $ret -ne 0 ]; then
596 test_done "$testroot" "$ret"
597 return 1
598 fi
600 echo "edit $old_commit1" > $testroot/histedit-script
601 echo "mesg committing changes" >> $testroot/histedit-script
602 echo "pick $old_commit2" >> $testroot/histedit-script
604 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
605 > $testroot/stdout)
607 local short_old_commit1=`trim_obj_id 28 $old_commit1`
608 local short_old_commit2=`trim_obj_id 28 $old_commit2`
610 echo "G alpha" > $testroot/stdout.expected
611 echo "D beta" >> $testroot/stdout.expected
612 echo "A epsilon/new" >> $testroot/stdout.expected
613 echo "Stopping histedit for amending commit $old_commit1" \
614 >> $testroot/stdout.expected
615 cmp -s $testroot/stdout.expected $testroot/stdout
616 ret=$?
617 if [ $ret -ne 0 ]; then
618 diff -u $testroot/stdout.expected $testroot/stdout
619 test_done "$testroot" "$ret"
620 return 1
621 fi
623 echo "edited modified alpha on master" > $testroot/wt/alpha
625 # test interaction of 'got stage' and histedit -c
626 (cd $testroot/wt && got stage alpha > /dev/null)
627 (cd $testroot/wt && got histedit -c > $testroot/stdout \
628 2> $testroot/stderr)
629 ret=$?
630 if [ $ret -eq 0 ]; then
631 echo "histedit succeeded unexpectedly" >&2
632 test_done "$testroot" "1"
633 return 1
634 fi
635 echo -n "got: work tree contains files with staged changes; " \
636 > $testroot/stderr.expected
637 echo "these changes must be committed or unstaged first" \
638 >> $testroot/stderr.expected
639 cmp -s $testroot/stderr.expected $testroot/stderr
640 ret=$?
641 if [ $ret -ne 0 ]; then
642 diff -u $testroot/stderr.expected $testroot/stderr
643 test_done "$testroot" "$ret"
644 return 1
645 fi
647 (cd $testroot/wt && got unstage alpha > /dev/null)
648 (cd $testroot/wt && got histedit -c > $testroot/stdout)
650 local new_commit1=`git_show_parent_commit $testroot/repo`
651 local new_commit2=`git_show_head $testroot/repo`
653 local short_new_commit1=`trim_obj_id 28 $new_commit1`
654 local short_new_commit2=`trim_obj_id 28 $new_commit2`
656 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
657 > $testroot/stdout.expected
658 echo "G epsilon/zeta" >> $testroot/stdout.expected
659 echo -n "$short_old_commit2 -> $short_new_commit2: " \
660 >> $testroot/stdout.expected
661 echo "committing to zeta on master" >> $testroot/stdout.expected
662 echo "Switching work tree to refs/heads/master" \
663 >> $testroot/stdout.expected
665 cmp -s $testroot/stdout.expected $testroot/stdout
666 ret=$?
667 if [ $ret -ne 0 ]; then
668 diff -u $testroot/stdout.expected $testroot/stdout
669 test_done "$testroot" "$ret"
670 return 1
671 fi
673 echo "edited modified alpha on master" > $testroot/content.expected
674 cat $testroot/wt/alpha > $testroot/content
675 cmp -s $testroot/content.expected $testroot/content
676 ret=$?
677 if [ $ret -ne 0 ]; then
678 diff -u $testroot/content.expected $testroot/content
679 test_done "$testroot" "$ret"
680 return 1
681 fi
683 if [ -e $testroot/wt/beta ]; then
684 echo "removed file beta still exists on disk" >&2
685 test_done "$testroot" "1"
686 return 1
687 fi
689 echo "new file on master" > $testroot/content.expected
690 cat $testroot/wt/epsilon/new > $testroot/content
691 cmp -s $testroot/content.expected $testroot/content
692 ret=$?
693 if [ $ret -ne 0 ]; then
694 diff -u $testroot/content.expected $testroot/content
695 test_done "$testroot" "$ret"
696 return 1
697 fi
699 (cd $testroot/wt && got status > $testroot/stdout)
701 echo -n > $testroot/stdout.expected
702 cmp -s $testroot/stdout.expected $testroot/stdout
703 ret=$?
704 if [ $ret -ne 0 ]; then
705 diff -u $testroot/stdout.expected $testroot/stdout
706 test_done "$testroot" "$ret"
707 return 1
708 fi
710 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
711 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
712 echo "commit $new_commit1" >> $testroot/stdout.expected
713 echo "commit $orig_commit" >> $testroot/stdout.expected
714 cmp -s $testroot/stdout.expected $testroot/stdout
715 ret=$?
716 if [ $ret -ne 0 ]; then
717 diff -u $testroot/stdout.expected $testroot/stdout
718 fi
719 test_done "$testroot" "$ret"
722 test_histedit_fold_last_commit() {
723 local testroot=`test_init histedit_fold_last_commit`
725 local orig_commit=`git_show_head $testroot/repo`
727 echo "modified alpha on master" > $testroot/repo/alpha
728 (cd $testroot/repo && git rm -q beta)
729 echo "new file on master" > $testroot/repo/epsilon/new
730 (cd $testroot/repo && git add epsilon/new)
731 git_commit $testroot/repo -m "committing changes"
732 local old_commit1=`git_show_head $testroot/repo`
734 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
735 git_commit $testroot/repo -m "committing to zeta on master"
736 local old_commit2=`git_show_head $testroot/repo`
738 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
739 ret=$?
740 if [ $ret -ne 0 ]; then
741 test_done "$testroot" "$ret"
742 return 1
743 fi
745 echo "pick $old_commit1" > $testroot/histedit-script
746 echo "fold $old_commit2" >> $testroot/histedit-script
747 echo "mesg committing folded changes" >> $testroot/histedit-script
749 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
750 > $testroot/stdout 2> $testroot/stderr)
752 ret=$?
753 if [ $ret -eq 0 ]; then
754 echo "histedit succeeded unexpectedly" >&2
755 test_done "$testroot" "1"
756 return 1
757 fi
759 echo "got: last commit in histedit script cannot be folded" \
760 > $testroot/stderr.expected
762 cmp -s $testroot/stderr.expected $testroot/stderr
763 ret=$?
764 if [ $ret -ne 0 ]; then
765 diff -u $testroot/stderr.expected $testroot/stderr
766 fi
767 test_done "$testroot" "$ret"
770 test_histedit_missing_commit() {
771 local testroot=`test_init histedit_missing_commit`
773 local orig_commit=`git_show_head $testroot/repo`
775 echo "modified alpha on master" > $testroot/repo/alpha
776 (cd $testroot/repo && git rm -q beta)
777 echo "new file on master" > $testroot/repo/epsilon/new
778 (cd $testroot/repo && git add epsilon/new)
779 git_commit $testroot/repo -m "committing changes"
780 local old_commit1=`git_show_head $testroot/repo`
782 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
783 git_commit $testroot/repo -m "committing to zeta on master"
784 local old_commit2=`git_show_head $testroot/repo`
786 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
787 ret=$?
788 if [ $ret -ne 0 ]; then
789 test_done "$testroot" "$ret"
790 return 1
791 fi
793 echo "pick $old_commit1" > $testroot/histedit-script
794 echo "mesg committing changes" >> $testroot/histedit-script
796 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
797 > $testroot/stdout 2> $testroot/stderr)
799 ret=$?
800 if [ $ret -eq 0 ]; then
801 echo "histedit succeeded unexpectedly" >&2
802 test_done "$testroot" "1"
803 return 1
804 fi
806 echo "got: commit $old_commit2 missing from histedit script" \
807 > $testroot/stderr.expected
809 cmp -s $testroot/stderr.expected $testroot/stderr
810 ret=$?
811 if [ $ret -ne 0 ]; then
812 diff -u $testroot/stderr.expected $testroot/stderr
813 fi
814 test_done "$testroot" "$ret"
817 test_histedit_abort() {
818 local testroot=`test_init histedit_abort`
820 local orig_commit=`git_show_head $testroot/repo`
822 echo "modified alpha on master" > $testroot/repo/alpha
823 (cd $testroot/repo && git rm -q beta)
824 echo "new file on master" > $testroot/repo/epsilon/new
825 (cd $testroot/repo && git add epsilon/new)
826 git_commit $testroot/repo -m "committing changes"
827 local old_commit1=`git_show_head $testroot/repo`
829 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
830 git_commit $testroot/repo -m "committing to zeta on master"
831 local old_commit2=`git_show_head $testroot/repo`
833 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
834 ret=$?
835 if [ $ret -ne 0 ]; then
836 test_done "$testroot" "$ret"
837 return 1
838 fi
840 # unrelated unversioned file in work tree
841 touch $testroot/wt/unversioned-file
843 echo "edit $old_commit1" > $testroot/histedit-script
844 echo "mesg committing changes" >> $testroot/histedit-script
845 echo "pick $old_commit2" >> $testroot/histedit-script
847 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
848 > $testroot/stdout)
850 local short_old_commit1=`trim_obj_id 28 $old_commit1`
851 local short_old_commit2=`trim_obj_id 28 $old_commit2`
853 echo "G alpha" > $testroot/stdout.expected
854 echo "D beta" >> $testroot/stdout.expected
855 echo "A epsilon/new" >> $testroot/stdout.expected
856 echo "Stopping histedit for amending commit $old_commit1" \
857 >> $testroot/stdout.expected
858 cmp -s $testroot/stdout.expected $testroot/stdout
859 ret=$?
860 if [ $ret -ne 0 ]; then
861 diff -u $testroot/stdout.expected $testroot/stdout
862 test_done "$testroot" "$ret"
863 return 1
864 fi
866 echo "edited modified alpha on master" > $testroot/wt/alpha
868 (cd $testroot/wt && got histedit -a > $testroot/stdout)
870 local new_commit1=`git_show_parent_commit $testroot/repo`
871 local new_commit2=`git_show_head $testroot/repo`
873 echo "Switching work tree to refs/heads/master" \
874 > $testroot/stdout.expected
875 echo "R alpha" >> $testroot/stdout.expected
876 echo "R beta" >> $testroot/stdout.expected
877 echo "R epsilon/new" >> $testroot/stdout.expected
878 echo "Histedit of refs/heads/master aborted" \
879 >> $testroot/stdout.expected
881 cmp -s $testroot/stdout.expected $testroot/stdout
882 ret=$?
883 if [ $ret -ne 0 ]; then
884 diff -u $testroot/stdout.expected $testroot/stdout
885 test_done "$testroot" "$ret"
886 return 1
887 fi
889 for f in alpha beta; do
890 echo "$f" > $testroot/content.expected
891 cat $testroot/wt/$f > $testroot/content
892 cmp -s $testroot/content.expected $testroot/content
893 ret=$?
894 if [ $ret -ne 0 ]; then
895 diff -u $testroot/content.expected $testroot/content
896 test_done "$testroot" "$ret"
897 return 1
898 fi
899 done
901 echo "new file on master" > $testroot/content.expected
902 cat $testroot/wt/epsilon/new > $testroot/content
903 cmp -s $testroot/content.expected $testroot/content
904 ret=$?
905 if [ $ret -ne 0 ]; then
906 diff -u $testroot/content.expected $testroot/content
907 test_done "$testroot" "$ret"
908 return 1
909 fi
911 (cd $testroot/wt && got status > $testroot/stdout)
913 echo "? epsilon/new" > $testroot/stdout.expected
914 echo "? unversioned-file" >> $testroot/stdout.expected
915 cmp -s $testroot/stdout.expected $testroot/stdout
916 ret=$?
917 if [ $ret -ne 0 ]; then
918 diff -u $testroot/stdout.expected $testroot/stdout
919 test_done "$testroot" "$ret"
920 return 1
921 fi
923 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
924 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
925 echo "commit $new_commit1" >> $testroot/stdout.expected
926 echo "commit $orig_commit" >> $testroot/stdout.expected
927 cmp -s $testroot/stdout.expected $testroot/stdout
928 ret=$?
929 if [ $ret -ne 0 ]; then
930 diff -u $testroot/stdout.expected $testroot/stdout
931 fi
932 test_done "$testroot" "$ret"
935 test_histedit_path_prefix_drop() {
936 local testroot=`test_init histedit_path_prefix_drop`
937 local orig_commit=`git_show_head $testroot/repo`
939 echo "modified zeta" > $testroot/repo/epsilon/zeta
940 git_commit $testroot/repo -m "changing zeta"
941 local old_commit1=`git_show_head $testroot/repo`
943 got checkout -c $orig_commit -p gamma $testroot/repo \
944 $testroot/wt > /dev/null
945 ret=$?
946 if [ $ret -ne 0 ]; then
947 test_done "$testroot" "$ret"
948 return 1
949 fi
951 echo "drop $old_commit1" > $testroot/histedit-script
953 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
954 > $testroot/stdout 2> $testroot/stderr)
956 ret=$?
957 if [ $ret -eq 0 ]; then
958 echo "histedit succeeded unexpectedly" >&2
959 test_done "$testroot" "1"
960 return 1
961 fi
963 echo -n "got: cannot edit branch history which contains changes " \
964 > $testroot/stderr.expected
965 echo "outside of this work tree's path prefix" \
966 >> $testroot/stderr.expected
968 cmp -s $testroot/stderr.expected $testroot/stderr
969 ret=$?
970 if [ $ret -ne 0 ]; then
971 diff -u $testroot/stderr.expected $testroot/stderr
972 test_done "$testroot" "$ret"
973 return 1
974 fi
976 rm -rf $testroot/wt
977 got checkout -c $orig_commit -p epsilon $testroot/repo \
978 $testroot/wt > /dev/null
979 ret=$?
980 if [ $ret -ne 0 ]; then
981 test_done "$testroot" "$ret"
982 return 1
983 fi
984 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
985 > $testroot/stdout)
987 local short_old_commit1=`trim_obj_id 28 $old_commit1`
988 local short_old_commit2=`trim_obj_id 28 $old_commit2`
990 echo "$short_old_commit1 -> drop commit: changing zeta" \
991 > $testroot/stdout.expected
992 echo "Switching work tree to refs/heads/master" \
993 >> $testroot/stdout.expected
995 cmp -s $testroot/stdout.expected $testroot/stdout
996 ret=$?
997 if [ $ret -ne 0 ]; then
998 diff -u $testroot/stdout.expected $testroot/stdout
999 test_done "$testroot" "$ret"
1000 return 1
1003 echo "zeta" > $testroot/content.expected
1004 cat $testroot/wt/zeta > $testroot/content
1005 cmp -s $testroot/content.expected $testroot/content
1006 ret=$?
1007 if [ $ret -ne 0 ]; then
1008 diff -u $testroot/content.expected $testroot/content
1009 test_done "$testroot" "$ret"
1010 return 1
1014 (cd $testroot/wt && got status > $testroot/stdout)
1016 echo -n > $testroot/stdout.expected
1017 cmp -s $testroot/stdout.expected $testroot/stdout
1018 ret=$?
1019 if [ $ret -ne 0 ]; then
1020 diff -u $testroot/stdout.expected $testroot/stdout
1021 test_done "$testroot" "$ret"
1022 return 1
1025 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1026 echo "commit $orig_commit (master)" > $testroot/stdout.expected
1027 cmp -s $testroot/stdout.expected $testroot/stdout
1028 ret=$?
1029 if [ $ret -ne 0 ]; then
1030 diff -u $testroot/stdout.expected $testroot/stdout
1032 test_done "$testroot" "$ret"
1035 test_histedit_path_prefix_edit() {
1036 local testroot=`test_init histedit_path_prefix_edit`
1037 local orig_commit=`git_show_head $testroot/repo`
1039 echo "modified zeta" > $testroot/repo/epsilon/zeta
1040 git_commit $testroot/repo -m "changing zeta"
1041 local old_commit1=`git_show_head $testroot/repo`
1043 got diff -r $testroot/repo $orig_commit $old_commit1 \
1044 > $testroot/diff.expected
1046 got checkout -c $orig_commit -p gamma $testroot/repo \
1047 $testroot/wt > /dev/null
1048 ret=$?
1049 if [ $ret -ne 0 ]; then
1050 test_done "$testroot" "$ret"
1051 return 1
1054 echo "edit $old_commit1" > $testroot/histedit-script
1055 echo "mesg modified zeta" >> $testroot/histedit-script
1057 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1058 > $testroot/stdout 2> $testroot/stderr)
1060 ret=$?
1061 if [ $ret -eq 0 ]; then
1062 echo "histedit succeeded unexpectedly" >&2
1063 test_done "$testroot" "1"
1064 return 1
1067 echo -n "got: cannot edit branch history which contains changes " \
1068 > $testroot/stderr.expected
1069 echo "outside of this work tree's path prefix" \
1070 >> $testroot/stderr.expected
1072 cmp -s $testroot/stderr.expected $testroot/stderr
1073 ret=$?
1074 if [ $ret -ne 0 ]; then
1075 diff -u $testroot/stderr.expected $testroot/stderr
1076 test_done "$testroot" "$ret"
1077 return 1
1080 rm -rf $testroot/wt
1081 got checkout -c $orig_commit -p epsilon $testroot/repo \
1082 $testroot/wt > /dev/null
1083 ret=$?
1084 if [ $ret -ne 0 ]; then
1085 test_done "$testroot" "$ret"
1086 return 1
1088 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1089 > $testroot/stdout)
1091 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1093 echo "G zeta" > $testroot/stdout.expected
1094 echo "Stopping histedit for amending commit $old_commit1" \
1095 >> $testroot/stdout.expected
1096 cmp -s $testroot/stdout.expected $testroot/stdout
1097 ret=$?
1098 if [ $ret -ne 0 ]; then
1099 diff -u $testroot/stdout.expected $testroot/stdout
1100 test_done "$testroot" "$ret"
1101 return 1
1104 echo "modified zeta" > $testroot/content.expected
1105 cat $testroot/wt/zeta > $testroot/content
1106 cmp -s $testroot/content.expected $testroot/content
1107 ret=$?
1108 if [ $ret -ne 0 ]; then
1109 diff -u $testroot/content.expected $testroot/content
1110 test_done "$testroot" "$ret"
1111 return 1
1114 (cd $testroot/wt && got status > $testroot/stdout)
1116 echo "M zeta"> $testroot/stdout.expected
1117 cmp -s $testroot/stdout.expected $testroot/stdout
1118 ret=$?
1119 if [ $ret -ne 0 ]; then
1120 diff -u $testroot/stdout.expected $testroot/stdout
1121 test_done "$testroot" "$ret"
1122 return 1
1125 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1127 local new_commit1=`git_show_head $testroot/repo`
1128 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1130 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1131 > $testroot/stdout.expected
1132 echo "modified zeta" >> $testroot/stdout.expected
1133 echo "Switching work tree to refs/heads/master" \
1134 >> $testroot/stdout.expected
1136 cmp -s $testroot/stdout.expected $testroot/stdout
1137 ret=$?
1138 if [ $ret -ne 0 ]; then
1139 diff -u $testroot/stdout.expected $testroot/stdout
1140 test_done "$testroot" "$ret"
1141 return 1
1144 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1145 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1146 echo "commit $orig_commit" >> $testroot/stdout.expected
1147 cmp -s $testroot/stdout.expected $testroot/stdout
1148 ret=$?
1149 if [ $ret -ne 0 ]; then
1150 diff -u $testroot/stdout.expected $testroot/stdout
1151 test_done "$testroot" "$ret"
1152 return 1
1155 got diff -r $testroot/repo $orig_commit $new_commit1 \
1156 > $testroot/diff
1157 sed -i '' -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1158 cmp -s $testroot/diff.expected $testroot/diff
1159 ret=$?
1160 if [ $ret -ne 0 ]; then
1161 diff -u $testroot/diff.expected $testroot/diff
1163 test_done "$testroot" "$ret"
1166 test_histedit_outside_refs_heads() {
1167 local testroot=`test_init histedit_outside_refs_heads`
1168 local commit1=`git_show_head $testroot/repo`
1170 got checkout $testroot/repo $testroot/wt > /dev/null
1171 ret=$?
1172 if [ $ret -ne 0 ]; then
1173 echo "got checkout failed unexpectedly"
1174 test_done "$testroot" "$ret"
1175 return 1
1178 echo "modified alpha" > $testroot/wt/alpha
1180 (cd $testroot/wt && got commit -m 'change alpha' \
1181 > $testroot/stdout 2> $testroot/stderr)
1182 ret=$?
1183 if [ $ret -ne 0 ]; then
1184 echo "got commit failed unexpectedly" >&2
1185 test_done "$testroot" "1"
1186 return 1
1188 local commit2=`git_show_head $testroot/repo`
1190 got ref -r $testroot/repo -c master refs/remotes/origin/master
1191 ret=$?
1192 if [ $ret -ne 0 ]; then
1193 echo "got ref failed unexpectedly" >&2
1194 test_done "$testroot" "1"
1195 return 1
1198 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1199 ret=$?
1200 if [ $ret -ne 0 ]; then
1201 echo "got update failed unexpectedly"
1202 test_done "$testroot" "$ret"
1203 return 1
1206 echo "edit $commit2" > $testroot/histedit-script
1207 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1208 2> $testroot/stderr)
1210 echo -n "got: will not edit commit history of a branch outside the " \
1211 > $testroot/stderr.expected
1212 echo '"refs/heads/" reference namespace' \
1213 >> $testroot/stderr.expected
1214 cmp -s $testroot/stderr.expected $testroot/stderr
1215 ret=$?
1216 if [ $ret -ne 0 ]; then
1217 diff -u $testroot/stderr.expected $testroot/stderr
1219 test_done "$testroot" "$ret"
1222 test_histedit_fold_last_commit_swap() {
1223 local testroot=`test_init histedit_fold_last_commit_swap`
1225 local orig_commit=`git_show_head $testroot/repo`
1227 echo "modified alpha on master" > $testroot/repo/alpha
1228 (cd $testroot/repo && git rm -q beta)
1229 echo "new file on master" > $testroot/repo/epsilon/new
1230 (cd $testroot/repo && git add epsilon/new)
1231 git_commit $testroot/repo -m "committing changes"
1232 local old_commit1=`git_show_head $testroot/repo`
1234 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1235 git_commit $testroot/repo -m "committing to zeta on master"
1236 local old_commit2=`git_show_head $testroot/repo`
1238 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1239 ret=$?
1240 if [ $ret -ne 0 ]; then
1241 test_done "$testroot" "$ret"
1242 return 1
1245 # fold commit2 into commit1 (requires swapping commits)
1246 echo "fold $old_commit2" > $testroot/histedit-script
1247 echo "pick $old_commit1" >> $testroot/histedit-script
1248 echo "mesg committing folded changes" >> $testroot/histedit-script
1250 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1251 > $testroot/stdout 2> $testroot/stderr)
1253 ret=$?
1254 if [ $ret -ne 0 ]; then
1255 echo "histedit failed unexpectedly" >&2
1256 test_done "$testroot" "$ret"
1257 return 1
1260 local new_commit=`git_show_head $testroot/repo`
1262 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1263 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1264 local short_new_commit=`trim_obj_id 28 $new_commit`
1266 echo "G epsilon/zeta" >> $testroot/stdout.expected
1267 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1268 >> $testroot/stdout.expected
1269 echo "on master" >> $testroot/stdout.expected
1270 echo "G alpha" >> $testroot/stdout.expected
1271 echo "D beta" >> $testroot/stdout.expected
1272 echo "A epsilon/new" >> $testroot/stdout.expected
1273 echo -n "$short_old_commit1 -> $short_new_commit: " \
1274 >> $testroot/stdout.expected
1275 echo "committing folded changes" >> $testroot/stdout.expected
1276 echo "Switching work tree to refs/heads/master" \
1277 >> $testroot/stdout.expected
1279 cmp -s $testroot/stdout.expected $testroot/stdout
1280 ret=$?
1281 if [ $ret -ne 0 ]; then
1282 diff -u $testroot/stdout.expected $testroot/stdout
1284 test_done "$testroot" "$ret"
1287 test_histedit_split_commit() {
1288 local testroot=`test_init histedit_split_commit`
1290 local orig_commit=`git_show_head $testroot/repo`
1292 echo "modified alpha on master" > $testroot/repo/alpha
1293 (cd $testroot/repo && git rm -q beta)
1294 echo "new file on master" > $testroot/repo/epsilon/new
1295 (cd $testroot/repo && git add epsilon/new)
1296 git_commit $testroot/repo -m "committing changes 1"
1297 local old_commit1=`git_show_head $testroot/repo`
1298 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1300 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1301 git_commit $testroot/repo -m "committing changes 2"
1302 local old_commit2=`git_show_head $testroot/repo`
1303 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1305 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1306 ret=$?
1307 if [ $ret -ne 0 ]; then
1308 test_done "$testroot" "$ret"
1309 return 1
1312 # split commit1 into commitA and commitB and commitC
1313 echo "e $old_commit1" > $testroot/histedit-script
1314 echo "p $old_commit2" >> $testroot/histedit-script
1316 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1317 > $testroot/stdout 2> $testroot/stderr)
1318 ret=$?
1319 if [ $ret -ne 0 ]; then
1320 echo "histedit failed unexpectedly:" >&2
1321 cat $testroot/stderr >&2
1322 test_done "$testroot" "$ret"
1323 return 1
1326 echo "G alpha" > $testroot/stdout.expected
1327 echo "D beta" >> $testroot/stdout.expected
1328 echo "A epsilon/new" >> $testroot/stdout.expected
1329 echo "Stopping histedit for amending commit $old_commit1" \
1330 >> $testroot/stdout.expected
1332 cmp -s $testroot/stdout.expected $testroot/stdout
1333 ret=$?
1334 if [ $ret -ne 0 ]; then
1335 diff -u $testroot/stdout.expected $testroot/stdout
1336 test_done "$testroot" "$ret"
1337 return 1
1340 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1341 ret=$?
1342 if [ $ret -ne 0 ]; then
1343 echo "commit failed unexpectedly" >&2
1344 test_done "$testroot" "$ret"
1345 return 1
1348 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1349 ret=$?
1350 if [ $ret -ne 0 ]; then
1351 echo "commit failed unexpectedly" >&2
1352 test_done "$testroot" "$ret"
1353 return 1
1356 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1357 ret=$?
1358 if [ $ret -ne 0 ]; then
1359 echo "commit failed unexpectedly" >&2
1360 test_done "$testroot" "$ret"
1361 return 1
1364 (cd $testroot/wt && got histedit -c \
1365 > $testroot/stdout 2> $testroot/stderr)
1366 ret=$?
1367 if [ $ret -ne 0 ]; then
1368 echo "histedit failed unexpectedly:" >&2
1369 cat $testroot/stderr >&2
1370 test_done "$testroot" "$ret"
1371 return 1
1373 local new_commit2=`git_show_head $testroot/repo`
1374 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1376 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1377 > $testroot/stdout.expected
1378 echo "G epsilon/zeta" >> $testroot/stdout.expected
1379 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1380 >> $testroot/stdout.expected
1381 echo "Switching work tree to refs/heads/master" \
1382 >> $testroot/stdout.expected
1384 cmp -s $testroot/stdout.expected $testroot/stdout
1385 ret=$?
1386 if [ $ret -ne 0 ]; then
1387 diff -u $testroot/stdout.expected $testroot/stdout
1389 test_done "$testroot" "$ret"
1393 test_histedit_duplicate_commit_in_script() {
1394 local testroot=`test_init histedit_duplicate_commit_in_script`
1396 local orig_commit=`git_show_head $testroot/repo`
1398 echo "modified alpha on master" > $testroot/repo/alpha
1399 (cd $testroot/repo && git rm -q beta)
1400 echo "new file on master" > $testroot/repo/epsilon/new
1401 (cd $testroot/repo && git add epsilon/new)
1402 git_commit $testroot/repo -m "committing changes 1"
1403 local old_commit1=`git_show_head $testroot/repo`
1405 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1406 git_commit $testroot/repo -m "committing changes 2"
1407 local old_commit2=`git_show_head $testroot/repo`
1409 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1410 ret=$?
1411 if [ $ret -ne 0 ]; then
1412 test_done "$testroot" "$ret"
1413 return 1
1416 # This histedit script lists commit1 more than once
1417 echo "p $old_commit1" > $testroot/histedit-script
1418 echo "p $old_commit1" >> $testroot/histedit-script
1419 echo "p $old_commit2" >> $testroot/histedit-script
1421 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1422 > $testroot/stdout 2> $testroot/stderr)
1423 ret=$?
1424 if [ $ret -eq 0 ]; then
1425 echo "histedit succeeded unexpectedly:" >&2
1426 cat $testroot/stdout >&2
1427 test_done "$testroot" "$ret"
1428 return 1
1431 echo -n "got: commit $old_commit1 is listed more than once " \
1432 > $testroot/stderr.expected
1433 echo "in histedit script" >> $testroot/stderr.expected
1435 cmp -s $testroot/stderr.expected $testroot/stderr
1436 ret=$?
1437 if [ $ret -ne 0 ]; then
1438 diff -u $testroot/stderr.expected $testroot/stderr
1440 test_done "$testroot" "$ret"
1444 # if a previous commit introduces a new file, and it is folded into a commit
1445 # that deletes the same file, the file still exists after the histedit
1446 test_histedit_fold_add_delete() {
1447 local testroot=`test_init histedit_fold_add_delete`
1449 local orig_commit=`git_show_head $testroot/repo`
1451 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1452 (cd $testroot/repo && git add epsilon/psi)
1453 git_commit $testroot/repo -m "committing changes"
1454 local old_commit1=`git_show_head $testroot/repo`
1456 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1457 git_commit $testroot/repo -m "editing psi"
1458 local old_commit2=`git_show_head $testroot/repo`
1460 (cd $testroot/repo && git rm -q epsilon/psi)
1461 git_commit $testroot/repo -m "removing psi"
1462 local old_commit3=`git_show_head $testroot/repo`
1464 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1465 ret=$?
1466 if [ $ret -ne 0 ]; then
1467 test_done "$testroot" "$ret"
1468 return 1
1471 echo "fold $old_commit1" > $testroot/histedit-script
1472 echo "fold $old_commit2" >> $testroot/histedit-script
1473 echo "pick $old_commit3" >> $testroot/histedit-script
1474 echo "mesg folded changes" >> $testroot/histedit-script
1476 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1477 > $testroot/stdout)
1479 local new_commit1=`git_show_head $testroot/repo`
1481 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1482 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1483 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1484 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1486 echo "A epsilon/psi" >> $testroot/stdout.expected
1487 echo "$short_old_commit1 -> fold commit: committing changes" \
1488 >> $testroot/stdout.expected
1489 echo "G epsilon/psi" >> $testroot/stdout.expected
1490 echo "$short_old_commit2 -> fold commit: editing psi" \
1491 >> $testroot/stdout.expected
1492 echo "D epsilon/psi" >> $testroot/stdout.expected
1493 echo "$short_old_commit3 -> no-op change: folded changes" \
1494 >> $testroot/stdout.expected
1495 echo "Switching work tree to refs/heads/master" \
1496 >> $testroot/stdout.expected
1498 cmp -s $testroot/stdout.expected $testroot/stdout
1499 ret=$?
1500 if [ $ret -ne 0 ]; then
1501 diff -u $testroot/stdout.expected $testroot/stdout
1502 test_done "$testroot" "$ret"
1503 return 1
1506 if [ -e $testroot/wt/epsilon/psi ]; then
1507 echo "removed file psi still exists on disk" >&2
1508 test_done "$testroot" "1"
1509 return 1
1512 (cd $testroot/wt && got status > $testroot/stdout)
1514 echo -n > $testroot/stdout.expected
1515 cmp -s $testroot/stdout.expected $testroot/stdout
1516 ret=$?
1517 if [ $ret -ne 0 ]; then
1518 diff -u $testroot/stdout.expected $testroot/stdout
1519 test_done "$testroot" "$ret"
1520 return 1
1523 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1524 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1525 cmp -s $testroot/stdout.expected $testroot/stdout
1526 ret=$?
1527 if [ $ret -ne 0 ]; then
1528 diff -u $testroot/stdout.expected $testroot/stdout
1529 test_done "$testroot" "$ret"
1530 return 1
1533 got tree -r $testroot/repo epsilon > $testroot/stdout
1534 echo "zeta" > $testroot/stdout.expected
1535 cmp -s $testroot/stdout.expected $testroot/stdout
1536 ret=$?
1537 if [ $ret -ne 0 ]; then
1538 diff -u $testroot/stdout.expected $testroot/stdout
1540 test_done "$testroot" "$ret"
1543 test_histedit_fold_only() {
1544 local testroot=`test_init histedit_fold_only`
1546 local orig_commit=`git_show_head $testroot/repo`
1548 echo "modified alpha on master" > $testroot/repo/alpha
1549 (cd $testroot/repo && git rm -q beta)
1550 echo "new file on master" > $testroot/repo/epsilon/new
1551 (cd $testroot/repo && git add epsilon/new)
1552 git_commit $testroot/repo -m "committing changes"
1553 local old_commit1=`git_show_head $testroot/repo`
1555 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1556 git_commit $testroot/repo -m "committing to zeta on master"
1557 local old_commit2=`git_show_head $testroot/repo`
1559 echo "modified delta on master" > $testroot/repo/gamma/delta
1560 git_commit $testroot/repo -m "committing to delta on master"
1561 local old_commit3=`git_show_head $testroot/repo`
1563 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1564 ret=$?
1565 if [ $ret -ne 0 ]; then
1566 test_done "$testroot" "$ret"
1567 return 1
1570 cat > $testroot/editor.sh <<EOF
1571 #!/bin/sh
1572 SOPTS='-i ""'
1573 [ "\$OSTYPE" = "linux-gnu" ] && SOPTS="-i"
1574 sed "\$SOPTS" -e 's/.*/committing folded changes/' "\$1"
1575 EOF
1576 chmod +x $testroot/editor.sh
1578 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1579 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1581 local new_commit1=`git_show_head $testroot/repo`
1583 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1584 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1585 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1586 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1587 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1589 echo "G alpha" > $testroot/stdout.expected
1590 echo "D beta" >> $testroot/stdout.expected
1591 echo "A epsilon/new" >> $testroot/stdout.expected
1592 echo "$short_old_commit1 -> fold commit: committing changes" \
1593 >> $testroot/stdout.expected
1594 echo "G epsilon/zeta" >> $testroot/stdout.expected
1595 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1596 echo "fold commit: committing to zeta on master" \
1597 >> $testroot/stdout.expected
1598 echo "G gamma/delta" >> $testroot/stdout.expected
1599 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1600 >> $testroot/stdout.expected
1601 echo "committing folded changes" >> $testroot/stdout.expected
1602 echo "Switching work tree to refs/heads/master" \
1603 >> $testroot/stdout.expected
1605 cmp -s $testroot/stdout.expected $testroot/stdout
1606 ret=$?
1607 if [ $ret -ne 0 ]; then
1608 diff -u $testroot/stdout.expected $testroot/stdout
1609 test_done "$testroot" "$ret"
1610 return 1
1613 echo "modified alpha on master" > $testroot/content.expected
1614 cat $testroot/wt/alpha > $testroot/content
1615 cmp -s $testroot/content.expected $testroot/content
1616 ret=$?
1617 if [ $ret -ne 0 ]; then
1618 diff -u $testroot/content.expected $testroot/content
1619 test_done "$testroot" "$ret"
1620 return 1
1623 if [ -e $testroot/wt/beta ]; then
1624 echo "removed file beta still exists on disk" >&2
1625 test_done "$testroot" "1"
1626 return 1
1629 echo "new file on master" > $testroot/content.expected
1630 cat $testroot/wt/epsilon/new > $testroot/content
1631 cmp -s $testroot/content.expected $testroot/content
1632 ret=$?
1633 if [ $ret -ne 0 ]; then
1634 diff -u $testroot/content.expected $testroot/content
1635 test_done "$testroot" "$ret"
1636 return 1
1639 (cd $testroot/wt && got status > $testroot/stdout)
1641 echo -n > $testroot/stdout.expected
1642 cmp -s $testroot/stdout.expected $testroot/stdout
1643 ret=$?
1644 if [ $ret -ne 0 ]; then
1645 diff -u $testroot/stdout.expected $testroot/stdout
1646 test_done "$testroot" "$ret"
1647 return 1
1650 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1651 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1652 echo "commit $orig_commit" >> $testroot/stdout.expected
1653 cmp -s $testroot/stdout.expected $testroot/stdout
1654 ret=$?
1655 if [ $ret -ne 0 ]; then
1656 diff -u $testroot/stdout.expected $testroot/stdout
1658 test_done "$testroot" "$ret"
1661 test_histedit_fold_only_empty_logmsg() {
1662 local testroot=`test_init histedit_fold_only_empty_logmsg`
1664 local orig_commit=`git_show_head $testroot/repo`
1666 echo "modified alpha on master" > $testroot/repo/alpha
1667 (cd $testroot/repo && git rm -q beta)
1668 echo "new file on master" > $testroot/repo/epsilon/new
1669 (cd $testroot/repo && git add epsilon/new)
1670 git_commit $testroot/repo -m "committing changes"
1671 local old_commit1=`git_show_head $testroot/repo`
1673 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1674 git_commit $testroot/repo -m "committing to zeta on master"
1675 local old_commit2=`git_show_head $testroot/repo`
1677 echo "modified delta on master" > $testroot/repo/gamma/delta
1678 git_commit $testroot/repo -m "committing to delta on master"
1679 local old_commit3=`git_show_head $testroot/repo`
1681 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1682 ret=$?
1683 if [ $ret -ne 0 ]; then
1684 test_done "$testroot" "$ret"
1685 return 1
1688 cat > $testroot/editor.sh <<EOF
1689 #!/bin/sh
1690 SOPTS='-i ""'
1691 [ "\$OSTYPE" = "linux-gnu" ] && SOPTS="-i"
1692 sed "\$SOPTS" -e 'd' "\$1"
1693 EOF
1694 chmod +x $testroot/editor.sh
1696 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1697 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1699 local new_commit1=`git_show_head $testroot/repo`
1701 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1702 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1703 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1704 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1705 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1706 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1708 echo "G alpha" > $testroot/stdout.expected
1709 echo "D beta" >> $testroot/stdout.expected
1710 echo "A epsilon/new" >> $testroot/stdout.expected
1711 echo "$short_old_commit1 -> fold commit: committing changes" \
1712 >> $testroot/stdout.expected
1713 echo "G epsilon/zeta" >> $testroot/stdout.expected
1714 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1715 echo "fold commit: committing to zeta on master" \
1716 >> $testroot/stdout.expected
1717 echo "G gamma/delta" >> $testroot/stdout.expected
1718 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1719 >> $testroot/stdout.expected
1720 echo "# log message of folded commit $very_short_old_commit1" \
1721 >> $testroot/stdout.expected
1722 echo "Switching work tree to refs/heads/master" \
1723 >> $testroot/stdout.expected
1725 cmp -s $testroot/stdout.expected $testroot/stdout
1726 ret=$?
1727 if [ $ret -ne 0 ]; then
1728 diff -u $testroot/stdout.expected $testroot/stdout
1729 test_done "$testroot" "$ret"
1730 return 1
1733 echo "modified alpha on master" > $testroot/content.expected
1734 cat $testroot/wt/alpha > $testroot/content
1735 cmp -s $testroot/content.expected $testroot/content
1736 ret=$?
1737 if [ $ret -ne 0 ]; then
1738 diff -u $testroot/content.expected $testroot/content
1739 test_done "$testroot" "$ret"
1740 return 1
1743 if [ -e $testroot/wt/beta ]; then
1744 echo "removed file beta still exists on disk" >&2
1745 test_done "$testroot" "1"
1746 return 1
1749 echo "new file on master" > $testroot/content.expected
1750 cat $testroot/wt/epsilon/new > $testroot/content
1751 cmp -s $testroot/content.expected $testroot/content
1752 ret=$?
1753 if [ $ret -ne 0 ]; then
1754 diff -u $testroot/content.expected $testroot/content
1755 test_done "$testroot" "$ret"
1756 return 1
1759 (cd $testroot/wt && got status > $testroot/stdout)
1761 echo -n > $testroot/stdout.expected
1762 cmp -s $testroot/stdout.expected $testroot/stdout
1763 ret=$?
1764 if [ $ret -ne 0 ]; then
1765 diff -u $testroot/stdout.expected $testroot/stdout
1766 test_done "$testroot" "$ret"
1767 return 1
1770 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1771 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1772 echo "commit $orig_commit" >> $testroot/stdout.expected
1773 cmp -s $testroot/stdout.expected $testroot/stdout
1774 ret=$?
1775 if [ $ret -ne 0 ]; then
1776 diff -u $testroot/stdout.expected $testroot/stdout
1778 test_done "$testroot" "$ret"
1781 test_histedit_edit_only() {
1782 local testroot=`test_init histedit_edit_only`
1784 local orig_commit=`git_show_head $testroot/repo`
1786 echo "modified alpha on master" > $testroot/repo/alpha
1787 (cd $testroot/repo && git rm -q beta)
1788 echo "new file on master" > $testroot/repo/epsilon/new
1789 (cd $testroot/repo && git add epsilon/new)
1790 git_commit $testroot/repo -m "committing changes"
1791 local old_commit1=`git_show_head $testroot/repo`
1793 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1794 git_commit $testroot/repo -m "committing to zeta on master"
1795 local old_commit2=`git_show_head $testroot/repo`
1797 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1798 ret=$?
1799 if [ $ret -ne 0 ]; then
1800 test_done "$testroot" "$ret"
1801 return 1
1804 (cd $testroot/wt && got histedit -e > $testroot/stdout)
1806 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1807 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1809 echo "G alpha" > $testroot/stdout.expected
1810 echo "D beta" >> $testroot/stdout.expected
1811 echo "A epsilon/new" >> $testroot/stdout.expected
1812 echo "Stopping histedit for amending commit $old_commit1" \
1813 >> $testroot/stdout.expected
1814 cmp -s $testroot/stdout.expected $testroot/stdout
1815 ret=$?
1816 if [ $ret -ne 0 ]; then
1817 diff -u $testroot/stdout.expected $testroot/stdout
1818 test_done "$testroot" "$ret"
1819 return 1
1822 echo "edited modified alpha on master" > $testroot/wt/alpha
1824 cat > $testroot/editor.sh <<EOF
1825 #!/bin/sh
1826 sed -i 's/.*/committing edited changes 1/' "\$1"
1827 EOF
1828 chmod +x $testroot/editor.sh
1830 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1831 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1833 local new_commit1=$(cd $testroot/wt && got info | \
1834 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1835 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1837 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1838 > $testroot/stdout.expected
1839 echo "committing edited changes 1" >> $testroot/stdout.expected
1840 echo "G epsilon/zeta" >> $testroot/stdout.expected
1841 echo "Stopping histedit for amending commit $old_commit2" \
1842 >> $testroot/stdout.expected
1843 cmp -s $testroot/stdout.expected $testroot/stdout
1844 ret=$?
1845 if [ $ret -ne 0 ]; then
1846 diff -u $testroot/stdout.expected $testroot/stdout
1847 test_done "$testroot" "$ret"
1848 return 1
1851 echo "edited zeta on master" > $testroot/wt/epsilon/zeta
1853 cat > $testroot/editor.sh <<EOF
1854 #!/bin/sh
1855 sed -i 's/.*/committing edited changes 2/' "\$1"
1856 EOF
1857 chmod +x $testroot/editor.sh
1859 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1860 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1862 local new_commit2=`git_show_head $testroot/repo`
1863 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1865 echo -n "$short_old_commit2 -> $short_new_commit2: " \
1866 > $testroot/stdout.expected
1867 echo "committing edited changes 2" >> $testroot/stdout.expected
1868 echo "Switching work tree to refs/heads/master" \
1869 >> $testroot/stdout.expected
1871 cmp -s $testroot/stdout.expected $testroot/stdout
1872 ret=$?
1873 if [ $ret -ne 0 ]; then
1874 diff -u $testroot/stdout.expected $testroot/stdout
1875 test_done "$testroot" "$ret"
1876 return 1
1879 echo "edited modified alpha on master" > $testroot/content.expected
1880 cat $testroot/wt/alpha > $testroot/content
1881 cmp -s $testroot/content.expected $testroot/content
1882 ret=$?
1883 if [ $ret -ne 0 ]; then
1884 diff -u $testroot/content.expected $testroot/content
1885 test_done "$testroot" "$ret"
1886 return 1
1889 if [ -e $testroot/wt/beta ]; then
1890 echo "removed file beta still exists on disk" >&2
1891 test_done "$testroot" "1"
1892 return 1
1895 echo "new file on master" > $testroot/content.expected
1896 cat $testroot/wt/epsilon/new > $testroot/content
1897 cmp -s $testroot/content.expected $testroot/content
1898 ret=$?
1899 if [ $ret -ne 0 ]; then
1900 diff -u $testroot/content.expected $testroot/content
1901 test_done "$testroot" "$ret"
1902 return 1
1905 (cd $testroot/wt && got status > $testroot/stdout)
1907 echo -n > $testroot/stdout.expected
1908 cmp -s $testroot/stdout.expected $testroot/stdout
1909 ret=$?
1910 if [ $ret -ne 0 ]; then
1911 diff -u $testroot/stdout.expected $testroot/stdout
1912 test_done "$testroot" "$ret"
1913 return 1
1916 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1917 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
1918 echo "commit $new_commit1" >> $testroot/stdout.expected
1919 echo "commit $orig_commit" >> $testroot/stdout.expected
1920 cmp -s $testroot/stdout.expected $testroot/stdout
1921 ret=$?
1922 if [ $ret -ne 0 ]; then
1923 diff -u $testroot/stdout.expected $testroot/stdout
1925 test_done "$testroot" "$ret"
1928 test_histedit_prepend_line() {
1929 local testroot=`test_init histedit_prepend_line`
1930 local orig_commit=`git_show_head $testroot/repo`
1932 got checkout $testroot/repo $testroot/wt > /dev/null
1934 ed "$testroot/wt/alpha" <<EOF >/dev/null 2>&1
1936 first line
1939 EOF
1941 cp $testroot/wt/alpha $testroot/content.expected
1943 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
1944 alpha > /dev/null)
1945 ret=$?
1946 if [ "$?" != 0 ]; then
1947 echo "got commit failed unexpectedly" >&2
1948 test_done "$testroot" "$ret"
1949 return 1
1952 local top_commit=`git_show_head $testroot/repo`
1953 echo "pick $top_commit" > "$testroot/histedit-script"
1955 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
1956 ret=$?
1957 if [ "$?" != 0 ]; then
1958 echo "got update failed unexpectedly" >&2
1959 test_done "$testroot" "$ret"
1960 return 1
1963 (cd $testroot/wt && got histedit -F "$testroot/histedit-script" \
1964 > /dev/null)
1965 ret=$?
1966 if [ "$?" != 0 ]; then
1967 echo "got histedit failed unexpectedly" >&2
1968 test_done "$testroot" "$ret"
1969 return 1
1972 cp $testroot/wt/alpha $testroot/content
1973 cmp -s $testroot/content.expected $testroot/content
1974 ret=$?
1975 if [ $ret -ne 0 ]; then
1976 diff -u $testroot/content.expected $testroot/content
1977 test_done "$testroot" "$ret"
1978 return 1
1981 test_done "$testroot" $ret
1984 test_parseargs "$@"
1985 run_test test_histedit_no_op
1986 run_test test_histedit_swap
1987 run_test test_histedit_drop
1988 run_test test_histedit_fold
1989 run_test test_histedit_edit
1990 run_test test_histedit_fold_last_commit
1991 run_test test_histedit_missing_commit
1992 run_test test_histedit_abort
1993 run_test test_histedit_path_prefix_drop
1994 run_test test_histedit_path_prefix_edit
1995 run_test test_histedit_outside_refs_heads
1996 run_test test_histedit_fold_last_commit_swap
1997 run_test test_histedit_split_commit
1998 run_test test_histedit_duplicate_commit_in_script
1999 run_test test_histedit_fold_add_delete
2000 run_test test_histedit_fold_only
2001 run_test test_histedit_fold_only_empty_logmsg
2002 run_test test_histedit_edit_only
2003 run_test test_histedit_prepend_line