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 ed -s $testroot/diff.expected <<-EOF
135 ,s/$old_commit2/$new_commit2/
137 EOF
138 cmp -s $testroot/diff.expected $testroot/diff
139 ret=$?
140 if [ $ret -ne 0 ]; then
141 diff -u $testroot/diff.expected $testroot/diff
142 test_done "$testroot" "$ret"
143 return 1
144 fi
146 (cd $testroot/wt && got update > $testroot/stdout)
148 echo 'Already up-to-date' > $testroot/stdout.expected
149 cmp -s $testroot/stdout.expected $testroot/stdout
150 ret=$?
151 if [ $ret -ne 0 ]; then
152 diff -u $testroot/stdout.expected $testroot/stdout
153 test_done "$testroot" "$ret"
154 return 1
155 fi
157 # We should have a backup of old commits
158 (cd $testroot/repo && got histedit -l > $testroot/stdout)
159 d_orig1=`date -u -r $old_author_time1 +"%G-%m-%d"`
160 d_orig2=`date -u -r $old_author_time2 +"%a %b %e %X %Y UTC"`
161 d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
162 d_orig=`date -u -r $orig_author_time +"%G-%m-%d"`
163 cat > $testroot/stdout.expected <<EOF
164 -----------------------------------------------
165 commit $old_commit2 (formerly master)
166 from: $GOT_AUTHOR
167 date: $d_orig2
169 committing to zeta on master
171 has become commit $new_commit2 (master)
172 $d_new2 $GOT_AUTHOR_11 committing to zeta on master
173 EOF
175 local is_forked=true d_fork fork_commit fork_commit_msg
177 if [ "$old_commit1" = "$new_commit1" ]; then
178 if [ "$old_commit2" = "$new_commit2" ]; then
179 is_forked=false
180 else
181 d_fork=$d_orig1
182 fork_commit=$new_commit1
183 fork_commit_msg="committing changes"
184 fi
185 else
186 d_fork=$d_orig
187 fork_commit=$orig_commit
188 fork_commit_msg="adding the test tree"
189 fi
191 $is_forked && cat >> $testroot/stdout.expected <<EOF
192 history forked at $fork_commit
193 $d_fork $GOT_AUTHOR_11 $fork_commit_msg
194 EOF
196 cmp -s $testroot/stdout.expected $testroot/stdout
197 ret=$?
198 if [ $ret -ne 0 ]; then
199 diff -u $testroot/stdout.expected $testroot/stdout
200 test_done "$testroot" "$ret"
201 return 1
202 fi
204 (cd $testroot/repo && got histedit -X master \
205 > $testroot/stdout 2> $testroot/stderr)
206 echo -n "Deleted refs/got/backup/histedit/master/$new_commit2: " \
207 > $testroot/stdout.expected
208 echo "$old_commit2" >> $testroot/stdout.expected
209 echo -n > $testroot/stderr.expected
210 cmp -s $testroot/stdout.expected $testroot/stdout
211 ret=$?
212 if [ $ret -ne 0 ]; then
213 diff -u $testroot/stdout.expected $testroot/stdout
214 test_done "$testroot" "$ret"
215 return 1
216 fi
217 cmp -s $testroot/stderr.expected $testroot/stderr
218 ret=$?
219 if [ $ret -ne 0 ]; then
220 diff -u $testroot/stderr.expected $testroot/stderr
221 test_done "$testroot" "$ret"
222 return 1
223 fi
225 (cd $testroot/repo && got histedit -l > $testroot/stdout)
226 echo -n > $testroot/stdout.expected
227 cmp -s $testroot/stdout.expected $testroot/stdout
228 ret=$?
229 if [ $ret -ne 0 ]; then
230 diff -u $testroot/stdout.expected $testroot/stdout
231 fi
232 test_done "$testroot" "$ret"
235 test_histedit_swap() {
236 local testroot=`test_init histedit_swap`
238 local orig_commit=`git_show_head $testroot/repo`
240 echo "modified alpha on master" > $testroot/repo/alpha
241 (cd $testroot/repo && git rm -q beta)
242 echo "new file on master" > $testroot/repo/epsilon/new
243 (cd $testroot/repo && git add epsilon/new)
244 git_commit $testroot/repo -m "committing changes"
245 local old_commit1=`git_show_head $testroot/repo`
247 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
248 git_commit $testroot/repo -m "committing to zeta on master"
249 local old_commit2=`git_show_head $testroot/repo`
251 got diff -r $testroot/repo $orig_commit $old_commit2 \
252 > $testroot/diff.expected
254 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
255 ret=$?
256 if [ $ret -ne 0 ]; then
257 test_done "$testroot" "$ret"
258 return 1
259 fi
261 echo "pick $old_commit2" > $testroot/histedit-script
262 echo "pick $old_commit1" >> $testroot/histedit-script
264 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
265 > $testroot/stdout)
267 local new_commit2=`git_show_parent_commit $testroot/repo`
268 local new_commit1=`git_show_head $testroot/repo`
270 local short_old_commit1=`trim_obj_id 28 $old_commit1`
271 local short_old_commit2=`trim_obj_id 28 $old_commit2`
272 local short_new_commit1=`trim_obj_id 28 $new_commit1`
273 local short_new_commit2=`trim_obj_id 28 $new_commit2`
275 echo "G epsilon/zeta" > $testroot/stdout.expected
276 echo -n "$short_old_commit2 -> $short_new_commit2: " \
277 >> $testroot/stdout.expected
278 echo "committing to zeta on master" >> $testroot/stdout.expected
279 echo "G alpha" >> $testroot/stdout.expected
280 echo "D beta" >> $testroot/stdout.expected
281 echo "A epsilon/new" >> $testroot/stdout.expected
282 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
283 >> $testroot/stdout.expected
284 echo "Switching work tree to refs/heads/master" \
285 >> $testroot/stdout.expected
287 cmp -s $testroot/stdout.expected $testroot/stdout
288 ret=$?
289 if [ $ret -ne 0 ]; then
290 diff -u $testroot/stdout.expected $testroot/stdout
291 test_done "$testroot" "$ret"
292 return 1
293 fi
295 echo "modified alpha on master" > $testroot/content.expected
296 cat $testroot/wt/alpha > $testroot/content
297 cmp -s $testroot/content.expected $testroot/content
298 ret=$?
299 if [ $ret -ne 0 ]; then
300 diff -u $testroot/content.expected $testroot/content
301 test_done "$testroot" "$ret"
302 return 1
303 fi
305 if [ -e $testroot/wt/beta ]; then
306 echo "removed file beta still exists on disk" >&2
307 test_done "$testroot" "1"
308 return 1
309 fi
311 echo "new file on master" > $testroot/content.expected
312 cat $testroot/wt/epsilon/new > $testroot/content
313 cmp -s $testroot/content.expected $testroot/content
314 ret=$?
315 if [ $ret -ne 0 ]; then
316 diff -u $testroot/content.expected $testroot/content
317 test_done "$testroot" "$ret"
318 return 1
319 fi
321 (cd $testroot/wt && got status > $testroot/stdout)
323 echo -n > $testroot/stdout.expected
324 cmp -s $testroot/stdout.expected $testroot/stdout
325 ret=$?
326 if [ $ret -ne 0 ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 test_done "$testroot" "$ret"
329 return 1
330 fi
332 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
333 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
334 echo "commit $new_commit2" >> $testroot/stdout.expected
335 echo "commit $orig_commit" >> $testroot/stdout.expected
336 cmp -s $testroot/stdout.expected $testroot/stdout
337 ret=$?
338 if [ $ret -ne 0 ]; then
339 diff -u $testroot/stdout.expected $testroot/stdout
340 test_done "$testroot" "$ret"
341 return 1
342 fi
344 got diff -r $testroot/repo $orig_commit $new_commit1 \
345 > $testroot/diff
346 ed -s $testroot/diff.expected <<-EOF
347 ,s/$old_commit2/$new_commit1/
349 EOF
350 cmp -s $testroot/diff.expected $testroot/diff
351 ret=$?
352 if [ $ret -ne 0 ]; then
353 diff -u $testroot/diff.expected $testroot/diff
354 fi
355 test_done "$testroot" "$ret"
358 test_histedit_drop() {
359 local testroot=`test_init histedit_drop`
360 local orig_commit=`git_show_head $testroot/repo`
362 echo "modified alpha on master" > $testroot/repo/alpha
363 (cd $testroot/repo && git rm -q beta)
364 echo "new file on master" > $testroot/repo/epsilon/new
365 (cd $testroot/repo && git add epsilon/new)
366 git_commit $testroot/repo -m "committing changes"
367 local old_commit1=`git_show_head $testroot/repo`
369 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
370 git_commit $testroot/repo -m "committing to zeta on master"
371 local old_commit2=`git_show_head $testroot/repo`
373 got diff -r $testroot/repo $old_commit1 $old_commit2 \
374 > $testroot/diff.expected
376 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
377 ret=$?
378 if [ $ret -ne 0 ]; then
379 test_done "$testroot" "$ret"
380 return 1
381 fi
383 echo "drop $old_commit1" > $testroot/histedit-script
384 echo "pick $old_commit2" >> $testroot/histedit-script
386 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
387 > $testroot/stdout)
389 local new_commit2=`git_show_head $testroot/repo`
391 local short_old_commit1=`trim_obj_id 28 $old_commit1`
392 local short_old_commit2=`trim_obj_id 28 $old_commit2`
393 local short_new_commit2=`trim_obj_id 28 $new_commit2`
395 echo "$short_old_commit1 -> drop commit: committing changes" \
396 > $testroot/stdout.expected
397 echo "G epsilon/zeta" >> $testroot/stdout.expected
398 echo -n "$short_old_commit2 -> $short_new_commit2: " \
399 >> $testroot/stdout.expected
400 echo "committing to zeta on master" >> $testroot/stdout.expected
401 echo "Switching work tree to refs/heads/master" \
402 >> $testroot/stdout.expected
404 cmp -s $testroot/stdout.expected $testroot/stdout
405 ret=$?
406 if [ $ret -ne 0 ]; then
407 diff -u $testroot/stdout.expected $testroot/stdout
408 test_done "$testroot" "$ret"
409 return 1
410 fi
412 for f in alpha beta; do
413 echo "$f" > $testroot/content.expected
414 cat $testroot/wt/$f > $testroot/content
415 cmp -s $testroot/content.expected $testroot/content
416 ret=$?
417 if [ $ret -ne 0 ]; then
418 diff -u $testroot/content.expected $testroot/content
419 test_done "$testroot" "$ret"
420 return 1
421 fi
422 done
424 if [ -e $testroot/wt/new ]; then
425 echo "file new exists on disk but should not" >&2
426 test_done "$testroot" "1"
427 return 1
428 fi
430 (cd $testroot/wt && got status > $testroot/stdout)
432 echo -n > $testroot/stdout.expected
433 cmp -s $testroot/stdout.expected $testroot/stdout
434 ret=$?
435 if [ $ret -ne 0 ]; then
436 diff -u $testroot/stdout.expected $testroot/stdout
437 test_done "$testroot" "$ret"
438 return 1
439 fi
441 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
442 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
443 echo "commit $orig_commit" >> $testroot/stdout.expected
444 cmp -s $testroot/stdout.expected $testroot/stdout
445 ret=$?
446 if [ $ret -ne 0 ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$ret"
449 return 1
450 fi
452 got diff -r $testroot/repo $orig_commit $new_commit2 \
453 > $testroot/diff
454 ed -s $testroot/diff.expected <<-EOF
455 ,s/$old_commit1/$orig_commit/
456 ,s/$old_commit2/$new_commit2/
458 EOF
459 cmp -s $testroot/diff.expected $testroot/diff
460 ret=$?
461 if [ $ret -ne 0 ]; then
462 diff -u $testroot/diff.expected $testroot/diff
463 fi
464 test_done "$testroot" "$ret"
467 test_histedit_fold() {
468 local testroot=`test_init histedit_fold`
470 local orig_commit=`git_show_head $testroot/repo`
472 echo "modified alpha on master" > $testroot/repo/alpha
473 (cd $testroot/repo && git rm -q beta)
474 echo "new file on master" > $testroot/repo/epsilon/new
475 (cd $testroot/repo && git add epsilon/new)
476 git_commit $testroot/repo -m "committing changes"
477 local old_commit1=`git_show_head $testroot/repo`
479 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
480 git_commit $testroot/repo -m "committing to zeta on master"
481 local old_commit2=`git_show_head $testroot/repo`
483 echo "modified delta on master" > $testroot/repo/gamma/delta
484 git_commit $testroot/repo -m "committing to delta on master"
485 local old_commit3=`git_show_head $testroot/repo`
487 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
488 ret=$?
489 if [ $ret -ne 0 ]; then
490 test_done "$testroot" "$ret"
491 return 1
492 fi
494 echo "fold $old_commit1" > $testroot/histedit-script
495 echo "drop $old_commit2" >> $testroot/histedit-script
496 echo "pick $old_commit3" >> $testroot/histedit-script
497 echo "mesg committing folded changes" >> $testroot/histedit-script
499 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
500 > $testroot/stdout)
502 local new_commit1=`git_show_parent_commit $testroot/repo`
503 local new_commit2=`git_show_head $testroot/repo`
505 local short_old_commit1=`trim_obj_id 28 $old_commit1`
506 local short_old_commit2=`trim_obj_id 28 $old_commit2`
507 local short_old_commit3=`trim_obj_id 28 $old_commit3`
508 local short_new_commit1=`trim_obj_id 28 $new_commit1`
509 local short_new_commit2=`trim_obj_id 28 $new_commit2`
511 echo "G alpha" > $testroot/stdout.expected
512 echo "D beta" >> $testroot/stdout.expected
513 echo "A epsilon/new" >> $testroot/stdout.expected
514 echo "$short_old_commit1 -> fold commit: committing changes" \
515 >> $testroot/stdout.expected
516 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
517 echo "drop commit: committing to zeta on master" \
518 >> $testroot/stdout.expected
519 echo "G gamma/delta" >> $testroot/stdout.expected
520 echo -n "$short_old_commit3 -> $short_new_commit2: " \
521 >> $testroot/stdout.expected
522 echo "committing folded changes" >> $testroot/stdout.expected
523 echo "Switching work tree to refs/heads/master" \
524 >> $testroot/stdout.expected
526 cmp -s $testroot/stdout.expected $testroot/stdout
527 ret=$?
528 if [ $ret -ne 0 ]; then
529 diff -u $testroot/stdout.expected $testroot/stdout
530 test_done "$testroot" "$ret"
531 return 1
532 fi
534 echo "modified alpha on master" > $testroot/content.expected
535 cat $testroot/wt/alpha > $testroot/content
536 cmp -s $testroot/content.expected $testroot/content
537 ret=$?
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/content.expected $testroot/content
540 test_done "$testroot" "$ret"
541 return 1
542 fi
544 if [ -e $testroot/wt/beta ]; then
545 echo "removed file beta still exists on disk" >&2
546 test_done "$testroot" "1"
547 return 1
548 fi
550 echo "new file on master" > $testroot/content.expected
551 cat $testroot/wt/epsilon/new > $testroot/content
552 cmp -s $testroot/content.expected $testroot/content
553 ret=$?
554 if [ $ret -ne 0 ]; then
555 diff -u $testroot/content.expected $testroot/content
556 test_done "$testroot" "$ret"
557 return 1
558 fi
560 (cd $testroot/wt && got status > $testroot/stdout)
562 echo -n > $testroot/stdout.expected
563 cmp -s $testroot/stdout.expected $testroot/stdout
564 ret=$?
565 if [ $ret -ne 0 ]; then
566 diff -u $testroot/stdout.expected $testroot/stdout
567 test_done "$testroot" "$ret"
568 return 1
569 fi
571 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
572 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
573 echo "commit $orig_commit" >> $testroot/stdout.expected
574 cmp -s $testroot/stdout.expected $testroot/stdout
575 ret=$?
576 if [ $ret -ne 0 ]; then
577 diff -u $testroot/stdout.expected $testroot/stdout
578 fi
579 test_done "$testroot" "$ret"
582 test_histedit_edit() {
583 local testroot=`test_init histedit_edit`
585 local orig_commit=`git_show_head $testroot/repo`
587 echo "modified alpha on master" > $testroot/repo/alpha
588 (cd $testroot/repo && git rm -q beta)
589 echo "new file on master" > $testroot/repo/epsilon/new
590 (cd $testroot/repo && git add epsilon/new)
591 git_commit $testroot/repo -m "committing changes"
592 local old_commit1=`git_show_head $testroot/repo`
594 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
595 git_commit $testroot/repo -m "committing to zeta on master"
596 local old_commit2=`git_show_head $testroot/repo`
598 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
599 ret=$?
600 if [ $ret -ne 0 ]; then
601 test_done "$testroot" "$ret"
602 return 1
603 fi
605 echo "edit $old_commit1" > $testroot/histedit-script
606 echo "mesg committing changes" >> $testroot/histedit-script
607 echo "pick $old_commit2" >> $testroot/histedit-script
609 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
610 > $testroot/stdout)
612 local short_old_commit1=`trim_obj_id 28 $old_commit1`
613 local short_old_commit2=`trim_obj_id 28 $old_commit2`
615 echo "G alpha" > $testroot/stdout.expected
616 echo "D beta" >> $testroot/stdout.expected
617 echo "A epsilon/new" >> $testroot/stdout.expected
618 echo "Stopping histedit for amending commit $old_commit1" \
619 >> $testroot/stdout.expected
620 cmp -s $testroot/stdout.expected $testroot/stdout
621 ret=$?
622 if [ $ret -ne 0 ]; then
623 diff -u $testroot/stdout.expected $testroot/stdout
624 test_done "$testroot" "$ret"
625 return 1
626 fi
628 echo "edited modified alpha on master" > $testroot/wt/alpha
630 # test interaction of 'got stage' and histedit -c
631 (cd $testroot/wt && got stage alpha > /dev/null)
632 (cd $testroot/wt && got histedit -c > $testroot/stdout \
633 2> $testroot/stderr)
634 ret=$?
635 if [ $ret -eq 0 ]; then
636 echo "histedit succeeded unexpectedly" >&2
637 test_done "$testroot" "1"
638 return 1
639 fi
640 echo -n "got: work tree contains files with staged changes; " \
641 > $testroot/stderr.expected
642 echo "these changes must be committed or unstaged first" \
643 >> $testroot/stderr.expected
644 cmp -s $testroot/stderr.expected $testroot/stderr
645 ret=$?
646 if [ $ret -ne 0 ]; then
647 diff -u $testroot/stderr.expected $testroot/stderr
648 test_done "$testroot" "$ret"
649 return 1
650 fi
652 (cd $testroot/wt && got unstage alpha > /dev/null)
653 (cd $testroot/wt && got histedit -c > $testroot/stdout)
655 local new_commit1=`git_show_parent_commit $testroot/repo`
656 local new_commit2=`git_show_head $testroot/repo`
658 local short_new_commit1=`trim_obj_id 28 $new_commit1`
659 local short_new_commit2=`trim_obj_id 28 $new_commit2`
661 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
662 > $testroot/stdout.expected
663 echo "G epsilon/zeta" >> $testroot/stdout.expected
664 echo -n "$short_old_commit2 -> $short_new_commit2: " \
665 >> $testroot/stdout.expected
666 echo "committing to zeta on master" >> $testroot/stdout.expected
667 echo "Switching work tree to refs/heads/master" \
668 >> $testroot/stdout.expected
670 cmp -s $testroot/stdout.expected $testroot/stdout
671 ret=$?
672 if [ $ret -ne 0 ]; then
673 diff -u $testroot/stdout.expected $testroot/stdout
674 test_done "$testroot" "$ret"
675 return 1
676 fi
678 echo "edited modified alpha on master" > $testroot/content.expected
679 cat $testroot/wt/alpha > $testroot/content
680 cmp -s $testroot/content.expected $testroot/content
681 ret=$?
682 if [ $ret -ne 0 ]; then
683 diff -u $testroot/content.expected $testroot/content
684 test_done "$testroot" "$ret"
685 return 1
686 fi
688 if [ -e $testroot/wt/beta ]; then
689 echo "removed file beta still exists on disk" >&2
690 test_done "$testroot" "1"
691 return 1
692 fi
694 echo "new file on master" > $testroot/content.expected
695 cat $testroot/wt/epsilon/new > $testroot/content
696 cmp -s $testroot/content.expected $testroot/content
697 ret=$?
698 if [ $ret -ne 0 ]; then
699 diff -u $testroot/content.expected $testroot/content
700 test_done "$testroot" "$ret"
701 return 1
702 fi
704 (cd $testroot/wt && got status > $testroot/stdout)
706 echo -n > $testroot/stdout.expected
707 cmp -s $testroot/stdout.expected $testroot/stdout
708 ret=$?
709 if [ $ret -ne 0 ]; then
710 diff -u $testroot/stdout.expected $testroot/stdout
711 test_done "$testroot" "$ret"
712 return 1
713 fi
715 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
716 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
717 echo "commit $new_commit1" >> $testroot/stdout.expected
718 echo "commit $orig_commit" >> $testroot/stdout.expected
719 cmp -s $testroot/stdout.expected $testroot/stdout
720 ret=$?
721 if [ $ret -ne 0 ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
723 fi
724 test_done "$testroot" "$ret"
727 test_histedit_fold_last_commit() {
728 local testroot=`test_init histedit_fold_last_commit`
730 local orig_commit=`git_show_head $testroot/repo`
732 echo "modified alpha on master" > $testroot/repo/alpha
733 (cd $testroot/repo && git rm -q beta)
734 echo "new file on master" > $testroot/repo/epsilon/new
735 (cd $testroot/repo && git add epsilon/new)
736 git_commit $testroot/repo -m "committing changes"
737 local old_commit1=`git_show_head $testroot/repo`
739 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
740 git_commit $testroot/repo -m "committing to zeta on master"
741 local old_commit2=`git_show_head $testroot/repo`
743 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
744 ret=$?
745 if [ $ret -ne 0 ]; then
746 test_done "$testroot" "$ret"
747 return 1
748 fi
750 echo "pick $old_commit1" > $testroot/histedit-script
751 echo "fold $old_commit2" >> $testroot/histedit-script
753 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
754 > $testroot/stdout 2> $testroot/stderr)
756 ret=$?
757 if [ $ret -eq 0 ]; then
758 echo "histedit succeeded unexpectedly" >&2
759 test_done "$testroot" "1"
760 return 1
761 fi
763 echo "got: last commit in histedit script cannot be folded" \
764 > $testroot/stderr.expected
766 cmp -s $testroot/stderr.expected $testroot/stderr
767 ret=$?
768 if [ $ret -ne 0 ]; then
769 diff -u $testroot/stderr.expected $testroot/stderr
770 fi
771 test_done "$testroot" "$ret"
774 test_histedit_missing_commit() {
775 local testroot=`test_init histedit_missing_commit`
777 local orig_commit=`git_show_head $testroot/repo`
779 echo "modified alpha on master" > $testroot/repo/alpha
780 (cd $testroot/repo && git rm -q beta)
781 echo "new file on master" > $testroot/repo/epsilon/new
782 (cd $testroot/repo && git add epsilon/new)
783 git_commit $testroot/repo -m "committing changes"
784 local old_commit1=`git_show_head $testroot/repo`
786 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
787 git_commit $testroot/repo -m "committing to zeta on master"
788 local old_commit2=`git_show_head $testroot/repo`
790 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
791 ret=$?
792 if [ $ret -ne 0 ]; then
793 test_done "$testroot" "$ret"
794 return 1
795 fi
797 echo "pick $old_commit1" > $testroot/histedit-script
798 echo "mesg committing changes" >> $testroot/histedit-script
800 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
801 > $testroot/stdout 2> $testroot/stderr)
803 ret=$?
804 if [ $ret -eq 0 ]; then
805 echo "histedit succeeded unexpectedly" >&2
806 test_done "$testroot" "1"
807 return 1
808 fi
810 echo "got: commit $old_commit2 missing from histedit script" \
811 > $testroot/stderr.expected
813 cmp -s $testroot/stderr.expected $testroot/stderr
814 ret=$?
815 if [ $ret -ne 0 ]; then
816 diff -u $testroot/stderr.expected $testroot/stderr
817 fi
818 test_done "$testroot" "$ret"
821 test_histedit_abort() {
822 local testroot=`test_init histedit_abort`
824 local orig_commit=`git_show_head $testroot/repo`
826 echo "modified alpha on master" > $testroot/repo/alpha
827 (cd $testroot/repo && git rm -q beta)
828 echo "new file on master" > $testroot/repo/epsilon/new
829 (cd $testroot/repo && git add epsilon/new)
830 git_commit $testroot/repo -m "committing changes"
831 local old_commit1=`git_show_head $testroot/repo`
833 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
834 git_commit $testroot/repo -m "committing to zeta on master"
835 local old_commit2=`git_show_head $testroot/repo`
837 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
838 ret=$?
839 if [ $ret -ne 0 ]; then
840 test_done "$testroot" "$ret"
841 return 1
842 fi
844 # unrelated unversioned file in work tree
845 touch $testroot/wt/unversioned-file
847 echo "edit $old_commit1" > $testroot/histedit-script
848 echo "mesg committing changes" >> $testroot/histedit-script
849 echo "pick $old_commit2" >> $testroot/histedit-script
851 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
852 > $testroot/stdout)
854 local short_old_commit1=`trim_obj_id 28 $old_commit1`
855 local short_old_commit2=`trim_obj_id 28 $old_commit2`
857 echo "G alpha" > $testroot/stdout.expected
858 echo "D beta" >> $testroot/stdout.expected
859 echo "A epsilon/new" >> $testroot/stdout.expected
860 echo "Stopping histedit for amending commit $old_commit1" \
861 >> $testroot/stdout.expected
862 cmp -s $testroot/stdout.expected $testroot/stdout
863 ret=$?
864 if [ $ret -ne 0 ]; then
865 diff -u $testroot/stdout.expected $testroot/stdout
866 test_done "$testroot" "$ret"
867 return 1
868 fi
870 echo "edited modified alpha on master" > $testroot/wt/alpha
872 (cd $testroot/wt && got histedit -a > $testroot/stdout)
874 local new_commit1=`git_show_parent_commit $testroot/repo`
875 local new_commit2=`git_show_head $testroot/repo`
877 echo "Switching work tree to refs/heads/master" \
878 > $testroot/stdout.expected
879 echo "R alpha" >> $testroot/stdout.expected
880 echo "R beta" >> $testroot/stdout.expected
881 echo "R epsilon/new" >> $testroot/stdout.expected
882 echo "Histedit of refs/heads/master aborted" \
883 >> $testroot/stdout.expected
885 cmp -s $testroot/stdout.expected $testroot/stdout
886 ret=$?
887 if [ $ret -ne 0 ]; then
888 diff -u $testroot/stdout.expected $testroot/stdout
889 test_done "$testroot" "$ret"
890 return 1
891 fi
893 for f in alpha beta; do
894 echo "$f" > $testroot/content.expected
895 cat $testroot/wt/$f > $testroot/content
896 cmp -s $testroot/content.expected $testroot/content
897 ret=$?
898 if [ $ret -ne 0 ]; then
899 diff -u $testroot/content.expected $testroot/content
900 test_done "$testroot" "$ret"
901 return 1
902 fi
903 done
905 echo "new file on master" > $testroot/content.expected
906 cat $testroot/wt/epsilon/new > $testroot/content
907 cmp -s $testroot/content.expected $testroot/content
908 ret=$?
909 if [ $ret -ne 0 ]; then
910 diff -u $testroot/content.expected $testroot/content
911 test_done "$testroot" "$ret"
912 return 1
913 fi
915 (cd $testroot/wt && got status > $testroot/stdout)
917 echo "? epsilon/new" > $testroot/stdout.expected
918 echo "? unversioned-file" >> $testroot/stdout.expected
919 cmp -s $testroot/stdout.expected $testroot/stdout
920 ret=$?
921 if [ $ret -ne 0 ]; then
922 diff -u $testroot/stdout.expected $testroot/stdout
923 test_done "$testroot" "$ret"
924 return 1
925 fi
927 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
928 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
929 echo "commit $new_commit1" >> $testroot/stdout.expected
930 echo "commit $orig_commit" >> $testroot/stdout.expected
931 cmp -s $testroot/stdout.expected $testroot/stdout
932 ret=$?
933 if [ $ret -ne 0 ]; then
934 diff -u $testroot/stdout.expected $testroot/stdout
935 fi
936 test_done "$testroot" "$ret"
939 test_histedit_path_prefix_drop() {
940 local testroot=`test_init histedit_path_prefix_drop`
941 local orig_commit=`git_show_head $testroot/repo`
943 echo "modified zeta" > $testroot/repo/epsilon/zeta
944 git_commit $testroot/repo -m "changing zeta"
945 local old_commit1=`git_show_head $testroot/repo`
947 got checkout -c $orig_commit -p gamma $testroot/repo \
948 $testroot/wt > /dev/null
949 ret=$?
950 if [ $ret -ne 0 ]; then
951 test_done "$testroot" "$ret"
952 return 1
953 fi
955 echo "drop $old_commit1" > $testroot/histedit-script
957 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
958 > $testroot/stdout 2> $testroot/stderr)
960 ret=$?
961 if [ $ret -eq 0 ]; then
962 echo "histedit succeeded unexpectedly" >&2
963 test_done "$testroot" "1"
964 return 1
965 fi
967 echo -n "got: cannot edit branch history which contains changes " \
968 > $testroot/stderr.expected
969 echo "outside of this work tree's path prefix" \
970 >> $testroot/stderr.expected
972 cmp -s $testroot/stderr.expected $testroot/stderr
973 ret=$?
974 if [ $ret -ne 0 ]; then
975 diff -u $testroot/stderr.expected $testroot/stderr
976 test_done "$testroot" "$ret"
977 return 1
978 fi
980 rm -rf $testroot/wt
981 got checkout -c $orig_commit -p epsilon $testroot/repo \
982 $testroot/wt > /dev/null
983 ret=$?
984 if [ $ret -ne 0 ]; then
985 test_done "$testroot" "$ret"
986 return 1
987 fi
988 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
989 > $testroot/stdout)
991 local short_old_commit1=`trim_obj_id 28 $old_commit1`
992 local short_old_commit2=`trim_obj_id 28 $old_commit2`
994 echo "$short_old_commit1 -> drop commit: changing zeta" \
995 > $testroot/stdout.expected
996 echo "Switching work tree to refs/heads/master" \
997 >> $testroot/stdout.expected
999 cmp -s $testroot/stdout.expected $testroot/stdout
1000 ret=$?
1001 if [ $ret -ne 0 ]; then
1002 diff -u $testroot/stdout.expected $testroot/stdout
1003 test_done "$testroot" "$ret"
1004 return 1
1007 echo "zeta" > $testroot/content.expected
1008 cat $testroot/wt/zeta > $testroot/content
1009 cmp -s $testroot/content.expected $testroot/content
1010 ret=$?
1011 if [ $ret -ne 0 ]; then
1012 diff -u $testroot/content.expected $testroot/content
1013 test_done "$testroot" "$ret"
1014 return 1
1018 (cd $testroot/wt && got status > $testroot/stdout)
1020 echo -n > $testroot/stdout.expected
1021 cmp -s $testroot/stdout.expected $testroot/stdout
1022 ret=$?
1023 if [ $ret -ne 0 ]; then
1024 diff -u $testroot/stdout.expected $testroot/stdout
1025 test_done "$testroot" "$ret"
1026 return 1
1029 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1030 echo "commit $orig_commit (master)" > $testroot/stdout.expected
1031 cmp -s $testroot/stdout.expected $testroot/stdout
1032 ret=$?
1033 if [ $ret -ne 0 ]; then
1034 diff -u $testroot/stdout.expected $testroot/stdout
1036 test_done "$testroot" "$ret"
1039 test_histedit_path_prefix_edit() {
1040 local testroot=`test_init histedit_path_prefix_edit`
1041 local orig_commit=`git_show_head $testroot/repo`
1043 echo "modified zeta" > $testroot/repo/epsilon/zeta
1044 git_commit $testroot/repo -m "changing zeta"
1045 local old_commit1=`git_show_head $testroot/repo`
1047 got diff -r $testroot/repo $orig_commit $old_commit1 \
1048 > $testroot/diff.expected
1050 got checkout -c $orig_commit -p gamma $testroot/repo \
1051 $testroot/wt > /dev/null
1052 ret=$?
1053 if [ $ret -ne 0 ]; then
1054 test_done "$testroot" "$ret"
1055 return 1
1058 echo "edit $old_commit1" > $testroot/histedit-script
1059 echo "mesg modified zeta" >> $testroot/histedit-script
1061 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1062 > $testroot/stdout 2> $testroot/stderr)
1064 ret=$?
1065 if [ $ret -eq 0 ]; then
1066 echo "histedit succeeded unexpectedly" >&2
1067 test_done "$testroot" "1"
1068 return 1
1071 echo -n "got: cannot edit branch history which contains changes " \
1072 > $testroot/stderr.expected
1073 echo "outside of this work tree's path prefix" \
1074 >> $testroot/stderr.expected
1076 cmp -s $testroot/stderr.expected $testroot/stderr
1077 ret=$?
1078 if [ $ret -ne 0 ]; then
1079 diff -u $testroot/stderr.expected $testroot/stderr
1080 test_done "$testroot" "$ret"
1081 return 1
1084 rm -rf $testroot/wt
1085 got checkout -c $orig_commit -p epsilon $testroot/repo \
1086 $testroot/wt > /dev/null
1087 ret=$?
1088 if [ $ret -ne 0 ]; then
1089 test_done "$testroot" "$ret"
1090 return 1
1092 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1093 > $testroot/stdout)
1095 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1097 echo "G zeta" > $testroot/stdout.expected
1098 echo "Stopping histedit for amending commit $old_commit1" \
1099 >> $testroot/stdout.expected
1100 cmp -s $testroot/stdout.expected $testroot/stdout
1101 ret=$?
1102 if [ $ret -ne 0 ]; then
1103 diff -u $testroot/stdout.expected $testroot/stdout
1104 test_done "$testroot" "$ret"
1105 return 1
1108 echo "modified zeta" > $testroot/content.expected
1109 cat $testroot/wt/zeta > $testroot/content
1110 cmp -s $testroot/content.expected $testroot/content
1111 ret=$?
1112 if [ $ret -ne 0 ]; then
1113 diff -u $testroot/content.expected $testroot/content
1114 test_done "$testroot" "$ret"
1115 return 1
1118 (cd $testroot/wt && got status > $testroot/stdout)
1120 echo "M zeta"> $testroot/stdout.expected
1121 cmp -s $testroot/stdout.expected $testroot/stdout
1122 ret=$?
1123 if [ $ret -ne 0 ]; then
1124 diff -u $testroot/stdout.expected $testroot/stdout
1125 test_done "$testroot" "$ret"
1126 return 1
1129 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1131 local new_commit1=`git_show_head $testroot/repo`
1132 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1134 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1135 > $testroot/stdout.expected
1136 echo "modified zeta" >> $testroot/stdout.expected
1137 echo "Switching work tree to refs/heads/master" \
1138 >> $testroot/stdout.expected
1140 cmp -s $testroot/stdout.expected $testroot/stdout
1141 ret=$?
1142 if [ $ret -ne 0 ]; then
1143 diff -u $testroot/stdout.expected $testroot/stdout
1144 test_done "$testroot" "$ret"
1145 return 1
1148 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1149 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1150 echo "commit $orig_commit" >> $testroot/stdout.expected
1151 cmp -s $testroot/stdout.expected $testroot/stdout
1152 ret=$?
1153 if [ $ret -ne 0 ]; then
1154 diff -u $testroot/stdout.expected $testroot/stdout
1155 test_done "$testroot" "$ret"
1156 return 1
1159 got diff -r $testroot/repo $orig_commit $new_commit1 \
1160 > $testroot/diff
1161 ed -s $testroot/diff.expected <<-EOF
1162 ,s/$old_commit1/$new_commit1/
1164 EOF
1165 cmp -s $testroot/diff.expected $testroot/diff
1166 ret=$?
1167 if [ $ret -ne 0 ]; then
1168 diff -u $testroot/diff.expected $testroot/diff
1170 test_done "$testroot" "$ret"
1173 test_histedit_outside_refs_heads() {
1174 local testroot=`test_init histedit_outside_refs_heads`
1175 local commit1=`git_show_head $testroot/repo`
1177 got checkout $testroot/repo $testroot/wt > /dev/null
1178 ret=$?
1179 if [ $ret -ne 0 ]; then
1180 echo "got checkout failed unexpectedly"
1181 test_done "$testroot" "$ret"
1182 return 1
1185 echo "modified alpha" > $testroot/wt/alpha
1187 (cd $testroot/wt && got commit -m 'change alpha' \
1188 > $testroot/stdout 2> $testroot/stderr)
1189 ret=$?
1190 if [ $ret -ne 0 ]; then
1191 echo "got commit failed unexpectedly" >&2
1192 test_done "$testroot" "1"
1193 return 1
1195 local commit2=`git_show_head $testroot/repo`
1197 got ref -r $testroot/repo -c master refs/remotes/origin/master
1198 ret=$?
1199 if [ $ret -ne 0 ]; then
1200 echo "got ref failed unexpectedly" >&2
1201 test_done "$testroot" "1"
1202 return 1
1205 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1206 ret=$?
1207 if [ $ret -ne 0 ]; then
1208 echo "got update failed unexpectedly"
1209 test_done "$testroot" "$ret"
1210 return 1
1213 echo "edit $commit2" > $testroot/histedit-script
1214 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1215 2> $testroot/stderr)
1217 echo -n "got: will not edit commit history of a branch outside the " \
1218 > $testroot/stderr.expected
1219 echo '"refs/heads/" reference namespace' \
1220 >> $testroot/stderr.expected
1221 cmp -s $testroot/stderr.expected $testroot/stderr
1222 ret=$?
1223 if [ $ret -ne 0 ]; then
1224 diff -u $testroot/stderr.expected $testroot/stderr
1226 test_done "$testroot" "$ret"
1229 test_histedit_fold_last_commit_swap() {
1230 local testroot=`test_init histedit_fold_last_commit_swap`
1232 local orig_commit=`git_show_head $testroot/repo`
1234 echo "modified alpha on master" > $testroot/repo/alpha
1235 (cd $testroot/repo && git rm -q beta)
1236 echo "new file on master" > $testroot/repo/epsilon/new
1237 (cd $testroot/repo && git add epsilon/new)
1238 git_commit $testroot/repo -m "committing changes"
1239 local old_commit1=`git_show_head $testroot/repo`
1241 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1242 git_commit $testroot/repo -m "committing to zeta on master"
1243 local old_commit2=`git_show_head $testroot/repo`
1245 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1246 ret=$?
1247 if [ $ret -ne 0 ]; then
1248 test_done "$testroot" "$ret"
1249 return 1
1252 # fold commit2 into commit1 (requires swapping commits)
1253 echo "fold $old_commit2" > $testroot/histedit-script
1254 echo "pick $old_commit1" >> $testroot/histedit-script
1255 echo "mesg committing folded changes" >> $testroot/histedit-script
1257 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1258 > $testroot/stdout 2> $testroot/stderr)
1260 ret=$?
1261 if [ $ret -ne 0 ]; then
1262 echo "histedit failed unexpectedly" >&2
1263 test_done "$testroot" "$ret"
1264 return 1
1267 local new_commit=`git_show_head $testroot/repo`
1269 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1270 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1271 local short_new_commit=`trim_obj_id 28 $new_commit`
1273 echo "G epsilon/zeta" >> $testroot/stdout.expected
1274 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1275 >> $testroot/stdout.expected
1276 echo "on master" >> $testroot/stdout.expected
1277 echo "G alpha" >> $testroot/stdout.expected
1278 echo "D beta" >> $testroot/stdout.expected
1279 echo "A epsilon/new" >> $testroot/stdout.expected
1280 echo -n "$short_old_commit1 -> $short_new_commit: " \
1281 >> $testroot/stdout.expected
1282 echo "committing folded changes" >> $testroot/stdout.expected
1283 echo "Switching work tree to refs/heads/master" \
1284 >> $testroot/stdout.expected
1286 cmp -s $testroot/stdout.expected $testroot/stdout
1287 ret=$?
1288 if [ $ret -ne 0 ]; then
1289 diff -u $testroot/stdout.expected $testroot/stdout
1291 test_done "$testroot" "$ret"
1294 test_histedit_split_commit() {
1295 local testroot=`test_init histedit_split_commit`
1297 local orig_commit=`git_show_head $testroot/repo`
1299 echo "modified alpha on master" > $testroot/repo/alpha
1300 (cd $testroot/repo && git rm -q beta)
1301 echo "new file on master" > $testroot/repo/epsilon/new
1302 (cd $testroot/repo && git add epsilon/new)
1303 git_commit $testroot/repo -m "committing changes 1"
1304 local old_commit1=`git_show_head $testroot/repo`
1305 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1307 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1308 git_commit $testroot/repo -m "committing changes 2"
1309 local old_commit2=`git_show_head $testroot/repo`
1310 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1312 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1313 ret=$?
1314 if [ $ret -ne 0 ]; then
1315 test_done "$testroot" "$ret"
1316 return 1
1319 # split commit1 into commitA and commitB and commitC
1320 echo "e $old_commit1" > $testroot/histedit-script
1321 echo "p $old_commit2" >> $testroot/histedit-script
1323 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1324 > $testroot/stdout 2> $testroot/stderr)
1325 ret=$?
1326 if [ $ret -ne 0 ]; then
1327 echo "histedit failed unexpectedly:" >&2
1328 cat $testroot/stderr >&2
1329 test_done "$testroot" "$ret"
1330 return 1
1333 echo "G alpha" > $testroot/stdout.expected
1334 echo "D beta" >> $testroot/stdout.expected
1335 echo "A epsilon/new" >> $testroot/stdout.expected
1336 echo "Stopping histedit for amending commit $old_commit1" \
1337 >> $testroot/stdout.expected
1339 cmp -s $testroot/stdout.expected $testroot/stdout
1340 ret=$?
1341 if [ $ret -ne 0 ]; then
1342 diff -u $testroot/stdout.expected $testroot/stdout
1343 test_done "$testroot" "$ret"
1344 return 1
1347 (cd $testroot/wt && got ci -m "commitA" alpha >/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 "commitB" beta >/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 ci -m "commitC" epsilon/new >/dev/null)
1364 ret=$?
1365 if [ $ret -ne 0 ]; then
1366 echo "commit failed unexpectedly" >&2
1367 test_done "$testroot" "$ret"
1368 return 1
1371 (cd $testroot/wt && got histedit -c \
1372 > $testroot/stdout 2> $testroot/stderr)
1373 ret=$?
1374 if [ $ret -ne 0 ]; then
1375 echo "histedit failed unexpectedly:" >&2
1376 cat $testroot/stderr >&2
1377 test_done "$testroot" "$ret"
1378 return 1
1380 local new_commit2=`git_show_head $testroot/repo`
1381 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1383 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1384 > $testroot/stdout.expected
1385 echo "G epsilon/zeta" >> $testroot/stdout.expected
1386 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1387 >> $testroot/stdout.expected
1388 echo "Switching work tree to refs/heads/master" \
1389 >> $testroot/stdout.expected
1391 cmp -s $testroot/stdout.expected $testroot/stdout
1392 ret=$?
1393 if [ $ret -ne 0 ]; then
1394 diff -u $testroot/stdout.expected $testroot/stdout
1396 test_done "$testroot" "$ret"
1400 test_histedit_duplicate_commit_in_script() {
1401 local testroot=`test_init histedit_duplicate_commit_in_script`
1403 local orig_commit=`git_show_head $testroot/repo`
1405 echo "modified alpha on master" > $testroot/repo/alpha
1406 (cd $testroot/repo && git rm -q beta)
1407 echo "new file on master" > $testroot/repo/epsilon/new
1408 (cd $testroot/repo && git add epsilon/new)
1409 git_commit $testroot/repo -m "committing changes 1"
1410 local old_commit1=`git_show_head $testroot/repo`
1412 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1413 git_commit $testroot/repo -m "committing changes 2"
1414 local old_commit2=`git_show_head $testroot/repo`
1416 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1417 ret=$?
1418 if [ $ret -ne 0 ]; then
1419 test_done "$testroot" "$ret"
1420 return 1
1423 # This histedit script lists commit1 more than once
1424 echo "p $old_commit1" > $testroot/histedit-script
1425 echo "p $old_commit1" >> $testroot/histedit-script
1426 echo "p $old_commit2" >> $testroot/histedit-script
1428 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1429 > $testroot/stdout 2> $testroot/stderr)
1430 ret=$?
1431 if [ $ret -eq 0 ]; then
1432 echo "histedit succeeded unexpectedly:" >&2
1433 cat $testroot/stdout >&2
1434 test_done "$testroot" "$ret"
1435 return 1
1438 echo -n "got: commit $old_commit1 is listed more than once " \
1439 > $testroot/stderr.expected
1440 echo "in histedit script" >> $testroot/stderr.expected
1442 cmp -s $testroot/stderr.expected $testroot/stderr
1443 ret=$?
1444 if [ $ret -ne 0 ]; then
1445 diff -u $testroot/stderr.expected $testroot/stderr
1447 test_done "$testroot" "$ret"
1451 # if a previous commit introduces a new file, and it is folded into a commit
1452 # that deletes the same file, the file still exists after the histedit
1453 test_histedit_fold_add_delete() {
1454 local testroot=`test_init histedit_fold_add_delete`
1456 local orig_commit=`git_show_head $testroot/repo`
1458 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1459 (cd $testroot/repo && git add epsilon/psi)
1460 git_commit $testroot/repo -m "committing changes"
1461 local old_commit1=`git_show_head $testroot/repo`
1463 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1464 git_commit $testroot/repo -m "editing psi"
1465 local old_commit2=`git_show_head $testroot/repo`
1467 (cd $testroot/repo && git rm -q epsilon/psi)
1468 git_commit $testroot/repo -m "removing psi"
1469 local old_commit3=`git_show_head $testroot/repo`
1471 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1472 ret=$?
1473 if [ $ret -ne 0 ]; then
1474 test_done "$testroot" "$ret"
1475 return 1
1478 echo "fold $old_commit1" > $testroot/histedit-script
1479 echo "fold $old_commit2" >> $testroot/histedit-script
1480 echo "pick $old_commit3" >> $testroot/histedit-script
1481 echo "mesg folded changes" >> $testroot/histedit-script
1483 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1484 > $testroot/stdout)
1486 local new_commit1=`git_show_head $testroot/repo`
1488 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1489 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1490 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1491 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1493 echo "A epsilon/psi" >> $testroot/stdout.expected
1494 echo "$short_old_commit1 -> fold commit: committing changes" \
1495 >> $testroot/stdout.expected
1496 echo "G epsilon/psi" >> $testroot/stdout.expected
1497 echo "$short_old_commit2 -> fold commit: editing psi" \
1498 >> $testroot/stdout.expected
1499 echo "D epsilon/psi" >> $testroot/stdout.expected
1500 echo "$short_old_commit3 -> no-op change: folded changes" \
1501 >> $testroot/stdout.expected
1502 echo "Switching work tree to refs/heads/master" \
1503 >> $testroot/stdout.expected
1505 cmp -s $testroot/stdout.expected $testroot/stdout
1506 ret=$?
1507 if [ $ret -ne 0 ]; then
1508 diff -u $testroot/stdout.expected $testroot/stdout
1509 test_done "$testroot" "$ret"
1510 return 1
1513 if [ -e $testroot/wt/epsilon/psi ]; then
1514 echo "removed file psi still exists on disk" >&2
1515 test_done "$testroot" "1"
1516 return 1
1519 (cd $testroot/wt && got status > $testroot/stdout)
1521 echo -n > $testroot/stdout.expected
1522 cmp -s $testroot/stdout.expected $testroot/stdout
1523 ret=$?
1524 if [ $ret -ne 0 ]; then
1525 diff -u $testroot/stdout.expected $testroot/stdout
1526 test_done "$testroot" "$ret"
1527 return 1
1530 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1531 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1532 cmp -s $testroot/stdout.expected $testroot/stdout
1533 ret=$?
1534 if [ $ret -ne 0 ]; then
1535 diff -u $testroot/stdout.expected $testroot/stdout
1536 test_done "$testroot" "$ret"
1537 return 1
1540 got tree -r $testroot/repo epsilon > $testroot/stdout
1541 echo "zeta" > $testroot/stdout.expected
1542 cmp -s $testroot/stdout.expected $testroot/stdout
1543 ret=$?
1544 if [ $ret -ne 0 ]; then
1545 diff -u $testroot/stdout.expected $testroot/stdout
1547 test_done "$testroot" "$ret"
1550 test_histedit_fold_delete_add() {
1551 local testroot=`test_init histedit_fold_delete_add`
1553 local orig_commit=`git_show_head $testroot/repo`
1555 (cd $testroot/repo && git rm -q alpha)
1556 git_commit $testroot/repo -m "removing alpha"
1557 local old_commit1=`git_show_head $testroot/repo`
1559 echo "modified alpha" >$testroot/repo/alpha
1560 (cd $testroot/repo && git add alpha)
1561 git_commit $testroot/repo -m "add back modified alpha"
1562 local old_commit2=`git_show_head $testroot/repo`
1564 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1565 ret=$?
1566 if [ $ret -ne 0 ]; then
1567 test_done "$testroot" "$ret"
1568 return 1
1571 echo "fold $old_commit1" > $testroot/histedit-script
1572 echo "pick $old_commit2" >> $testroot/histedit-script
1573 echo "mesg folded changes" >> $testroot/histedit-script
1575 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1576 > $testroot/stdout)
1578 local new_commit1=`git_show_head $testroot/repo`
1580 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1581 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1582 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1584 echo "D alpha" > $testroot/stdout.expected
1585 echo "$short_old_commit1 -> fold commit: removing alpha" \
1586 >> $testroot/stdout.expected
1587 echo "A alpha" >> $testroot/stdout.expected
1588 echo "$short_old_commit2 -> $short_new_commit1: folded changes" \
1589 >> $testroot/stdout.expected
1590 echo "Switching work tree to refs/heads/master" \
1591 >> $testroot/stdout.expected
1593 #cmp -s $testroot/stdout.expected $testroot/stdout
1594 #ret=$?
1595 #if [ $ret -ne 0 ]; then
1596 # diff -u $testroot/stdout.expected $testroot/stdout
1597 # test_done "$testroot" "$ret"
1598 # return 1
1599 #fi
1601 if [ ! -e $testroot/wt/alpha ]; then
1602 ret="xfail fold deleted and added file"
1604 test_done "$testroot" "$ret"
1607 test_histedit_fold_only() {
1608 local testroot=`test_init histedit_fold_only`
1610 local orig_commit=`git_show_head $testroot/repo`
1612 echo "modified alpha on master" > $testroot/repo/alpha
1613 (cd $testroot/repo && git rm -q beta)
1614 echo "new file on master" > $testroot/repo/epsilon/new
1615 (cd $testroot/repo && git add epsilon/new)
1616 git_commit $testroot/repo -m "committing changes"
1617 local old_commit1=`git_show_head $testroot/repo`
1619 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1620 git_commit $testroot/repo -m "committing to zeta on master"
1621 local old_commit2=`git_show_head $testroot/repo`
1623 echo "modified delta on master" > $testroot/repo/gamma/delta
1624 git_commit $testroot/repo -m "committing to delta on master"
1625 local old_commit3=`git_show_head $testroot/repo`
1627 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1628 ret=$?
1629 if [ $ret -ne 0 ]; then
1630 test_done "$testroot" "$ret"
1631 return 1
1634 cat > $testroot/editor.sh <<EOF
1635 #!/bin/sh
1636 ed -s "\$1" <<-EOF
1637 ,s/.*/committing folded changes/
1639 EOF
1640 EOF
1641 chmod +x $testroot/editor.sh
1643 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1644 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1646 local new_commit1=`git_show_head $testroot/repo`
1648 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1649 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1650 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1651 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1652 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1654 echo "G alpha" > $testroot/stdout.expected
1655 echo "D beta" >> $testroot/stdout.expected
1656 echo "A epsilon/new" >> $testroot/stdout.expected
1657 echo "$short_old_commit1 -> fold commit: committing changes" \
1658 >> $testroot/stdout.expected
1659 echo "G epsilon/zeta" >> $testroot/stdout.expected
1660 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1661 echo "fold commit: committing to zeta on master" \
1662 >> $testroot/stdout.expected
1663 echo "G gamma/delta" >> $testroot/stdout.expected
1664 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1665 >> $testroot/stdout.expected
1666 echo "committing folded changes" >> $testroot/stdout.expected
1667 echo "Switching work tree to refs/heads/master" \
1668 >> $testroot/stdout.expected
1670 cmp -s $testroot/stdout.expected $testroot/stdout
1671 ret=$?
1672 if [ $ret -ne 0 ]; then
1673 diff -u $testroot/stdout.expected $testroot/stdout
1674 test_done "$testroot" "$ret"
1675 return 1
1678 echo "modified alpha on master" > $testroot/content.expected
1679 cat $testroot/wt/alpha > $testroot/content
1680 cmp -s $testroot/content.expected $testroot/content
1681 ret=$?
1682 if [ $ret -ne 0 ]; then
1683 diff -u $testroot/content.expected $testroot/content
1684 test_done "$testroot" "$ret"
1685 return 1
1688 if [ -e $testroot/wt/beta ]; then
1689 echo "removed file beta still exists on disk" >&2
1690 test_done "$testroot" "1"
1691 return 1
1694 echo "new file on master" > $testroot/content.expected
1695 cat $testroot/wt/epsilon/new > $testroot/content
1696 cmp -s $testroot/content.expected $testroot/content
1697 ret=$?
1698 if [ $ret -ne 0 ]; then
1699 diff -u $testroot/content.expected $testroot/content
1700 test_done "$testroot" "$ret"
1701 return 1
1704 (cd $testroot/wt && got status > $testroot/stdout)
1706 echo -n > $testroot/stdout.expected
1707 cmp -s $testroot/stdout.expected $testroot/stdout
1708 ret=$?
1709 if [ $ret -ne 0 ]; then
1710 diff -u $testroot/stdout.expected $testroot/stdout
1711 test_done "$testroot" "$ret"
1712 return 1
1715 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1716 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1717 echo "commit $orig_commit" >> $testroot/stdout.expected
1718 cmp -s $testroot/stdout.expected $testroot/stdout
1719 ret=$?
1720 if [ $ret -ne 0 ]; then
1721 diff -u $testroot/stdout.expected $testroot/stdout
1723 test_done "$testroot" "$ret"
1726 test_histedit_fold_only_empty_logmsg() {
1727 local testroot=`test_init histedit_fold_only_empty_logmsg`
1729 local orig_commit=`git_show_head $testroot/repo`
1731 echo "modified alpha on master" > $testroot/repo/alpha
1732 (cd $testroot/repo && git rm -q beta)
1733 echo "new file on master" > $testroot/repo/epsilon/new
1734 (cd $testroot/repo && git add epsilon/new)
1735 git_commit $testroot/repo -m "committing changes"
1736 local old_commit1=`git_show_head $testroot/repo`
1738 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1739 git_commit $testroot/repo -m "committing to zeta on master"
1740 local old_commit2=`git_show_head $testroot/repo`
1742 echo "modified delta on master" > $testroot/repo/gamma/delta
1743 git_commit $testroot/repo -m "committing to delta on master"
1744 local old_commit3=`git_show_head $testroot/repo`
1746 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1747 ret=$?
1748 if [ $ret -ne 0 ]; then
1749 test_done "$testroot" "$ret"
1750 return 1
1753 cat > $testroot/editor.sh <<EOF
1754 #!/bin/sh
1755 ed -s "\$1" <<-EOF
1758 EOF
1759 EOF
1760 chmod +x $testroot/editor.sh
1762 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1763 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1765 local new_commit1=`git_show_head $testroot/repo`
1767 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1768 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1769 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1770 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1771 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1772 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1774 echo "G alpha" > $testroot/stdout.expected
1775 echo "D beta" >> $testroot/stdout.expected
1776 echo "A epsilon/new" >> $testroot/stdout.expected
1777 echo "$short_old_commit1 -> fold commit: committing changes" \
1778 >> $testroot/stdout.expected
1779 echo "G epsilon/zeta" >> $testroot/stdout.expected
1780 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1781 echo "fold commit: committing to zeta on master" \
1782 >> $testroot/stdout.expected
1783 echo "G gamma/delta" >> $testroot/stdout.expected
1784 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1785 >> $testroot/stdout.expected
1786 echo "# log message of folded commit $very_short_old_commit1" \
1787 >> $testroot/stdout.expected
1788 echo "Switching work tree to refs/heads/master" \
1789 >> $testroot/stdout.expected
1791 cmp -s $testroot/stdout.expected $testroot/stdout
1792 ret=$?
1793 if [ $ret -ne 0 ]; then
1794 diff -u $testroot/stdout.expected $testroot/stdout
1795 test_done "$testroot" "$ret"
1796 return 1
1799 echo "modified alpha on master" > $testroot/content.expected
1800 cat $testroot/wt/alpha > $testroot/content
1801 cmp -s $testroot/content.expected $testroot/content
1802 ret=$?
1803 if [ $ret -ne 0 ]; then
1804 diff -u $testroot/content.expected $testroot/content
1805 test_done "$testroot" "$ret"
1806 return 1
1809 if [ -e $testroot/wt/beta ]; then
1810 echo "removed file beta still exists on disk" >&2
1811 test_done "$testroot" "1"
1812 return 1
1815 echo "new file on master" > $testroot/content.expected
1816 cat $testroot/wt/epsilon/new > $testroot/content
1817 cmp -s $testroot/content.expected $testroot/content
1818 ret=$?
1819 if [ $ret -ne 0 ]; then
1820 diff -u $testroot/content.expected $testroot/content
1821 test_done "$testroot" "$ret"
1822 return 1
1825 (cd $testroot/wt && got status > $testroot/stdout)
1827 echo -n > $testroot/stdout.expected
1828 cmp -s $testroot/stdout.expected $testroot/stdout
1829 ret=$?
1830 if [ $ret -ne 0 ]; then
1831 diff -u $testroot/stdout.expected $testroot/stdout
1832 test_done "$testroot" "$ret"
1833 return 1
1836 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1837 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1838 echo "commit $orig_commit" >> $testroot/stdout.expected
1839 cmp -s $testroot/stdout.expected $testroot/stdout
1840 ret=$?
1841 if [ $ret -ne 0 ]; then
1842 diff -u $testroot/stdout.expected $testroot/stdout
1844 test_done "$testroot" "$ret"
1847 test_histedit_edit_only() {
1848 local testroot=`test_init histedit_edit_only`
1850 local orig_commit=`git_show_head $testroot/repo`
1852 echo "modified alpha on master" > $testroot/repo/alpha
1853 (cd $testroot/repo && git rm -q beta)
1854 echo "new file on master" > $testroot/repo/epsilon/new
1855 (cd $testroot/repo && git add epsilon/new)
1856 git_commit $testroot/repo -m "committing changes"
1857 local old_commit1=`git_show_head $testroot/repo`
1859 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1860 git_commit $testroot/repo -m "committing to zeta on master"
1861 local old_commit2=`git_show_head $testroot/repo`
1863 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1864 ret=$?
1865 if [ $ret -ne 0 ]; then
1866 test_done "$testroot" "$ret"
1867 return 1
1870 (cd $testroot/wt && got histedit -e > $testroot/stdout)
1872 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1873 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1875 echo "G alpha" > $testroot/stdout.expected
1876 echo "D beta" >> $testroot/stdout.expected
1877 echo "A epsilon/new" >> $testroot/stdout.expected
1878 echo "Stopping histedit for amending commit $old_commit1" \
1879 >> $testroot/stdout.expected
1880 cmp -s $testroot/stdout.expected $testroot/stdout
1881 ret=$?
1882 if [ $ret -ne 0 ]; then
1883 diff -u $testroot/stdout.expected $testroot/stdout
1884 test_done "$testroot" "$ret"
1885 return 1
1888 echo "edited modified alpha on master" > $testroot/wt/alpha
1890 cat > $testroot/editor.sh <<EOF
1891 #!/bin/sh
1892 ed -s "\$1" <<-EOF
1893 ,s/.*/committing edited changes 1/
1895 EOF
1896 EOF
1897 chmod +x $testroot/editor.sh
1899 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1900 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1902 local new_commit1=$(cd $testroot/wt && got info | \
1903 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1904 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1906 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1907 > $testroot/stdout.expected
1908 echo "committing edited changes 1" >> $testroot/stdout.expected
1909 echo "G epsilon/zeta" >> $testroot/stdout.expected
1910 echo "Stopping histedit for amending commit $old_commit2" \
1911 >> $testroot/stdout.expected
1912 cmp -s $testroot/stdout.expected $testroot/stdout
1913 ret=$?
1914 if [ $ret -ne 0 ]; then
1915 diff -u $testroot/stdout.expected $testroot/stdout
1916 test_done "$testroot" "$ret"
1917 return 1
1920 echo "edited zeta on master" > $testroot/wt/epsilon/zeta
1922 cat > $testroot/editor.sh <<EOF
1923 #!/bin/sh
1924 ed -s "\$1" <<-EOF
1925 ,s/.*/committing edited changes 2/
1927 EOF
1928 EOF
1929 chmod +x $testroot/editor.sh
1931 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1932 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1934 local new_commit2=`git_show_head $testroot/repo`
1935 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1937 echo -n "$short_old_commit2 -> $short_new_commit2: " \
1938 > $testroot/stdout.expected
1939 echo "committing edited changes 2" >> $testroot/stdout.expected
1940 echo "Switching work tree to refs/heads/master" \
1941 >> $testroot/stdout.expected
1943 cmp -s $testroot/stdout.expected $testroot/stdout
1944 ret=$?
1945 if [ $ret -ne 0 ]; then
1946 diff -u $testroot/stdout.expected $testroot/stdout
1947 test_done "$testroot" "$ret"
1948 return 1
1951 echo "edited modified alpha on master" > $testroot/content.expected
1952 cat $testroot/wt/alpha > $testroot/content
1953 cmp -s $testroot/content.expected $testroot/content
1954 ret=$?
1955 if [ $ret -ne 0 ]; then
1956 diff -u $testroot/content.expected $testroot/content
1957 test_done "$testroot" "$ret"
1958 return 1
1961 if [ -e $testroot/wt/beta ]; then
1962 echo "removed file beta still exists on disk" >&2
1963 test_done "$testroot" "1"
1964 return 1
1967 echo "new file on master" > $testroot/content.expected
1968 cat $testroot/wt/epsilon/new > $testroot/content
1969 cmp -s $testroot/content.expected $testroot/content
1970 ret=$?
1971 if [ $ret -ne 0 ]; then
1972 diff -u $testroot/content.expected $testroot/content
1973 test_done "$testroot" "$ret"
1974 return 1
1977 (cd $testroot/wt && got status > $testroot/stdout)
1979 echo -n > $testroot/stdout.expected
1980 cmp -s $testroot/stdout.expected $testroot/stdout
1981 ret=$?
1982 if [ $ret -ne 0 ]; then
1983 diff -u $testroot/stdout.expected $testroot/stdout
1984 test_done "$testroot" "$ret"
1985 return 1
1988 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1989 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
1990 echo "commit $new_commit1" >> $testroot/stdout.expected
1991 echo "commit $orig_commit" >> $testroot/stdout.expected
1992 cmp -s $testroot/stdout.expected $testroot/stdout
1993 ret=$?
1994 if [ $ret -ne 0 ]; then
1995 diff -u $testroot/stdout.expected $testroot/stdout
1997 test_done "$testroot" "$ret"
2000 test_histedit_prepend_line() {
2001 local testroot=`test_init histedit_prepend_line`
2002 local orig_commit=`git_show_head $testroot/repo`
2004 got checkout $testroot/repo $testroot/wt > /dev/null
2006 ed -s "$testroot/wt/alpha" <<EOF
2008 first line
2011 EOF
2013 cp $testroot/wt/alpha $testroot/content.expected
2015 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2016 alpha > /dev/null)
2017 ret=$?
2018 if [ "$?" != 0 ]; then
2019 echo "got commit failed unexpectedly" >&2
2020 test_done "$testroot" "$ret"
2021 return 1
2024 local top_commit=`git_show_head $testroot/repo`
2025 echo "pick $top_commit" > "$testroot/histedit-script"
2027 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2028 ret=$?
2029 if [ "$?" != 0 ]; then
2030 echo "got update failed unexpectedly" >&2
2031 test_done "$testroot" "$ret"
2032 return 1
2035 (cd $testroot/wt && got histedit -F "$testroot/histedit-script" \
2036 > /dev/null)
2037 ret=$?
2038 if [ "$?" != 0 ]; then
2039 echo "got histedit failed unexpectedly" >&2
2040 test_done "$testroot" "$ret"
2041 return 1
2044 cp $testroot/wt/alpha $testroot/content
2045 cmp -s $testroot/content.expected $testroot/content
2046 ret=$?
2047 if [ $ret -ne 0 ]; then
2048 diff -u $testroot/content.expected $testroot/content
2049 test_done "$testroot" "$ret"
2050 return 1
2053 test_done "$testroot" $ret
2056 test_histedit_mesg_invalid() {
2057 local testroot=`test_init mesg_invalid`
2059 local orig_commit=`git_show_head $testroot/repo`
2061 echo "modified alpha on master" > $testroot/repo/alpha
2062 (cd $testroot/repo && git rm -q beta)
2063 echo "new file on master" > $testroot/repo/epsilon/new
2064 (cd $testroot/repo && git add epsilon/new)
2065 git_commit $testroot/repo -m 'committing changes'
2066 local old_commit1=`git_show_head $testroot/repo`
2068 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2069 git_commit $testroot/repo -m 'committing to zeto on master'
2070 local old_commit2=`git_show_head $testroot/repo`
2072 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2073 ret=$?
2074 if [ $ret -ne 0 ]; then
2075 test_done "$testroot" $ret
2076 return 1
2079 # try with a leading mesg
2081 echo "mesg something something" > $testroot/histedit-script
2082 echo "pick $old_commit1" >> $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
2099 test_done "$testroot" $ret
2100 return 1
2103 # try again with mesg -> mesg
2105 echo "pick $old_commit1" > $testroot/histedit-script
2106 echo "mesg something something" >> $testroot/histedit-script
2107 echo "mesg something something else" >> $testroot/histedit-script
2108 echo "pick $old_commit2" >> $testroot/histedit-script
2110 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2111 > $testroot/stdout 2> $testroot/stderr)
2112 ret=$?
2113 if [ $ret -eq 0 ]; then
2114 echo "histedit succeeded unexpectedly" >&2
2115 test_done "$testroot" 1
2116 return 1
2119 echo "got: bad histedit command" > $testroot/stderr.expected
2120 cmp -s $testroot/stderr.expected $testroot/stderr
2121 ret=$?
2122 if [ $ret -ne 0 ]; then
2123 diff -u $testroot/stderr.expected $testroot/stderr
2124 test_done "$testroot" $ret
2125 return 1
2128 # try again with drop -> mesg
2130 echo "drop $old_commit1" > $testroot/histedit-script
2131 echo "mesg something something" >> $testroot/histedit-script
2132 echo "pick $old_commit2" >> $testroot/histedit-script
2134 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2135 > $testroot/stdout 2> $testroot/stderr)
2136 ret=$?
2137 if [ $ret -eq 0 ]; then
2138 echo "histedit succeeded unexpectedly" >&2
2139 test_done "$testroot" 1
2140 return 1
2143 echo "got: bad histedit command" > $testroot/stderr.expected
2144 cmp -s $testroot/stderr.expected $testroot/stderr
2145 ret=$?
2146 if [ $ret -ne 0 ]; then
2147 diff -u $testroot/stderr.expected $testroot/stderr
2148 test_done "$testroot" $ret
2149 return 1
2152 # try again with fold -> mesg
2154 echo "fold $old_commit1" > $testroot/histedit-script
2155 echo "mesg something something" >> $testroot/histedit-script
2156 echo "pick $old_commit2" >> $testroot/histedit-script
2158 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2159 > $testroot/stdout 2> $testroot/stderr)
2160 ret=$?
2161 if [ $ret -eq 0 ]; then
2162 echo "histedit succeeded unexpectedly" >&2
2163 test_done "$testroot" 1
2164 return 1
2167 echo "got: bad histedit command" > $testroot/stderr.expected
2168 cmp -s $testroot/stderr.expected $testroot/stderr
2169 ret=$?
2170 if [ $ret -ne 0 ]; then
2171 diff -u $testroot/stderr.expected $testroot/stderr
2173 test_done "$testroot" $ret
2176 test_histedit_resets_committer() {
2177 local testroot=`test_init histedit_resets_committer`
2178 local orig_commit=`git_show_head $testroot/repo`
2179 local committer="Flan Luck <flan_luck@openbsd.org>"
2181 got checkout $testroot/repo $testroot/wt > /dev/null
2183 echo "modified alpha" > $testroot/wt/alpha
2185 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2186 alpha > /dev/null)
2187 ret=$?
2188 if [ "$?" != 0 ]; then
2189 echo "got commit failed unexpectedly" >&2
2190 test_done "$testroot" "$ret"
2191 return 1
2194 local top_commit=`git_show_head $testroot/repo`
2195 echo "pick $top_commit" > "$testroot/histedit-script"
2197 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2198 ret=$?
2199 if [ "$?" != 0 ]; then
2200 echo "got update failed unexpectedly" >&2
2201 test_done "$testroot" "$ret"
2202 return 1
2205 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
2206 got histedit -F "$testroot/histedit-script" > /dev/null)
2207 ret=$?
2208 if [ "$?" != 0 ]; then
2209 echo "got histedit failed unexpectedly" >&2
2210 test_done "$testroot" "$ret"
2211 return 1
2213 local edited_commit=`git_show_head $testroot/repo`
2215 # Original commit only had one author
2216 (cd $testroot/repo && got log -l1 -c $top_commit | \
2217 egrep '^(from|via):' > $testroot/stdout)
2218 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2219 cmp -s $testroot/stdout.expected $testroot/stdout
2220 ret=$?
2221 if [ $ret -ne 0 ]; then
2222 diff -u $testroot/stdout.expected $testroot/stdout
2223 test_done "$testroot" "$ret"
2224 return 1
2227 # Edited commit should have new committer name added
2228 (cd $testroot/repo && got log -l1 -c $edited_commit | \
2229 egrep '^(from|via):' > $testroot/stdout)
2230 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2231 echo "via: $committer" >> $testroot/stdout.expected
2233 cmp -s $testroot/stdout.expected $testroot/stdout
2234 ret=$?
2235 if [ $ret -ne 0 ]; then
2236 diff -u $testroot/stdout.expected $testroot/stdout
2238 test_done "$testroot" "$ret"
2241 test_histedit_umask() {
2242 local testroot=`test_init histedit_umask`
2243 local orig_commit=`git_show_head "$testroot/repo"`
2245 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
2247 echo "modified alpha" > $testroot/wt/alpha
2248 (cd "$testroot/wt" && got commit -m 'edit #1') >/dev/null
2249 local commit1=`git_show_head "$testroot/repo"`
2251 echo "modified again" > $testroot/wt/alpha
2252 (cd "$testroot/wt" && got commit -m 'edit #2') >/dev/null
2253 local commit2=`git_show_head "$testroot/repo"`
2255 echo "modified again!" > $testroot/wt/alpha
2256 echo "modify beta too!" > $testroot/wt/beta
2257 (cd "$testroot/wt" && got commit -m 'edit #3') >/dev/null
2258 local commit3=`git_show_head "$testroot/repo"`
2260 (cd "$testroot/wt" && got update -c "$orig_commit") >/dev/null
2261 ret=$?
2262 if [ $ret -ne 0 ]; then
2263 echo "update to $orig_commit failed!" >&2
2264 test_done "$testroot" 1
2265 return 1
2268 echo fold $commit1 >$testroot/histedit-script
2269 echo fold $commit2 >>$testroot/histedit-script
2270 echo pick $commit3 >>$testroot/histedit-script
2271 echo mesg folding changes >>$testroot/histedit-script
2273 # using a subshell to avoid clobbering global umask
2274 (umask 077 && cd "$testroot/wt" && \
2275 got histedit -F "$testroot/histedit-script") >/dev/null
2276 ret=$?
2278 if [ $ret -ne 0 ]; then
2279 echo "histedit operation failed" >&2
2280 test_done "$testroot" $ret
2281 return 1
2284 for f in alpha beta; do
2285 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
2286 if [ $? -ne 0 ]; then
2287 echo "$f is not 0600 after histedi" >&2
2288 ls -l "$testroot/wt/$f" >&2
2289 test_done "$testroot" 1
2290 return 1
2292 done
2294 test_done "$testroot" 0
2297 test_histedit_mesg_filemode_change() {
2298 local testroot=`test_init histedit_mode_change`
2300 local orig_commit=`git_show_head $testroot/repo`
2301 local orig_author_time=`git_show_author_time $testroot/repo`
2303 chmod +x $testroot/repo/alpha
2304 git_commit $testroot/repo -m "set x bit on alpha"
2305 local old_commit1=`git_show_head $testroot/repo`
2306 local old_author_time1=`git_show_author_time $testroot/repo`
2308 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2309 ret=$?
2310 if [ $ret -ne 0 ]; then
2311 test_done "$testroot" "$ret"
2312 return 1
2315 if [ -x $testroot/wt/alpha ]; then
2316 echo "file alpha has unexpected executable bit" >&2
2317 test_done "$testroot" "1"
2318 return 1
2321 cat > $testroot/editor.sh <<EOF
2322 #!/bin/sh
2323 ed -s "\$1" <<-EOF
2324 ,s/ x bit / executable bit /
2326 EOF
2327 EOF
2329 chmod +x $testroot/editor.sh
2331 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
2332 got histedit -m > $testroot/stdout)
2334 local new_commit1=`git_show_head $testroot/repo`
2335 local new_author_time1=`git_show_author_time $testroot/repo`
2337 local short_old_commit1=`trim_obj_id 28 $old_commit1`
2338 local short_new_commit1=`trim_obj_id 28 $new_commit1`
2340 echo "G alpha" > $testroot/stdout.expected
2341 echo "$short_old_commit1 -> $short_new_commit1: set executable bit on alpha" \
2342 >> $testroot/stdout.expected
2343 echo "Switching work tree to refs/heads/master" \
2344 >> $testroot/stdout.expected
2346 cmp -s $testroot/stdout.expected $testroot/stdout
2347 ret=$?
2348 if [ $ret -ne 0 ]; then
2349 diff -u $testroot/stdout.expected $testroot/stdout
2350 test_done "$testroot" "$ret"
2351 return 1
2354 echo "alpha" > $testroot/content.expected
2355 cmp -s $testroot/content.expected $testroot/wt/alpha
2356 ret=$?
2357 if [ $ret -ne 0 ]; then
2358 diff -u $testroot/content.expected $testroot/wt/alpha
2359 test_done "$testroot" "$ret"
2360 return 1
2363 if [ ! -x $testroot/wt/alpha ]; then
2364 echo "file alpha lost its executable bit" >&2
2365 test_done "$testroot" "1"
2366 return 1
2369 (cd $testroot/wt && got status > $testroot/stdout)
2371 echo -n > $testroot/stdout.expected
2372 cmp -s $testroot/stdout.expected $testroot/stdout
2373 ret=$?
2374 if [ $ret -ne 0 ]; then
2375 diff -u $testroot/stdout.expected $testroot/stdout
2376 test_done "$testroot" "$ret"
2377 return 1
2380 (cd $testroot/wt && got log -l1 | grep ' set executable bit on alpha' \
2381 > $testroot/stdout)
2383 echo ' set executable bit on alpha' > $testroot/stdout.expected
2384 cmp -s $testroot/stdout.expected $testroot/stdout
2385 ret=$?
2386 if [ $ret -ne 0 ]; then
2387 diff -u $testroot/stdout.expected $testroot/stdout
2388 test_done "$testroot" "$ret"
2389 return 1
2392 test_done "$testroot" "$ret"
2395 test_histedit_drop_only() {
2396 local testroot=`test_init histedit_drop_only`
2398 local orig_commit=`git_show_head $testroot/repo`
2399 local drop="-> drop commit:"
2400 local dropmsg="commit changes to drop"
2402 echo "modified alpha on master" > $testroot/repo/alpha
2403 (cd $testroot/repo && git rm -q beta)
2404 echo "new file on master" > $testroot/repo/epsilon/new
2405 (cd $testroot/repo && git add epsilon/new)
2407 git_commit $testroot/repo -m "$dropmsg 1"
2408 local drop_commit1=`git_show_head $testroot/repo`
2410 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2412 git_commit $testroot/repo -m "$dropmsg 2"
2413 local drop_commit2=`git_show_head $testroot/repo`
2415 echo "modified delta on master" > $testroot/repo/gamma/delta
2417 git_commit $testroot/repo -m "$dropmsg 3"
2418 local drop_commit3=`git_show_head $testroot/repo`
2420 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2421 ret=$?
2422 if [ $ret -ne 0 ]; then
2423 test_done "$testroot" "$ret"
2424 return 1
2427 (cd $testroot/wt && got histedit -d > $testroot/stdout)
2428 local new_commit1=`git_show_head $testroot/repo`
2430 local short_commit1=`trim_obj_id 28 $drop_commit1`
2431 local short_commit2=`trim_obj_id 28 $drop_commit2`
2432 local short_commit3=`trim_obj_id 28 $drop_commit3`
2434 echo "$short_commit1 $drop $dropmsg 1" > $testroot/stdout.expected
2435 echo "$short_commit2 $drop $dropmsg 2" >> $testroot/stdout.expected
2436 echo "$short_commit3 $drop $dropmsg 3" >> $testroot/stdout.expected
2437 echo "Switching work tree to refs/heads/master" \
2438 >> $testroot/stdout.expected
2440 cmp -s $testroot/stdout.expected $testroot/stdout
2441 ret=$?
2442 if [ $ret -ne 0 ]; then
2443 diff -u $testroot/stdout.expected $testroot/stdout
2444 test_done "$testroot" "$ret"
2445 return 1
2448 echo "alpha" > $testroot/content.expected
2449 cat $testroot/wt/alpha > $testroot/content
2450 cmp -s $testroot/content.expected $testroot/content
2451 ret=$?
2452 if [ $ret -ne 0 ]; then
2453 diff -u $testroot/content.expected $testroot/content
2454 test_done "$testroot" "$ret"
2455 return 1
2458 echo "zeta" > $testroot/content.expected
2459 cat $testroot/wt/epsilon/zeta > $testroot/content
2460 cmp -s $testroot/content.expected $testroot/content
2461 ret=$?
2462 if [ $ret -ne 0 ]; then
2463 diff -u $testroot/content.expected $testroot/content
2464 test_done "$testroot" "$ret"
2465 return 1
2468 echo "delta" > $testroot/content.expected
2469 cat $testroot/wt/gamma/delta > $testroot/content
2470 cmp -s $testroot/content.expected $testroot/content
2471 ret=$?
2472 if [ $ret -ne 0 ]; then
2473 diff -u $testroot/content.expected $testroot/content
2474 test_done "$testroot" "$ret"
2475 return 1
2478 if [ ! -e $testroot/wt/beta ]; then
2479 echo "removed file beta should be restored" >&2
2480 test_done "$testroot" "1"
2481 return 1
2484 if [ -e $testroot/wt/new ]; then
2485 echo "new file should no longer exist" >&2
2486 test_done "$testroot" "$ret"
2487 return 1
2490 (cd $testroot/wt && got status > $testroot/stdout)
2492 echo -n > $testroot/stdout.expected
2493 cmp -s $testroot/stdout.expected $testroot/stdout
2494 ret=$?
2495 if [ $ret -ne 0 ]; then
2496 diff -u $testroot/stdout.expected $testroot/stdout
2497 test_done "$testroot" "$ret"
2498 return 1
2501 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
2502 echo "commit $orig_commit (master)" > $testroot/stdout.expected
2503 cmp -s $testroot/stdout.expected $testroot/stdout
2504 ret=$?
2505 if [ $ret -ne 0 ]; then
2506 diff -u $testroot/stdout.expected $testroot/stdout
2508 test_done "$testroot" "$ret"
2511 test_parseargs "$@"
2512 run_test test_histedit_no_op
2513 run_test test_histedit_swap
2514 run_test test_histedit_drop
2515 run_test test_histedit_fold
2516 run_test test_histedit_edit
2517 run_test test_histedit_fold_last_commit
2518 run_test test_histedit_missing_commit
2519 run_test test_histedit_abort
2520 run_test test_histedit_path_prefix_drop
2521 run_test test_histedit_path_prefix_edit
2522 run_test test_histedit_outside_refs_heads
2523 run_test test_histedit_fold_last_commit_swap
2524 run_test test_histedit_split_commit
2525 run_test test_histedit_duplicate_commit_in_script
2526 run_test test_histedit_fold_add_delete
2527 run_test test_histedit_fold_delete_add
2528 run_test test_histedit_fold_only
2529 run_test test_histedit_fold_only_empty_logmsg
2530 run_test test_histedit_edit_only
2531 run_test test_histedit_prepend_line
2532 run_test test_histedit_mesg_invalid
2533 run_test test_histedit_resets_committer
2534 run_test test_histedit_umask
2535 run_test test_histedit_mesg_filemode_change
2536 run_test test_histedit_drop_only