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
748 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
749 > $testroot/stdout 2> $testroot/stderr)
751 ret=$?
752 if [ $ret -eq 0 ]; then
753 echo "histedit succeeded unexpectedly" >&2
754 test_done "$testroot" "1"
755 return 1
756 fi
758 echo "got: last commit in histedit script cannot be folded" \
759 > $testroot/stderr.expected
761 cmp -s $testroot/stderr.expected $testroot/stderr
762 ret=$?
763 if [ $ret -ne 0 ]; then
764 diff -u $testroot/stderr.expected $testroot/stderr
765 fi
766 test_done "$testroot" "$ret"
769 test_histedit_missing_commit() {
770 local testroot=`test_init histedit_missing_commit`
772 local orig_commit=`git_show_head $testroot/repo`
774 echo "modified alpha on master" > $testroot/repo/alpha
775 (cd $testroot/repo && git rm -q beta)
776 echo "new file on master" > $testroot/repo/epsilon/new
777 (cd $testroot/repo && git add epsilon/new)
778 git_commit $testroot/repo -m "committing changes"
779 local old_commit1=`git_show_head $testroot/repo`
781 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
782 git_commit $testroot/repo -m "committing to zeta on master"
783 local old_commit2=`git_show_head $testroot/repo`
785 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
786 ret=$?
787 if [ $ret -ne 0 ]; then
788 test_done "$testroot" "$ret"
789 return 1
790 fi
792 echo "pick $old_commit1" > $testroot/histedit-script
793 echo "mesg committing changes" >> $testroot/histedit-script
795 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
796 > $testroot/stdout 2> $testroot/stderr)
798 ret=$?
799 if [ $ret -eq 0 ]; then
800 echo "histedit succeeded unexpectedly" >&2
801 test_done "$testroot" "1"
802 return 1
803 fi
805 echo "got: commit $old_commit2 missing from histedit script" \
806 > $testroot/stderr.expected
808 cmp -s $testroot/stderr.expected $testroot/stderr
809 ret=$?
810 if [ $ret -ne 0 ]; then
811 diff -u $testroot/stderr.expected $testroot/stderr
812 fi
813 test_done "$testroot" "$ret"
816 test_histedit_abort() {
817 local testroot=`test_init histedit_abort`
819 local orig_commit=`git_show_head $testroot/repo`
821 echo "modified alpha on master" > $testroot/repo/alpha
822 (cd $testroot/repo && git rm -q beta)
823 echo "new file on master" > $testroot/repo/epsilon/new
824 (cd $testroot/repo && git add epsilon/new)
825 git_commit $testroot/repo -m "committing changes"
826 local old_commit1=`git_show_head $testroot/repo`
828 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
829 git_commit $testroot/repo -m "committing to zeta on master"
830 local old_commit2=`git_show_head $testroot/repo`
832 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
833 ret=$?
834 if [ $ret -ne 0 ]; then
835 test_done "$testroot" "$ret"
836 return 1
837 fi
839 # unrelated unversioned file in work tree
840 touch $testroot/wt/unversioned-file
842 echo "edit $old_commit1" > $testroot/histedit-script
843 echo "mesg committing changes" >> $testroot/histedit-script
844 echo "pick $old_commit2" >> $testroot/histedit-script
846 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
847 > $testroot/stdout)
849 local short_old_commit1=`trim_obj_id 28 $old_commit1`
850 local short_old_commit2=`trim_obj_id 28 $old_commit2`
852 echo "G alpha" > $testroot/stdout.expected
853 echo "D beta" >> $testroot/stdout.expected
854 echo "A epsilon/new" >> $testroot/stdout.expected
855 echo "Stopping histedit for amending commit $old_commit1" \
856 >> $testroot/stdout.expected
857 cmp -s $testroot/stdout.expected $testroot/stdout
858 ret=$?
859 if [ $ret -ne 0 ]; then
860 diff -u $testroot/stdout.expected $testroot/stdout
861 test_done "$testroot" "$ret"
862 return 1
863 fi
865 echo "edited modified alpha on master" > $testroot/wt/alpha
867 (cd $testroot/wt && got histedit -a > $testroot/stdout)
869 local new_commit1=`git_show_parent_commit $testroot/repo`
870 local new_commit2=`git_show_head $testroot/repo`
872 echo "Switching work tree to refs/heads/master" \
873 > $testroot/stdout.expected
874 echo "R alpha" >> $testroot/stdout.expected
875 echo "R beta" >> $testroot/stdout.expected
876 echo "R epsilon/new" >> $testroot/stdout.expected
877 echo "Histedit of refs/heads/master aborted" \
878 >> $testroot/stdout.expected
880 cmp -s $testroot/stdout.expected $testroot/stdout
881 ret=$?
882 if [ $ret -ne 0 ]; then
883 diff -u $testroot/stdout.expected $testroot/stdout
884 test_done "$testroot" "$ret"
885 return 1
886 fi
888 for f in alpha beta; do
889 echo "$f" > $testroot/content.expected
890 cat $testroot/wt/$f > $testroot/content
891 cmp -s $testroot/content.expected $testroot/content
892 ret=$?
893 if [ $ret -ne 0 ]; then
894 diff -u $testroot/content.expected $testroot/content
895 test_done "$testroot" "$ret"
896 return 1
897 fi
898 done
900 echo "new file on master" > $testroot/content.expected
901 cat $testroot/wt/epsilon/new > $testroot/content
902 cmp -s $testroot/content.expected $testroot/content
903 ret=$?
904 if [ $ret -ne 0 ]; then
905 diff -u $testroot/content.expected $testroot/content
906 test_done "$testroot" "$ret"
907 return 1
908 fi
910 (cd $testroot/wt && got status > $testroot/stdout)
912 echo "? epsilon/new" > $testroot/stdout.expected
913 echo "? unversioned-file" >> $testroot/stdout.expected
914 cmp -s $testroot/stdout.expected $testroot/stdout
915 ret=$?
916 if [ $ret -ne 0 ]; then
917 diff -u $testroot/stdout.expected $testroot/stdout
918 test_done "$testroot" "$ret"
919 return 1
920 fi
922 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
923 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
924 echo "commit $new_commit1" >> $testroot/stdout.expected
925 echo "commit $orig_commit" >> $testroot/stdout.expected
926 cmp -s $testroot/stdout.expected $testroot/stdout
927 ret=$?
928 if [ $ret -ne 0 ]; then
929 diff -u $testroot/stdout.expected $testroot/stdout
930 fi
931 test_done "$testroot" "$ret"
934 test_histedit_path_prefix_drop() {
935 local testroot=`test_init histedit_path_prefix_drop`
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 checkout -c $orig_commit -p gamma $testroot/repo \
943 $testroot/wt > /dev/null
944 ret=$?
945 if [ $ret -ne 0 ]; then
946 test_done "$testroot" "$ret"
947 return 1
948 fi
950 echo "drop $old_commit1" > $testroot/histedit-script
952 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
953 > $testroot/stdout 2> $testroot/stderr)
955 ret=$?
956 if [ $ret -eq 0 ]; then
957 echo "histedit succeeded unexpectedly" >&2
958 test_done "$testroot" "1"
959 return 1
960 fi
962 echo -n "got: cannot edit branch history which contains changes " \
963 > $testroot/stderr.expected
964 echo "outside of this work tree's path prefix" \
965 >> $testroot/stderr.expected
967 cmp -s $testroot/stderr.expected $testroot/stderr
968 ret=$?
969 if [ $ret -ne 0 ]; then
970 diff -u $testroot/stderr.expected $testroot/stderr
971 test_done "$testroot" "$ret"
972 return 1
973 fi
975 rm -rf $testroot/wt
976 got checkout -c $orig_commit -p epsilon $testroot/repo \
977 $testroot/wt > /dev/null
978 ret=$?
979 if [ $ret -ne 0 ]; then
980 test_done "$testroot" "$ret"
981 return 1
982 fi
983 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
984 > $testroot/stdout)
986 local short_old_commit1=`trim_obj_id 28 $old_commit1`
987 local short_old_commit2=`trim_obj_id 28 $old_commit2`
989 echo "$short_old_commit1 -> drop commit: changing zeta" \
990 > $testroot/stdout.expected
991 echo "Switching work tree to refs/heads/master" \
992 >> $testroot/stdout.expected
994 cmp -s $testroot/stdout.expected $testroot/stdout
995 ret=$?
996 if [ $ret -ne 0 ]; then
997 diff -u $testroot/stdout.expected $testroot/stdout
998 test_done "$testroot" "$ret"
999 return 1
1002 echo "zeta" > $testroot/content.expected
1003 cat $testroot/wt/zeta > $testroot/content
1004 cmp -s $testroot/content.expected $testroot/content
1005 ret=$?
1006 if [ $ret -ne 0 ]; then
1007 diff -u $testroot/content.expected $testroot/content
1008 test_done "$testroot" "$ret"
1009 return 1
1013 (cd $testroot/wt && got status > $testroot/stdout)
1015 echo -n > $testroot/stdout.expected
1016 cmp -s $testroot/stdout.expected $testroot/stdout
1017 ret=$?
1018 if [ $ret -ne 0 ]; then
1019 diff -u $testroot/stdout.expected $testroot/stdout
1020 test_done "$testroot" "$ret"
1021 return 1
1024 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1025 echo "commit $orig_commit (master)" > $testroot/stdout.expected
1026 cmp -s $testroot/stdout.expected $testroot/stdout
1027 ret=$?
1028 if [ $ret -ne 0 ]; then
1029 diff -u $testroot/stdout.expected $testroot/stdout
1031 test_done "$testroot" "$ret"
1034 test_histedit_path_prefix_edit() {
1035 local testroot=`test_init histedit_path_prefix_edit`
1036 local orig_commit=`git_show_head $testroot/repo`
1038 echo "modified zeta" > $testroot/repo/epsilon/zeta
1039 git_commit $testroot/repo -m "changing zeta"
1040 local old_commit1=`git_show_head $testroot/repo`
1042 got diff -r $testroot/repo $orig_commit $old_commit1 \
1043 > $testroot/diff.expected
1045 got checkout -c $orig_commit -p gamma $testroot/repo \
1046 $testroot/wt > /dev/null
1047 ret=$?
1048 if [ $ret -ne 0 ]; then
1049 test_done "$testroot" "$ret"
1050 return 1
1053 echo "edit $old_commit1" > $testroot/histedit-script
1054 echo "mesg modified zeta" >> $testroot/histedit-script
1056 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1057 > $testroot/stdout 2> $testroot/stderr)
1059 ret=$?
1060 if [ $ret -eq 0 ]; then
1061 echo "histedit succeeded unexpectedly" >&2
1062 test_done "$testroot" "1"
1063 return 1
1066 echo -n "got: cannot edit branch history which contains changes " \
1067 > $testroot/stderr.expected
1068 echo "outside of this work tree's path prefix" \
1069 >> $testroot/stderr.expected
1071 cmp -s $testroot/stderr.expected $testroot/stderr
1072 ret=$?
1073 if [ $ret -ne 0 ]; then
1074 diff -u $testroot/stderr.expected $testroot/stderr
1075 test_done "$testroot" "$ret"
1076 return 1
1079 rm -rf $testroot/wt
1080 got checkout -c $orig_commit -p epsilon $testroot/repo \
1081 $testroot/wt > /dev/null
1082 ret=$?
1083 if [ $ret -ne 0 ]; then
1084 test_done "$testroot" "$ret"
1085 return 1
1087 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1088 > $testroot/stdout)
1090 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1092 echo "G zeta" > $testroot/stdout.expected
1093 echo "Stopping histedit for amending commit $old_commit1" \
1094 >> $testroot/stdout.expected
1095 cmp -s $testroot/stdout.expected $testroot/stdout
1096 ret=$?
1097 if [ $ret -ne 0 ]; then
1098 diff -u $testroot/stdout.expected $testroot/stdout
1099 test_done "$testroot" "$ret"
1100 return 1
1103 echo "modified zeta" > $testroot/content.expected
1104 cat $testroot/wt/zeta > $testroot/content
1105 cmp -s $testroot/content.expected $testroot/content
1106 ret=$?
1107 if [ $ret -ne 0 ]; then
1108 diff -u $testroot/content.expected $testroot/content
1109 test_done "$testroot" "$ret"
1110 return 1
1113 (cd $testroot/wt && got status > $testroot/stdout)
1115 echo "M zeta"> $testroot/stdout.expected
1116 cmp -s $testroot/stdout.expected $testroot/stdout
1117 ret=$?
1118 if [ $ret -ne 0 ]; then
1119 diff -u $testroot/stdout.expected $testroot/stdout
1120 test_done "$testroot" "$ret"
1121 return 1
1124 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1126 local new_commit1=`git_show_head $testroot/repo`
1127 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1129 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1130 > $testroot/stdout.expected
1131 echo "modified zeta" >> $testroot/stdout.expected
1132 echo "Switching work tree to refs/heads/master" \
1133 >> $testroot/stdout.expected
1135 cmp -s $testroot/stdout.expected $testroot/stdout
1136 ret=$?
1137 if [ $ret -ne 0 ]; then
1138 diff -u $testroot/stdout.expected $testroot/stdout
1139 test_done "$testroot" "$ret"
1140 return 1
1143 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1144 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1145 echo "commit $orig_commit" >> $testroot/stdout.expected
1146 cmp -s $testroot/stdout.expected $testroot/stdout
1147 ret=$?
1148 if [ $ret -ne 0 ]; then
1149 diff -u $testroot/stdout.expected $testroot/stdout
1150 test_done "$testroot" "$ret"
1151 return 1
1154 got diff -r $testroot/repo $orig_commit $new_commit1 \
1155 > $testroot/diff
1156 sed -i '' -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1157 cmp -s $testroot/diff.expected $testroot/diff
1158 ret=$?
1159 if [ $ret -ne 0 ]; then
1160 diff -u $testroot/diff.expected $testroot/diff
1162 test_done "$testroot" "$ret"
1165 test_histedit_outside_refs_heads() {
1166 local testroot=`test_init histedit_outside_refs_heads`
1167 local commit1=`git_show_head $testroot/repo`
1169 got checkout $testroot/repo $testroot/wt > /dev/null
1170 ret=$?
1171 if [ $ret -ne 0 ]; then
1172 echo "got checkout failed unexpectedly"
1173 test_done "$testroot" "$ret"
1174 return 1
1177 echo "modified alpha" > $testroot/wt/alpha
1179 (cd $testroot/wt && got commit -m 'change alpha' \
1180 > $testroot/stdout 2> $testroot/stderr)
1181 ret=$?
1182 if [ $ret -ne 0 ]; then
1183 echo "got commit failed unexpectedly" >&2
1184 test_done "$testroot" "1"
1185 return 1
1187 local commit2=`git_show_head $testroot/repo`
1189 got ref -r $testroot/repo -c master refs/remotes/origin/master
1190 ret=$?
1191 if [ $ret -ne 0 ]; then
1192 echo "got ref failed unexpectedly" >&2
1193 test_done "$testroot" "1"
1194 return 1
1197 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1198 ret=$?
1199 if [ $ret -ne 0 ]; then
1200 echo "got update failed unexpectedly"
1201 test_done "$testroot" "$ret"
1202 return 1
1205 echo "edit $commit2" > $testroot/histedit-script
1206 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1207 2> $testroot/stderr)
1209 echo -n "got: will not edit commit history of a branch outside the " \
1210 > $testroot/stderr.expected
1211 echo '"refs/heads/" reference namespace' \
1212 >> $testroot/stderr.expected
1213 cmp -s $testroot/stderr.expected $testroot/stderr
1214 ret=$?
1215 if [ $ret -ne 0 ]; then
1216 diff -u $testroot/stderr.expected $testroot/stderr
1218 test_done "$testroot" "$ret"
1221 test_histedit_fold_last_commit_swap() {
1222 local testroot=`test_init histedit_fold_last_commit_swap`
1224 local orig_commit=`git_show_head $testroot/repo`
1226 echo "modified alpha on master" > $testroot/repo/alpha
1227 (cd $testroot/repo && git rm -q beta)
1228 echo "new file on master" > $testroot/repo/epsilon/new
1229 (cd $testroot/repo && git add epsilon/new)
1230 git_commit $testroot/repo -m "committing changes"
1231 local old_commit1=`git_show_head $testroot/repo`
1233 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1234 git_commit $testroot/repo -m "committing to zeta on master"
1235 local old_commit2=`git_show_head $testroot/repo`
1237 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1238 ret=$?
1239 if [ $ret -ne 0 ]; then
1240 test_done "$testroot" "$ret"
1241 return 1
1244 # fold commit2 into commit1 (requires swapping commits)
1245 echo "fold $old_commit2" > $testroot/histedit-script
1246 echo "pick $old_commit1" >> $testroot/histedit-script
1247 echo "mesg committing folded changes" >> $testroot/histedit-script
1249 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1250 > $testroot/stdout 2> $testroot/stderr)
1252 ret=$?
1253 if [ $ret -ne 0 ]; then
1254 echo "histedit failed unexpectedly" >&2
1255 test_done "$testroot" "$ret"
1256 return 1
1259 local new_commit=`git_show_head $testroot/repo`
1261 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1262 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1263 local short_new_commit=`trim_obj_id 28 $new_commit`
1265 echo "G epsilon/zeta" >> $testroot/stdout.expected
1266 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1267 >> $testroot/stdout.expected
1268 echo "on master" >> $testroot/stdout.expected
1269 echo "G alpha" >> $testroot/stdout.expected
1270 echo "D beta" >> $testroot/stdout.expected
1271 echo "A epsilon/new" >> $testroot/stdout.expected
1272 echo -n "$short_old_commit1 -> $short_new_commit: " \
1273 >> $testroot/stdout.expected
1274 echo "committing folded changes" >> $testroot/stdout.expected
1275 echo "Switching work tree to refs/heads/master" \
1276 >> $testroot/stdout.expected
1278 cmp -s $testroot/stdout.expected $testroot/stdout
1279 ret=$?
1280 if [ $ret -ne 0 ]; then
1281 diff -u $testroot/stdout.expected $testroot/stdout
1283 test_done "$testroot" "$ret"
1286 test_histedit_split_commit() {
1287 local testroot=`test_init histedit_split_commit`
1289 local orig_commit=`git_show_head $testroot/repo`
1291 echo "modified alpha on master" > $testroot/repo/alpha
1292 (cd $testroot/repo && git rm -q beta)
1293 echo "new file on master" > $testroot/repo/epsilon/new
1294 (cd $testroot/repo && git add epsilon/new)
1295 git_commit $testroot/repo -m "committing changes 1"
1296 local old_commit1=`git_show_head $testroot/repo`
1297 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1299 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1300 git_commit $testroot/repo -m "committing changes 2"
1301 local old_commit2=`git_show_head $testroot/repo`
1302 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1304 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1305 ret=$?
1306 if [ $ret -ne 0 ]; then
1307 test_done "$testroot" "$ret"
1308 return 1
1311 # split commit1 into commitA and commitB and commitC
1312 echo "e $old_commit1" > $testroot/histedit-script
1313 echo "p $old_commit2" >> $testroot/histedit-script
1315 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1316 > $testroot/stdout 2> $testroot/stderr)
1317 ret=$?
1318 if [ $ret -ne 0 ]; then
1319 echo "histedit failed unexpectedly:" >&2
1320 cat $testroot/stderr >&2
1321 test_done "$testroot" "$ret"
1322 return 1
1325 echo "G alpha" > $testroot/stdout.expected
1326 echo "D beta" >> $testroot/stdout.expected
1327 echo "A epsilon/new" >> $testroot/stdout.expected
1328 echo "Stopping histedit for amending commit $old_commit1" \
1329 >> $testroot/stdout.expected
1331 cmp -s $testroot/stdout.expected $testroot/stdout
1332 ret=$?
1333 if [ $ret -ne 0 ]; then
1334 diff -u $testroot/stdout.expected $testroot/stdout
1335 test_done "$testroot" "$ret"
1336 return 1
1339 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1340 ret=$?
1341 if [ $ret -ne 0 ]; then
1342 echo "commit failed unexpectedly" >&2
1343 test_done "$testroot" "$ret"
1344 return 1
1347 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1348 ret=$?
1349 if [ $ret -ne 0 ]; then
1350 echo "commit failed unexpectedly" >&2
1351 test_done "$testroot" "$ret"
1352 return 1
1355 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1356 ret=$?
1357 if [ $ret -ne 0 ]; then
1358 echo "commit failed unexpectedly" >&2
1359 test_done "$testroot" "$ret"
1360 return 1
1363 (cd $testroot/wt && got histedit -c \
1364 > $testroot/stdout 2> $testroot/stderr)
1365 ret=$?
1366 if [ $ret -ne 0 ]; then
1367 echo "histedit failed unexpectedly:" >&2
1368 cat $testroot/stderr >&2
1369 test_done "$testroot" "$ret"
1370 return 1
1372 local new_commit2=`git_show_head $testroot/repo`
1373 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1375 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1376 > $testroot/stdout.expected
1377 echo "G epsilon/zeta" >> $testroot/stdout.expected
1378 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1379 >> $testroot/stdout.expected
1380 echo "Switching work tree to refs/heads/master" \
1381 >> $testroot/stdout.expected
1383 cmp -s $testroot/stdout.expected $testroot/stdout
1384 ret=$?
1385 if [ $ret -ne 0 ]; then
1386 diff -u $testroot/stdout.expected $testroot/stdout
1388 test_done "$testroot" "$ret"
1392 test_histedit_duplicate_commit_in_script() {
1393 local testroot=`test_init histedit_duplicate_commit_in_script`
1395 local orig_commit=`git_show_head $testroot/repo`
1397 echo "modified alpha on master" > $testroot/repo/alpha
1398 (cd $testroot/repo && git rm -q beta)
1399 echo "new file on master" > $testroot/repo/epsilon/new
1400 (cd $testroot/repo && git add epsilon/new)
1401 git_commit $testroot/repo -m "committing changes 1"
1402 local old_commit1=`git_show_head $testroot/repo`
1404 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1405 git_commit $testroot/repo -m "committing changes 2"
1406 local old_commit2=`git_show_head $testroot/repo`
1408 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1409 ret=$?
1410 if [ $ret -ne 0 ]; then
1411 test_done "$testroot" "$ret"
1412 return 1
1415 # This histedit script lists commit1 more than once
1416 echo "p $old_commit1" > $testroot/histedit-script
1417 echo "p $old_commit1" >> $testroot/histedit-script
1418 echo "p $old_commit2" >> $testroot/histedit-script
1420 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1421 > $testroot/stdout 2> $testroot/stderr)
1422 ret=$?
1423 if [ $ret -eq 0 ]; then
1424 echo "histedit succeeded unexpectedly:" >&2
1425 cat $testroot/stdout >&2
1426 test_done "$testroot" "$ret"
1427 return 1
1430 echo -n "got: commit $old_commit1 is listed more than once " \
1431 > $testroot/stderr.expected
1432 echo "in histedit script" >> $testroot/stderr.expected
1434 cmp -s $testroot/stderr.expected $testroot/stderr
1435 ret=$?
1436 if [ $ret -ne 0 ]; then
1437 diff -u $testroot/stderr.expected $testroot/stderr
1439 test_done "$testroot" "$ret"
1443 # if a previous commit introduces a new file, and it is folded into a commit
1444 # that deletes the same file, the file still exists after the histedit
1445 test_histedit_fold_add_delete() {
1446 local testroot=`test_init histedit_fold_add_delete`
1448 local orig_commit=`git_show_head $testroot/repo`
1450 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1451 (cd $testroot/repo && git add epsilon/psi)
1452 git_commit $testroot/repo -m "committing changes"
1453 local old_commit1=`git_show_head $testroot/repo`
1455 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1456 git_commit $testroot/repo -m "editing psi"
1457 local old_commit2=`git_show_head $testroot/repo`
1459 (cd $testroot/repo && git rm -q epsilon/psi)
1460 git_commit $testroot/repo -m "removing psi"
1461 local old_commit3=`git_show_head $testroot/repo`
1463 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1464 ret=$?
1465 if [ $ret -ne 0 ]; then
1466 test_done "$testroot" "$ret"
1467 return 1
1470 echo "fold $old_commit1" > $testroot/histedit-script
1471 echo "fold $old_commit2" >> $testroot/histedit-script
1472 echo "pick $old_commit3" >> $testroot/histedit-script
1473 echo "mesg folded changes" >> $testroot/histedit-script
1475 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1476 > $testroot/stdout)
1478 local new_commit1=`git_show_head $testroot/repo`
1480 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1481 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1482 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1483 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1485 echo "A epsilon/psi" >> $testroot/stdout.expected
1486 echo "$short_old_commit1 -> fold commit: committing changes" \
1487 >> $testroot/stdout.expected
1488 echo "G epsilon/psi" >> $testroot/stdout.expected
1489 echo "$short_old_commit2 -> fold commit: editing psi" \
1490 >> $testroot/stdout.expected
1491 echo "D epsilon/psi" >> $testroot/stdout.expected
1492 echo "$short_old_commit3 -> no-op change: folded changes" \
1493 >> $testroot/stdout.expected
1494 echo "Switching work tree to refs/heads/master" \
1495 >> $testroot/stdout.expected
1497 cmp -s $testroot/stdout.expected $testroot/stdout
1498 ret=$?
1499 if [ $ret -ne 0 ]; then
1500 diff -u $testroot/stdout.expected $testroot/stdout
1501 test_done "$testroot" "$ret"
1502 return 1
1505 if [ -e $testroot/wt/epsilon/psi ]; then
1506 echo "removed file psi still exists on disk" >&2
1507 test_done "$testroot" "1"
1508 return 1
1511 (cd $testroot/wt && got status > $testroot/stdout)
1513 echo -n > $testroot/stdout.expected
1514 cmp -s $testroot/stdout.expected $testroot/stdout
1515 ret=$?
1516 if [ $ret -ne 0 ]; then
1517 diff -u $testroot/stdout.expected $testroot/stdout
1518 test_done "$testroot" "$ret"
1519 return 1
1522 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1523 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1524 cmp -s $testroot/stdout.expected $testroot/stdout
1525 ret=$?
1526 if [ $ret -ne 0 ]; then
1527 diff -u $testroot/stdout.expected $testroot/stdout
1528 test_done "$testroot" "$ret"
1529 return 1
1532 got tree -r $testroot/repo epsilon > $testroot/stdout
1533 echo "zeta" > $testroot/stdout.expected
1534 cmp -s $testroot/stdout.expected $testroot/stdout
1535 ret=$?
1536 if [ $ret -ne 0 ]; then
1537 diff -u $testroot/stdout.expected $testroot/stdout
1539 test_done "$testroot" "$ret"
1542 test_histedit_fold_only() {
1543 local testroot=`test_init histedit_fold_only`
1545 local orig_commit=`git_show_head $testroot/repo`
1547 echo "modified alpha on master" > $testroot/repo/alpha
1548 (cd $testroot/repo && git rm -q beta)
1549 echo "new file on master" > $testroot/repo/epsilon/new
1550 (cd $testroot/repo && git add epsilon/new)
1551 git_commit $testroot/repo -m "committing changes"
1552 local old_commit1=`git_show_head $testroot/repo`
1554 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1555 git_commit $testroot/repo -m "committing to zeta on master"
1556 local old_commit2=`git_show_head $testroot/repo`
1558 echo "modified delta on master" > $testroot/repo/gamma/delta
1559 git_commit $testroot/repo -m "committing to delta on master"
1560 local old_commit3=`git_show_head $testroot/repo`
1562 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1563 ret=$?
1564 if [ $ret -ne 0 ]; then
1565 test_done "$testroot" "$ret"
1566 return 1
1569 cat > $testroot/editor.sh <<EOF
1570 #!/bin/sh
1571 SOPTS='-i ""'
1572 [ "\$OSTYPE" = "linux-gnu" ] && SOPTS="-i"
1573 sed "\$SOPTS" -e 's/.*/committing folded changes/' "\$1"
1574 EOF
1575 chmod +x $testroot/editor.sh
1577 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1578 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1580 local new_commit1=`git_show_head $testroot/repo`
1582 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1583 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1584 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1585 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1586 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1588 echo "G alpha" > $testroot/stdout.expected
1589 echo "D beta" >> $testroot/stdout.expected
1590 echo "A epsilon/new" >> $testroot/stdout.expected
1591 echo "$short_old_commit1 -> fold commit: committing changes" \
1592 >> $testroot/stdout.expected
1593 echo "G epsilon/zeta" >> $testroot/stdout.expected
1594 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1595 echo "fold commit: committing to zeta on master" \
1596 >> $testroot/stdout.expected
1597 echo "G gamma/delta" >> $testroot/stdout.expected
1598 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1599 >> $testroot/stdout.expected
1600 echo "committing folded changes" >> $testroot/stdout.expected
1601 echo "Switching work tree to refs/heads/master" \
1602 >> $testroot/stdout.expected
1604 cmp -s $testroot/stdout.expected $testroot/stdout
1605 ret=$?
1606 if [ $ret -ne 0 ]; then
1607 diff -u $testroot/stdout.expected $testroot/stdout
1608 test_done "$testroot" "$ret"
1609 return 1
1612 echo "modified alpha on master" > $testroot/content.expected
1613 cat $testroot/wt/alpha > $testroot/content
1614 cmp -s $testroot/content.expected $testroot/content
1615 ret=$?
1616 if [ $ret -ne 0 ]; then
1617 diff -u $testroot/content.expected $testroot/content
1618 test_done "$testroot" "$ret"
1619 return 1
1622 if [ -e $testroot/wt/beta ]; then
1623 echo "removed file beta still exists on disk" >&2
1624 test_done "$testroot" "1"
1625 return 1
1628 echo "new file on master" > $testroot/content.expected
1629 cat $testroot/wt/epsilon/new > $testroot/content
1630 cmp -s $testroot/content.expected $testroot/content
1631 ret=$?
1632 if [ $ret -ne 0 ]; then
1633 diff -u $testroot/content.expected $testroot/content
1634 test_done "$testroot" "$ret"
1635 return 1
1638 (cd $testroot/wt && got status > $testroot/stdout)
1640 echo -n > $testroot/stdout.expected
1641 cmp -s $testroot/stdout.expected $testroot/stdout
1642 ret=$?
1643 if [ $ret -ne 0 ]; then
1644 diff -u $testroot/stdout.expected $testroot/stdout
1645 test_done "$testroot" "$ret"
1646 return 1
1649 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1650 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1651 echo "commit $orig_commit" >> $testroot/stdout.expected
1652 cmp -s $testroot/stdout.expected $testroot/stdout
1653 ret=$?
1654 if [ $ret -ne 0 ]; then
1655 diff -u $testroot/stdout.expected $testroot/stdout
1657 test_done "$testroot" "$ret"
1660 test_histedit_fold_only_empty_logmsg() {
1661 local testroot=`test_init histedit_fold_only_empty_logmsg`
1663 local orig_commit=`git_show_head $testroot/repo`
1665 echo "modified alpha on master" > $testroot/repo/alpha
1666 (cd $testroot/repo && git rm -q beta)
1667 echo "new file on master" > $testroot/repo/epsilon/new
1668 (cd $testroot/repo && git add epsilon/new)
1669 git_commit $testroot/repo -m "committing changes"
1670 local old_commit1=`git_show_head $testroot/repo`
1672 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1673 git_commit $testroot/repo -m "committing to zeta on master"
1674 local old_commit2=`git_show_head $testroot/repo`
1676 echo "modified delta on master" > $testroot/repo/gamma/delta
1677 git_commit $testroot/repo -m "committing to delta on master"
1678 local old_commit3=`git_show_head $testroot/repo`
1680 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1681 ret=$?
1682 if [ $ret -ne 0 ]; then
1683 test_done "$testroot" "$ret"
1684 return 1
1687 cat > $testroot/editor.sh <<EOF
1688 #!/bin/sh
1689 SOPTS='-i ""'
1690 [ "\$OSTYPE" = "linux-gnu" ] && SOPTS="-i"
1691 sed "\$SOPTS" -e 'd' "\$1"
1692 EOF
1693 chmod +x $testroot/editor.sh
1695 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1696 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1698 local new_commit1=`git_show_head $testroot/repo`
1700 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1701 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1702 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1703 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1704 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1705 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1707 echo "G alpha" > $testroot/stdout.expected
1708 echo "D beta" >> $testroot/stdout.expected
1709 echo "A epsilon/new" >> $testroot/stdout.expected
1710 echo "$short_old_commit1 -> fold commit: committing changes" \
1711 >> $testroot/stdout.expected
1712 echo "G epsilon/zeta" >> $testroot/stdout.expected
1713 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1714 echo "fold commit: committing to zeta on master" \
1715 >> $testroot/stdout.expected
1716 echo "G gamma/delta" >> $testroot/stdout.expected
1717 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1718 >> $testroot/stdout.expected
1719 echo "# log message of folded commit $very_short_old_commit1" \
1720 >> $testroot/stdout.expected
1721 echo "Switching work tree to refs/heads/master" \
1722 >> $testroot/stdout.expected
1724 cmp -s $testroot/stdout.expected $testroot/stdout
1725 ret=$?
1726 if [ $ret -ne 0 ]; then
1727 diff -u $testroot/stdout.expected $testroot/stdout
1728 test_done "$testroot" "$ret"
1729 return 1
1732 echo "modified alpha on master" > $testroot/content.expected
1733 cat $testroot/wt/alpha > $testroot/content
1734 cmp -s $testroot/content.expected $testroot/content
1735 ret=$?
1736 if [ $ret -ne 0 ]; then
1737 diff -u $testroot/content.expected $testroot/content
1738 test_done "$testroot" "$ret"
1739 return 1
1742 if [ -e $testroot/wt/beta ]; then
1743 echo "removed file beta still exists on disk" >&2
1744 test_done "$testroot" "1"
1745 return 1
1748 echo "new file on master" > $testroot/content.expected
1749 cat $testroot/wt/epsilon/new > $testroot/content
1750 cmp -s $testroot/content.expected $testroot/content
1751 ret=$?
1752 if [ $ret -ne 0 ]; then
1753 diff -u $testroot/content.expected $testroot/content
1754 test_done "$testroot" "$ret"
1755 return 1
1758 (cd $testroot/wt && got status > $testroot/stdout)
1760 echo -n > $testroot/stdout.expected
1761 cmp -s $testroot/stdout.expected $testroot/stdout
1762 ret=$?
1763 if [ $ret -ne 0 ]; then
1764 diff -u $testroot/stdout.expected $testroot/stdout
1765 test_done "$testroot" "$ret"
1766 return 1
1769 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1770 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1771 echo "commit $orig_commit" >> $testroot/stdout.expected
1772 cmp -s $testroot/stdout.expected $testroot/stdout
1773 ret=$?
1774 if [ $ret -ne 0 ]; then
1775 diff -u $testroot/stdout.expected $testroot/stdout
1777 test_done "$testroot" "$ret"
1780 test_histedit_edit_only() {
1781 local testroot=`test_init histedit_edit_only`
1783 local orig_commit=`git_show_head $testroot/repo`
1785 echo "modified alpha on master" > $testroot/repo/alpha
1786 (cd $testroot/repo && git rm -q beta)
1787 echo "new file on master" > $testroot/repo/epsilon/new
1788 (cd $testroot/repo && git add epsilon/new)
1789 git_commit $testroot/repo -m "committing changes"
1790 local old_commit1=`git_show_head $testroot/repo`
1792 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1793 git_commit $testroot/repo -m "committing to zeta on master"
1794 local old_commit2=`git_show_head $testroot/repo`
1796 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1797 ret=$?
1798 if [ $ret -ne 0 ]; then
1799 test_done "$testroot" "$ret"
1800 return 1
1803 (cd $testroot/wt && got histedit -e > $testroot/stdout)
1805 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1806 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1808 echo "G alpha" > $testroot/stdout.expected
1809 echo "D beta" >> $testroot/stdout.expected
1810 echo "A epsilon/new" >> $testroot/stdout.expected
1811 echo "Stopping histedit for amending commit $old_commit1" \
1812 >> $testroot/stdout.expected
1813 cmp -s $testroot/stdout.expected $testroot/stdout
1814 ret=$?
1815 if [ $ret -ne 0 ]; then
1816 diff -u $testroot/stdout.expected $testroot/stdout
1817 test_done "$testroot" "$ret"
1818 return 1
1821 echo "edited modified alpha on master" > $testroot/wt/alpha
1823 cat > $testroot/editor.sh <<EOF
1824 #!/bin/sh
1825 sed -i 's/.*/committing edited changes 1/' "\$1"
1826 EOF
1827 chmod +x $testroot/editor.sh
1829 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1830 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1832 local new_commit1=$(cd $testroot/wt && got info | \
1833 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1834 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1836 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1837 > $testroot/stdout.expected
1838 echo "committing edited changes 1" >> $testroot/stdout.expected
1839 echo "G epsilon/zeta" >> $testroot/stdout.expected
1840 echo "Stopping histedit for amending commit $old_commit2" \
1841 >> $testroot/stdout.expected
1842 cmp -s $testroot/stdout.expected $testroot/stdout
1843 ret=$?
1844 if [ $ret -ne 0 ]; then
1845 diff -u $testroot/stdout.expected $testroot/stdout
1846 test_done "$testroot" "$ret"
1847 return 1
1850 echo "edited zeta on master" > $testroot/wt/epsilon/zeta
1852 cat > $testroot/editor.sh <<EOF
1853 #!/bin/sh
1854 sed -i 's/.*/committing edited changes 2/' "\$1"
1855 EOF
1856 chmod +x $testroot/editor.sh
1858 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1859 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1861 local new_commit2=`git_show_head $testroot/repo`
1862 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1864 echo -n "$short_old_commit2 -> $short_new_commit2: " \
1865 > $testroot/stdout.expected
1866 echo "committing edited changes 2" >> $testroot/stdout.expected
1867 echo "Switching work tree to refs/heads/master" \
1868 >> $testroot/stdout.expected
1870 cmp -s $testroot/stdout.expected $testroot/stdout
1871 ret=$?
1872 if [ $ret -ne 0 ]; then
1873 diff -u $testroot/stdout.expected $testroot/stdout
1874 test_done "$testroot" "$ret"
1875 return 1
1878 echo "edited modified alpha on master" > $testroot/content.expected
1879 cat $testroot/wt/alpha > $testroot/content
1880 cmp -s $testroot/content.expected $testroot/content
1881 ret=$?
1882 if [ $ret -ne 0 ]; then
1883 diff -u $testroot/content.expected $testroot/content
1884 test_done "$testroot" "$ret"
1885 return 1
1888 if [ -e $testroot/wt/beta ]; then
1889 echo "removed file beta still exists on disk" >&2
1890 test_done "$testroot" "1"
1891 return 1
1894 echo "new file on master" > $testroot/content.expected
1895 cat $testroot/wt/epsilon/new > $testroot/content
1896 cmp -s $testroot/content.expected $testroot/content
1897 ret=$?
1898 if [ $ret -ne 0 ]; then
1899 diff -u $testroot/content.expected $testroot/content
1900 test_done "$testroot" "$ret"
1901 return 1
1904 (cd $testroot/wt && got status > $testroot/stdout)
1906 echo -n > $testroot/stdout.expected
1907 cmp -s $testroot/stdout.expected $testroot/stdout
1908 ret=$?
1909 if [ $ret -ne 0 ]; then
1910 diff -u $testroot/stdout.expected $testroot/stdout
1911 test_done "$testroot" "$ret"
1912 return 1
1915 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1916 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
1917 echo "commit $new_commit1" >> $testroot/stdout.expected
1918 echo "commit $orig_commit" >> $testroot/stdout.expected
1919 cmp -s $testroot/stdout.expected $testroot/stdout
1920 ret=$?
1921 if [ $ret -ne 0 ]; then
1922 diff -u $testroot/stdout.expected $testroot/stdout
1924 test_done "$testroot" "$ret"
1927 test_histedit_prepend_line() {
1928 local testroot=`test_init histedit_prepend_line`
1929 local orig_commit=`git_show_head $testroot/repo`
1931 got checkout $testroot/repo $testroot/wt > /dev/null
1933 ed "$testroot/wt/alpha" <<EOF >/dev/null 2>&1
1935 first line
1938 EOF
1940 cp $testroot/wt/alpha $testroot/content.expected
1942 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
1943 alpha > /dev/null)
1944 ret=$?
1945 if [ "$?" != 0 ]; then
1946 echo "got commit failed unexpectedly" >&2
1947 test_done "$testroot" "$ret"
1948 return 1
1951 local top_commit=`git_show_head $testroot/repo`
1952 echo "pick $top_commit" > "$testroot/histedit-script"
1954 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
1955 ret=$?
1956 if [ "$?" != 0 ]; then
1957 echo "got update failed unexpectedly" >&2
1958 test_done "$testroot" "$ret"
1959 return 1
1962 (cd $testroot/wt && got histedit -F "$testroot/histedit-script" \
1963 > /dev/null)
1964 ret=$?
1965 if [ "$?" != 0 ]; then
1966 echo "got histedit failed unexpectedly" >&2
1967 test_done "$testroot" "$ret"
1968 return 1
1971 cp $testroot/wt/alpha $testroot/content
1972 cmp -s $testroot/content.expected $testroot/content
1973 ret=$?
1974 if [ $ret -ne 0 ]; then
1975 diff -u $testroot/content.expected $testroot/content
1976 test_done "$testroot" "$ret"
1977 return 1
1980 test_done "$testroot" $ret
1983 test_histedit_mesg_invalid() {
1984 local testroot=`test_init mesg_invalid`
1986 local orig_commit=`git_show_head $testroot/repo`
1988 echo "modified alpha on master" > $testroot/repo/alpha
1989 (cd $testroot/repo && git rm -q beta)
1990 echo "new file on master" > $testroot/repo/epsilon/new
1991 (cd $testroot/repo && git add epsilon/new)
1992 git_commit $testroot/repo -m 'committing changes'
1993 local old_commit1=`git_show_head $testroot/repo`
1995 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1996 git_commit $testroot/repo -m 'committing to zeto on master'
1997 local old_commit2=`git_show_head $testroot/repo`
1999 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2000 ret=$?
2001 if [ $ret -ne 0 ]; then
2002 test_done "$testroot" $ret
2003 return 1
2006 # try with a leading mesg
2008 echo "mesg something something" > $testroot/histedit-script
2009 echo "pick $old_commit1" >> $testroot/histedit-script
2010 echo "pick $old_commit2" >> $testroot/histedit-script
2012 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2013 > $testroot/stdout 2> $testroot/stderr)
2014 ret=$?
2015 if [ $ret -eq 0 ]; then
2016 echo "histedit succeeded unexpectedly" >&2
2017 test_done "$testroot" 1
2018 return 1
2021 echo "got: bad histedit command" > $testroot/stderr.expected
2022 cmp -s $testroot/stderr.expected $testroot/stderr
2023 ret=$?
2024 if [ $ret -ne 0 ]; then
2025 diff -u $testroot/stderr.expected $testroot/stderr
2026 test_done "$testroot" $ret
2027 return 1
2030 # try again with mesg -> mesg
2032 echo "pick $old_commit1" > $testroot/histedit-script
2033 echo "mesg something something" >> $testroot/histedit-script
2034 echo "mesg something something else" >> $testroot/histedit-script
2035 echo "pick $old_commit2" >> $testroot/histedit-script
2037 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2038 > $testroot/stdout 2> $testroot/stderr)
2039 ret=$?
2040 if [ $ret -eq 0 ]; then
2041 echo "histedit succeeded unexpectedly" >&2
2042 test_done "$testroot" 1
2043 return 1
2046 echo "got: bad histedit command" > $testroot/stderr.expected
2047 cmp -s $testroot/stderr.expected $testroot/stderr
2048 ret=$?
2049 if [ $ret -ne 0 ]; then
2050 diff -u $testroot/stderr.expected $testroot/stderr
2051 test_done "$testroot" $ret
2052 return 1
2055 # try again with drop -> mesg
2057 echo "drop $old_commit1" > $testroot/histedit-script
2058 echo "mesg something something" >> $testroot/histedit-script
2059 echo "pick $old_commit2" >> $testroot/histedit-script
2061 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2062 > $testroot/stdout 2> $testroot/stderr)
2063 ret=$?
2064 if [ $ret -eq 0 ]; then
2065 echo "histedit succeeded unexpectedly" >&2
2066 test_done "$testroot" 1
2067 return 1
2070 echo "got: bad histedit command" > $testroot/stderr.expected
2071 cmp -s $testroot/stderr.expected $testroot/stderr
2072 ret=$?
2073 if [ $ret -ne 0 ]; then
2074 diff -u $testroot/stderr.expected $testroot/stderr
2075 test_done "$testroot" $ret
2076 return 1
2079 # try again with fold -> mesg
2081 echo "fold $old_commit1" > $testroot/histedit-script
2082 echo "mesg something something" >> $testroot/histedit-script
2083 echo "pick $old_commit2" >> $testroot/histedit-script
2085 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2086 > $testroot/stdout 2> $testroot/stderr)
2087 ret=$?
2088 if [ $ret -eq 0 ]; then
2089 echo "histedit succeeded unexpectedly" >&2
2090 test_done "$testroot" 1
2091 return 1
2094 echo "got: bad histedit command" > $testroot/stderr.expected
2095 cmp -s $testroot/stderr.expected $testroot/stderr
2096 ret=$?
2097 if [ $ret -ne 0 ]; then
2098 diff -u $testroot/stderr.expected $testroot/stderr
2100 test_done "$testroot" $ret
2103 test_histedit_resets_committer() {
2104 local testroot=`test_init histedit_resets_committer`
2105 local orig_commit=`git_show_head $testroot/repo`
2106 local committer="Flan Luck <flan_luck@openbsd.org>"
2108 got checkout $testroot/repo $testroot/wt > /dev/null
2110 echo "modified alpha" > $testroot/wt/alpha
2112 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2113 alpha > /dev/null)
2114 ret=$?
2115 if [ "$?" != 0 ]; then
2116 echo "got commit failed unexpectedly" >&2
2117 test_done "$testroot" "$ret"
2118 return 1
2121 local top_commit=`git_show_head $testroot/repo`
2122 echo "pick $top_commit" > "$testroot/histedit-script"
2124 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2125 ret=$?
2126 if [ "$?" != 0 ]; then
2127 echo "got update failed unexpectedly" >&2
2128 test_done "$testroot" "$ret"
2129 return 1
2132 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
2133 got histedit -F "$testroot/histedit-script" > /dev/null)
2134 ret=$?
2135 if [ "$?" != 0 ]; then
2136 echo "got histedit failed unexpectedly" >&2
2137 test_done "$testroot" "$ret"
2138 return 1
2140 local edited_commit=`git_show_head $testroot/repo`
2142 # Original commit only had one author
2143 (cd $testroot/repo && got log -l1 -c $top_commit | \
2144 egrep '^(from|via):' > $testroot/stdout)
2145 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2146 cmp -s $testroot/stdout.expected $testroot/stdout
2147 ret=$?
2148 if [ $ret -ne 0 ]; then
2149 diff -u $testroot/stdout.expected $testroot/stdout
2150 test_done "$testroot" "$ret"
2151 return 1
2154 # Edited commit should have new committer name added
2155 (cd $testroot/repo && got log -l1 -c $edited_commit | \
2156 egrep '^(from|via):' > $testroot/stdout)
2157 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2158 echo "via: $committer" >> $testroot/stdout.expected
2160 cmp -s $testroot/stdout.expected $testroot/stdout
2161 ret=$?
2162 if [ $ret -ne 0 ]; then
2163 diff -u $testroot/stdout.expected $testroot/stdout
2165 test_done "$testroot" "$ret"
2168 test_parseargs "$@"
2169 run_test test_histedit_no_op
2170 run_test test_histedit_swap
2171 run_test test_histedit_drop
2172 run_test test_histedit_fold
2173 run_test test_histedit_edit
2174 run_test test_histedit_fold_last_commit
2175 run_test test_histedit_missing_commit
2176 run_test test_histedit_abort
2177 run_test test_histedit_path_prefix_drop
2178 run_test test_histedit_path_prefix_edit
2179 run_test test_histedit_outside_refs_heads
2180 run_test test_histedit_fold_last_commit_swap
2181 run_test test_histedit_split_commit
2182 run_test test_histedit_duplicate_commit_in_script
2183 run_test test_histedit_fold_add_delete
2184 run_test test_histedit_fold_only
2185 run_test test_histedit_fold_only_empty_logmsg
2186 run_test test_histedit_edit_only
2187 run_test test_histedit_prepend_line
2188 run_test test_histedit_mesg_invalid
2189 run_test test_histedit_resets_committer