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
1601 if [ ! -e $testroot/wt/alpha ]; then
1602 echo "file alpha is missing on disk" >&2
1603 test_done "$testroot" "1"
1604 return 1
1607 echo "modified alpha" > $testroot/content.expected
1608 cat $testroot/wt/alpha > $testroot/content
1609 cmp -s $testroot/content.expected $testroot/content
1610 ret=$?
1611 if [ $ret -ne 0 ]; then
1612 diff -u $testroot/content.expected $testroot/content
1613 test_done "$testroot" "$ret"
1614 return 1
1616 test_done "$testroot" "0"
1619 test_histedit_fold_only() {
1620 local testroot=`test_init histedit_fold_only`
1622 local orig_commit=`git_show_head $testroot/repo`
1624 echo "modified alpha on master" > $testroot/repo/alpha
1625 (cd $testroot/repo && git rm -q beta)
1626 echo "new file on master" > $testroot/repo/epsilon/new
1627 (cd $testroot/repo && git add epsilon/new)
1628 git_commit $testroot/repo -m "committing changes"
1629 local old_commit1=`git_show_head $testroot/repo`
1631 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1632 git_commit $testroot/repo -m "committing to zeta on master"
1633 local old_commit2=`git_show_head $testroot/repo`
1635 echo "modified delta on master" > $testroot/repo/gamma/delta
1636 git_commit $testroot/repo -m "committing to delta on master"
1637 local old_commit3=`git_show_head $testroot/repo`
1639 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1640 ret=$?
1641 if [ $ret -ne 0 ]; then
1642 test_done "$testroot" "$ret"
1643 return 1
1646 cat > $testroot/editor.sh <<EOF
1647 #!/bin/sh
1648 ed -s "\$1" <<-EOF
1649 ,s/.*/committing folded changes/
1651 EOF
1652 EOF
1653 chmod +x $testroot/editor.sh
1655 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1656 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1658 local new_commit1=`git_show_head $testroot/repo`
1660 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1661 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1662 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1663 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1664 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1666 echo "G alpha" > $testroot/stdout.expected
1667 echo "D beta" >> $testroot/stdout.expected
1668 echo "A epsilon/new" >> $testroot/stdout.expected
1669 echo "$short_old_commit1 -> fold commit: committing changes" \
1670 >> $testroot/stdout.expected
1671 echo "G epsilon/zeta" >> $testroot/stdout.expected
1672 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1673 echo "fold commit: committing to zeta on master" \
1674 >> $testroot/stdout.expected
1675 echo "G gamma/delta" >> $testroot/stdout.expected
1676 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1677 >> $testroot/stdout.expected
1678 echo "committing folded changes" >> $testroot/stdout.expected
1679 echo "Switching work tree to refs/heads/master" \
1680 >> $testroot/stdout.expected
1682 cmp -s $testroot/stdout.expected $testroot/stdout
1683 ret=$?
1684 if [ $ret -ne 0 ]; then
1685 diff -u $testroot/stdout.expected $testroot/stdout
1686 test_done "$testroot" "$ret"
1687 return 1
1690 echo "modified alpha on master" > $testroot/content.expected
1691 cat $testroot/wt/alpha > $testroot/content
1692 cmp -s $testroot/content.expected $testroot/content
1693 ret=$?
1694 if [ $ret -ne 0 ]; then
1695 diff -u $testroot/content.expected $testroot/content
1696 test_done "$testroot" "$ret"
1697 return 1
1700 if [ -e $testroot/wt/beta ]; then
1701 echo "removed file beta still exists on disk" >&2
1702 test_done "$testroot" "1"
1703 return 1
1706 echo "new file on master" > $testroot/content.expected
1707 cat $testroot/wt/epsilon/new > $testroot/content
1708 cmp -s $testroot/content.expected $testroot/content
1709 ret=$?
1710 if [ $ret -ne 0 ]; then
1711 diff -u $testroot/content.expected $testroot/content
1712 test_done "$testroot" "$ret"
1713 return 1
1716 (cd $testroot/wt && got status > $testroot/stdout)
1718 echo -n > $testroot/stdout.expected
1719 cmp -s $testroot/stdout.expected $testroot/stdout
1720 ret=$?
1721 if [ $ret -ne 0 ]; then
1722 diff -u $testroot/stdout.expected $testroot/stdout
1723 test_done "$testroot" "$ret"
1724 return 1
1727 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1728 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1729 echo "commit $orig_commit" >> $testroot/stdout.expected
1730 cmp -s $testroot/stdout.expected $testroot/stdout
1731 ret=$?
1732 if [ $ret -ne 0 ]; then
1733 diff -u $testroot/stdout.expected $testroot/stdout
1735 test_done "$testroot" "$ret"
1738 test_histedit_fold_only_empty_logmsg() {
1739 local testroot=`test_init histedit_fold_only_empty_logmsg`
1741 local orig_commit=`git_show_head $testroot/repo`
1743 echo "modified alpha on master" > $testroot/repo/alpha
1744 (cd $testroot/repo && git rm -q beta)
1745 echo "new file on master" > $testroot/repo/epsilon/new
1746 (cd $testroot/repo && git add epsilon/new)
1747 git_commit $testroot/repo -m "committing changes"
1748 local old_commit1=`git_show_head $testroot/repo`
1750 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1751 git_commit $testroot/repo -m "committing to zeta on master"
1752 local old_commit2=`git_show_head $testroot/repo`
1754 echo "modified delta on master" > $testroot/repo/gamma/delta
1755 git_commit $testroot/repo -m "committing to delta on master"
1756 local old_commit3=`git_show_head $testroot/repo`
1758 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1759 ret=$?
1760 if [ $ret -ne 0 ]; then
1761 test_done "$testroot" "$ret"
1762 return 1
1765 cat > $testroot/editor.sh <<EOF
1766 #!/bin/sh
1767 ed -s "\$1" <<-EOF
1770 EOF
1771 EOF
1772 chmod +x $testroot/editor.sh
1774 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1775 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1777 local new_commit1=`git_show_head $testroot/repo`
1779 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1780 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1781 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1782 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1783 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1784 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1786 echo "G alpha" > $testroot/stdout.expected
1787 echo "D beta" >> $testroot/stdout.expected
1788 echo "A epsilon/new" >> $testroot/stdout.expected
1789 echo "$short_old_commit1 -> fold commit: committing changes" \
1790 >> $testroot/stdout.expected
1791 echo "G epsilon/zeta" >> $testroot/stdout.expected
1792 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1793 echo "fold commit: committing to zeta on master" \
1794 >> $testroot/stdout.expected
1795 echo "G gamma/delta" >> $testroot/stdout.expected
1796 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1797 >> $testroot/stdout.expected
1798 echo "# log message of folded commit $very_short_old_commit1" \
1799 >> $testroot/stdout.expected
1800 echo "Switching work tree to refs/heads/master" \
1801 >> $testroot/stdout.expected
1803 cmp -s $testroot/stdout.expected $testroot/stdout
1804 ret=$?
1805 if [ $ret -ne 0 ]; then
1806 diff -u $testroot/stdout.expected $testroot/stdout
1807 test_done "$testroot" "$ret"
1808 return 1
1811 echo "modified alpha on master" > $testroot/content.expected
1812 cat $testroot/wt/alpha > $testroot/content
1813 cmp -s $testroot/content.expected $testroot/content
1814 ret=$?
1815 if [ $ret -ne 0 ]; then
1816 diff -u $testroot/content.expected $testroot/content
1817 test_done "$testroot" "$ret"
1818 return 1
1821 if [ -e $testroot/wt/beta ]; then
1822 echo "removed file beta still exists on disk" >&2
1823 test_done "$testroot" "1"
1824 return 1
1827 echo "new file on master" > $testroot/content.expected
1828 cat $testroot/wt/epsilon/new > $testroot/content
1829 cmp -s $testroot/content.expected $testroot/content
1830 ret=$?
1831 if [ $ret -ne 0 ]; then
1832 diff -u $testroot/content.expected $testroot/content
1833 test_done "$testroot" "$ret"
1834 return 1
1837 (cd $testroot/wt && got status > $testroot/stdout)
1839 echo -n > $testroot/stdout.expected
1840 cmp -s $testroot/stdout.expected $testroot/stdout
1841 ret=$?
1842 if [ $ret -ne 0 ]; then
1843 diff -u $testroot/stdout.expected $testroot/stdout
1844 test_done "$testroot" "$ret"
1845 return 1
1848 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1849 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1850 echo "commit $orig_commit" >> $testroot/stdout.expected
1851 cmp -s $testroot/stdout.expected $testroot/stdout
1852 ret=$?
1853 if [ $ret -ne 0 ]; then
1854 diff -u $testroot/stdout.expected $testroot/stdout
1856 test_done "$testroot" "$ret"
1859 test_histedit_edit_only() {
1860 local testroot=`test_init histedit_edit_only`
1862 local orig_commit=`git_show_head $testroot/repo`
1864 echo "modified alpha on master" > $testroot/repo/alpha
1865 (cd $testroot/repo && git rm -q beta)
1866 echo "new file on master" > $testroot/repo/epsilon/new
1867 (cd $testroot/repo && git add epsilon/new)
1868 git_commit $testroot/repo -m "committing changes"
1869 local old_commit1=`git_show_head $testroot/repo`
1871 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1872 git_commit $testroot/repo -m "committing to zeta on master"
1873 local old_commit2=`git_show_head $testroot/repo`
1875 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1876 ret=$?
1877 if [ $ret -ne 0 ]; then
1878 test_done "$testroot" "$ret"
1879 return 1
1882 (cd $testroot/wt && got histedit -e > $testroot/stdout)
1884 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1885 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1887 echo "G alpha" > $testroot/stdout.expected
1888 echo "D beta" >> $testroot/stdout.expected
1889 echo "A epsilon/new" >> $testroot/stdout.expected
1890 echo "Stopping histedit for amending commit $old_commit1" \
1891 >> $testroot/stdout.expected
1892 cmp -s $testroot/stdout.expected $testroot/stdout
1893 ret=$?
1894 if [ $ret -ne 0 ]; then
1895 diff -u $testroot/stdout.expected $testroot/stdout
1896 test_done "$testroot" "$ret"
1897 return 1
1900 echo "edited modified alpha on master" > $testroot/wt/alpha
1902 cat > $testroot/editor.sh <<EOF
1903 #!/bin/sh
1904 ed -s "\$1" <<-EOF
1905 ,s/.*/committing edited changes 1/
1907 EOF
1908 EOF
1909 chmod +x $testroot/editor.sh
1911 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1912 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1914 local new_commit1=$(cd $testroot/wt && got info | \
1915 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1916 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1918 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1919 > $testroot/stdout.expected
1920 echo "committing edited changes 1" >> $testroot/stdout.expected
1921 echo "G epsilon/zeta" >> $testroot/stdout.expected
1922 echo "Stopping histedit for amending commit $old_commit2" \
1923 >> $testroot/stdout.expected
1924 cmp -s $testroot/stdout.expected $testroot/stdout
1925 ret=$?
1926 if [ $ret -ne 0 ]; then
1927 diff -u $testroot/stdout.expected $testroot/stdout
1928 test_done "$testroot" "$ret"
1929 return 1
1932 echo "edited zeta on master" > $testroot/wt/epsilon/zeta
1934 cat > $testroot/editor.sh <<EOF
1935 #!/bin/sh
1936 ed -s "\$1" <<-EOF
1937 ,s/.*/committing edited changes 2/
1939 EOF
1940 EOF
1941 chmod +x $testroot/editor.sh
1943 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1944 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1946 local new_commit2=`git_show_head $testroot/repo`
1947 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1949 echo -n "$short_old_commit2 -> $short_new_commit2: " \
1950 > $testroot/stdout.expected
1951 echo "committing edited changes 2" >> $testroot/stdout.expected
1952 echo "Switching work tree to refs/heads/master" \
1953 >> $testroot/stdout.expected
1955 cmp -s $testroot/stdout.expected $testroot/stdout
1956 ret=$?
1957 if [ $ret -ne 0 ]; then
1958 diff -u $testroot/stdout.expected $testroot/stdout
1959 test_done "$testroot" "$ret"
1960 return 1
1963 echo "edited modified alpha on master" > $testroot/content.expected
1964 cat $testroot/wt/alpha > $testroot/content
1965 cmp -s $testroot/content.expected $testroot/content
1966 ret=$?
1967 if [ $ret -ne 0 ]; then
1968 diff -u $testroot/content.expected $testroot/content
1969 test_done "$testroot" "$ret"
1970 return 1
1973 if [ -e $testroot/wt/beta ]; then
1974 echo "removed file beta still exists on disk" >&2
1975 test_done "$testroot" "1"
1976 return 1
1979 echo "new file on master" > $testroot/content.expected
1980 cat $testroot/wt/epsilon/new > $testroot/content
1981 cmp -s $testroot/content.expected $testroot/content
1982 ret=$?
1983 if [ $ret -ne 0 ]; then
1984 diff -u $testroot/content.expected $testroot/content
1985 test_done "$testroot" "$ret"
1986 return 1
1989 (cd $testroot/wt && got status > $testroot/stdout)
1991 echo -n > $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
1996 test_done "$testroot" "$ret"
1997 return 1
2000 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
2001 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
2002 echo "commit $new_commit1" >> $testroot/stdout.expected
2003 echo "commit $orig_commit" >> $testroot/stdout.expected
2004 cmp -s $testroot/stdout.expected $testroot/stdout
2005 ret=$?
2006 if [ $ret -ne 0 ]; then
2007 diff -u $testroot/stdout.expected $testroot/stdout
2009 test_done "$testroot" "$ret"
2012 test_histedit_prepend_line() {
2013 local testroot=`test_init histedit_prepend_line`
2014 local orig_commit=`git_show_head $testroot/repo`
2016 got checkout $testroot/repo $testroot/wt > /dev/null
2018 ed -s "$testroot/wt/alpha" <<EOF
2020 first line
2023 EOF
2025 cp $testroot/wt/alpha $testroot/content.expected
2027 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2028 alpha > /dev/null)
2029 ret=$?
2030 if [ "$?" != 0 ]; then
2031 echo "got commit failed unexpectedly" >&2
2032 test_done "$testroot" "$ret"
2033 return 1
2036 local top_commit=`git_show_head $testroot/repo`
2037 echo "pick $top_commit" > "$testroot/histedit-script"
2039 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2040 ret=$?
2041 if [ "$?" != 0 ]; then
2042 echo "got update failed unexpectedly" >&2
2043 test_done "$testroot" "$ret"
2044 return 1
2047 (cd $testroot/wt && got histedit -F "$testroot/histedit-script" \
2048 > /dev/null)
2049 ret=$?
2050 if [ "$?" != 0 ]; then
2051 echo "got histedit failed unexpectedly" >&2
2052 test_done "$testroot" "$ret"
2053 return 1
2056 cp $testroot/wt/alpha $testroot/content
2057 cmp -s $testroot/content.expected $testroot/content
2058 ret=$?
2059 if [ $ret -ne 0 ]; then
2060 diff -u $testroot/content.expected $testroot/content
2061 test_done "$testroot" "$ret"
2062 return 1
2065 test_done "$testroot" $ret
2068 test_histedit_mesg_invalid() {
2069 local testroot=`test_init mesg_invalid`
2071 local orig_commit=`git_show_head $testroot/repo`
2073 echo "modified alpha on master" > $testroot/repo/alpha
2074 (cd $testroot/repo && git rm -q beta)
2075 echo "new file on master" > $testroot/repo/epsilon/new
2076 (cd $testroot/repo && git add epsilon/new)
2077 git_commit $testroot/repo -m 'committing changes'
2078 local old_commit1=`git_show_head $testroot/repo`
2080 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2081 git_commit $testroot/repo -m 'committing to zeto on master'
2082 local old_commit2=`git_show_head $testroot/repo`
2084 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2085 ret=$?
2086 if [ $ret -ne 0 ]; then
2087 test_done "$testroot" $ret
2088 return 1
2091 # try with a leading mesg
2093 echo "mesg something something" > $testroot/histedit-script
2094 echo "pick $old_commit1" >> $testroot/histedit-script
2095 echo "pick $old_commit2" >> $testroot/histedit-script
2097 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2098 > $testroot/stdout 2> $testroot/stderr)
2099 ret=$?
2100 if [ $ret -eq 0 ]; then
2101 echo "histedit succeeded unexpectedly" >&2
2102 test_done "$testroot" 1
2103 return 1
2106 echo "got: bad histedit command" > $testroot/stderr.expected
2107 cmp -s $testroot/stderr.expected $testroot/stderr
2108 ret=$?
2109 if [ $ret -ne 0 ]; then
2110 diff -u $testroot/stderr.expected $testroot/stderr
2111 test_done "$testroot" $ret
2112 return 1
2115 # try again with mesg -> mesg
2117 echo "pick $old_commit1" > $testroot/histedit-script
2118 echo "mesg something something" >> $testroot/histedit-script
2119 echo "mesg something something else" >> $testroot/histedit-script
2120 echo "pick $old_commit2" >> $testroot/histedit-script
2122 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2123 > $testroot/stdout 2> $testroot/stderr)
2124 ret=$?
2125 if [ $ret -eq 0 ]; then
2126 echo "histedit succeeded unexpectedly" >&2
2127 test_done "$testroot" 1
2128 return 1
2131 echo "got: bad histedit command" > $testroot/stderr.expected
2132 cmp -s $testroot/stderr.expected $testroot/stderr
2133 ret=$?
2134 if [ $ret -ne 0 ]; then
2135 diff -u $testroot/stderr.expected $testroot/stderr
2136 test_done "$testroot" $ret
2137 return 1
2140 # try again with drop -> mesg
2142 echo "drop $old_commit1" > $testroot/histedit-script
2143 echo "mesg something something" >> $testroot/histedit-script
2144 echo "pick $old_commit2" >> $testroot/histedit-script
2146 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2147 > $testroot/stdout 2> $testroot/stderr)
2148 ret=$?
2149 if [ $ret -eq 0 ]; then
2150 echo "histedit succeeded unexpectedly" >&2
2151 test_done "$testroot" 1
2152 return 1
2155 echo "got: bad histedit command" > $testroot/stderr.expected
2156 cmp -s $testroot/stderr.expected $testroot/stderr
2157 ret=$?
2158 if [ $ret -ne 0 ]; then
2159 diff -u $testroot/stderr.expected $testroot/stderr
2160 test_done "$testroot" $ret
2161 return 1
2164 # try again with fold -> mesg
2166 echo "fold $old_commit1" > $testroot/histedit-script
2167 echo "mesg something something" >> $testroot/histedit-script
2168 echo "pick $old_commit2" >> $testroot/histedit-script
2170 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2171 > $testroot/stdout 2> $testroot/stderr)
2172 ret=$?
2173 if [ $ret -eq 0 ]; then
2174 echo "histedit succeeded unexpectedly" >&2
2175 test_done "$testroot" 1
2176 return 1
2179 echo "got: bad histedit command" > $testroot/stderr.expected
2180 cmp -s $testroot/stderr.expected $testroot/stderr
2181 ret=$?
2182 if [ $ret -ne 0 ]; then
2183 diff -u $testroot/stderr.expected $testroot/stderr
2185 test_done "$testroot" $ret
2188 test_histedit_resets_committer() {
2189 local testroot=`test_init histedit_resets_committer`
2190 local orig_commit=`git_show_head $testroot/repo`
2191 local committer="Flan Luck <flan_luck@openbsd.org>"
2193 got checkout $testroot/repo $testroot/wt > /dev/null
2195 echo "modified alpha" > $testroot/wt/alpha
2197 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2198 alpha > /dev/null)
2199 ret=$?
2200 if [ "$?" != 0 ]; then
2201 echo "got commit failed unexpectedly" >&2
2202 test_done "$testroot" "$ret"
2203 return 1
2206 local top_commit=`git_show_head $testroot/repo`
2207 echo "pick $top_commit" > "$testroot/histedit-script"
2209 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2210 ret=$?
2211 if [ "$?" != 0 ]; then
2212 echo "got update failed unexpectedly" >&2
2213 test_done "$testroot" "$ret"
2214 return 1
2217 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
2218 got histedit -F "$testroot/histedit-script" > /dev/null)
2219 ret=$?
2220 if [ "$?" != 0 ]; then
2221 echo "got histedit failed unexpectedly" >&2
2222 test_done "$testroot" "$ret"
2223 return 1
2225 local edited_commit=`git_show_head $testroot/repo`
2227 # Original commit only had one author
2228 (cd $testroot/repo && got log -l1 -c $top_commit | \
2229 egrep '^(from|via):' > $testroot/stdout)
2230 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2231 cmp -s $testroot/stdout.expected $testroot/stdout
2232 ret=$?
2233 if [ $ret -ne 0 ]; then
2234 diff -u $testroot/stdout.expected $testroot/stdout
2235 test_done "$testroot" "$ret"
2236 return 1
2239 # Edited commit should have new committer name added
2240 (cd $testroot/repo && got log -l1 -c $edited_commit | \
2241 egrep '^(from|via):' > $testroot/stdout)
2242 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2243 echo "via: $committer" >> $testroot/stdout.expected
2245 cmp -s $testroot/stdout.expected $testroot/stdout
2246 ret=$?
2247 if [ $ret -ne 0 ]; then
2248 diff -u $testroot/stdout.expected $testroot/stdout
2250 test_done "$testroot" "$ret"
2253 test_histedit_umask() {
2254 local testroot=`test_init histedit_umask`
2255 local orig_commit=`git_show_head "$testroot/repo"`
2257 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
2259 echo "modified alpha" > $testroot/wt/alpha
2260 (cd "$testroot/wt" && got commit -m 'edit #1') >/dev/null
2261 local commit1=`git_show_head "$testroot/repo"`
2263 echo "modified again" > $testroot/wt/alpha
2264 (cd "$testroot/wt" && got commit -m 'edit #2') >/dev/null
2265 local commit2=`git_show_head "$testroot/repo"`
2267 echo "modified again!" > $testroot/wt/alpha
2268 echo "modify beta too!" > $testroot/wt/beta
2269 (cd "$testroot/wt" && got commit -m 'edit #3') >/dev/null
2270 local commit3=`git_show_head "$testroot/repo"`
2272 (cd "$testroot/wt" && got update -c "$orig_commit") >/dev/null
2273 ret=$?
2274 if [ $ret -ne 0 ]; then
2275 echo "update to $orig_commit failed!" >&2
2276 test_done "$testroot" 1
2277 return 1
2280 echo fold $commit1 >$testroot/histedit-script
2281 echo fold $commit2 >>$testroot/histedit-script
2282 echo pick $commit3 >>$testroot/histedit-script
2283 echo mesg folding changes >>$testroot/histedit-script
2285 # using a subshell to avoid clobbering global umask
2286 (umask 077 && cd "$testroot/wt" && \
2287 got histedit -F "$testroot/histedit-script") >/dev/null
2288 ret=$?
2290 if [ $ret -ne 0 ]; then
2291 echo "histedit operation failed" >&2
2292 test_done "$testroot" $ret
2293 return 1
2296 for f in alpha beta; do
2297 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
2298 if [ $? -ne 0 ]; then
2299 echo "$f is not 0600 after histedi" >&2
2300 ls -l "$testroot/wt/$f" >&2
2301 test_done "$testroot" 1
2302 return 1
2304 done
2306 test_done "$testroot" 0
2309 test_histedit_mesg_filemode_change() {
2310 local testroot=`test_init histedit_mode_change`
2312 local orig_commit=`git_show_head $testroot/repo`
2313 local orig_author_time=`git_show_author_time $testroot/repo`
2315 chmod +x $testroot/repo/alpha
2316 git_commit $testroot/repo -m "set x bit on alpha"
2317 local old_commit1=`git_show_head $testroot/repo`
2318 local old_author_time1=`git_show_author_time $testroot/repo`
2320 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2321 ret=$?
2322 if [ $ret -ne 0 ]; then
2323 test_done "$testroot" "$ret"
2324 return 1
2327 if [ -x $testroot/wt/alpha ]; then
2328 echo "file alpha has unexpected executable bit" >&2
2329 test_done "$testroot" "1"
2330 return 1
2333 cat > $testroot/editor.sh <<EOF
2334 #!/bin/sh
2335 ed -s "\$1" <<-EOF
2336 ,s/ x bit / executable bit /
2338 EOF
2339 EOF
2341 chmod +x $testroot/editor.sh
2343 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
2344 got histedit -m > $testroot/stdout)
2346 local new_commit1=`git_show_head $testroot/repo`
2347 local new_author_time1=`git_show_author_time $testroot/repo`
2349 local short_old_commit1=`trim_obj_id 28 $old_commit1`
2350 local short_new_commit1=`trim_obj_id 28 $new_commit1`
2352 echo "G alpha" > $testroot/stdout.expected
2353 echo "$short_old_commit1 -> $short_new_commit1: set executable bit on alpha" \
2354 >> $testroot/stdout.expected
2355 echo "Switching work tree to refs/heads/master" \
2356 >> $testroot/stdout.expected
2358 cmp -s $testroot/stdout.expected $testroot/stdout
2359 ret=$?
2360 if [ $ret -ne 0 ]; then
2361 diff -u $testroot/stdout.expected $testroot/stdout
2362 test_done "$testroot" "$ret"
2363 return 1
2366 echo "alpha" > $testroot/content.expected
2367 cmp -s $testroot/content.expected $testroot/wt/alpha
2368 ret=$?
2369 if [ $ret -ne 0 ]; then
2370 diff -u $testroot/content.expected $testroot/wt/alpha
2371 test_done "$testroot" "$ret"
2372 return 1
2375 if [ ! -x $testroot/wt/alpha ]; then
2376 echo "file alpha lost its executable bit" >&2
2377 test_done "$testroot" "1"
2378 return 1
2381 (cd $testroot/wt && got status > $testroot/stdout)
2383 echo -n > $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 (cd $testroot/wt && got log -l1 | grep ' set executable bit on alpha' \
2393 > $testroot/stdout)
2395 echo ' set executable bit on alpha' > $testroot/stdout.expected
2396 cmp -s $testroot/stdout.expected $testroot/stdout
2397 ret=$?
2398 if [ $ret -ne 0 ]; then
2399 diff -u $testroot/stdout.expected $testroot/stdout
2400 test_done "$testroot" "$ret"
2401 return 1
2404 test_done "$testroot" "$ret"
2407 test_histedit_drop_only() {
2408 local testroot=`test_init histedit_drop_only`
2410 local orig_commit=`git_show_head $testroot/repo`
2411 local drop="-> drop commit:"
2412 local dropmsg="commit changes to drop"
2414 echo "modified alpha on master" > $testroot/repo/alpha
2415 (cd $testroot/repo && git rm -q beta)
2416 echo "new file on master" > $testroot/repo/epsilon/new
2417 (cd $testroot/repo && git add epsilon/new)
2419 git_commit $testroot/repo -m "$dropmsg 1"
2420 local drop_commit1=`git_show_head $testroot/repo`
2422 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2424 git_commit $testroot/repo -m "$dropmsg 2"
2425 local drop_commit2=`git_show_head $testroot/repo`
2427 echo "modified delta on master" > $testroot/repo/gamma/delta
2429 git_commit $testroot/repo -m "$dropmsg 3"
2430 local drop_commit3=`git_show_head $testroot/repo`
2432 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2433 ret=$?
2434 if [ $ret -ne 0 ]; then
2435 test_done "$testroot" "$ret"
2436 return 1
2439 (cd $testroot/wt && got histedit -d > $testroot/stdout)
2440 local new_commit1=`git_show_head $testroot/repo`
2442 local short_commit1=`trim_obj_id 28 $drop_commit1`
2443 local short_commit2=`trim_obj_id 28 $drop_commit2`
2444 local short_commit3=`trim_obj_id 28 $drop_commit3`
2446 echo "$short_commit1 $drop $dropmsg 1" > $testroot/stdout.expected
2447 echo "$short_commit2 $drop $dropmsg 2" >> $testroot/stdout.expected
2448 echo "$short_commit3 $drop $dropmsg 3" >> $testroot/stdout.expected
2449 echo "Switching work tree to refs/heads/master" \
2450 >> $testroot/stdout.expected
2452 cmp -s $testroot/stdout.expected $testroot/stdout
2453 ret=$?
2454 if [ $ret -ne 0 ]; then
2455 diff -u $testroot/stdout.expected $testroot/stdout
2456 test_done "$testroot" "$ret"
2457 return 1
2460 echo "alpha" > $testroot/content.expected
2461 cat $testroot/wt/alpha > $testroot/content
2462 cmp -s $testroot/content.expected $testroot/content
2463 ret=$?
2464 if [ $ret -ne 0 ]; then
2465 diff -u $testroot/content.expected $testroot/content
2466 test_done "$testroot" "$ret"
2467 return 1
2470 echo "zeta" > $testroot/content.expected
2471 cat $testroot/wt/epsilon/zeta > $testroot/content
2472 cmp -s $testroot/content.expected $testroot/content
2473 ret=$?
2474 if [ $ret -ne 0 ]; then
2475 diff -u $testroot/content.expected $testroot/content
2476 test_done "$testroot" "$ret"
2477 return 1
2480 echo "delta" > $testroot/content.expected
2481 cat $testroot/wt/gamma/delta > $testroot/content
2482 cmp -s $testroot/content.expected $testroot/content
2483 ret=$?
2484 if [ $ret -ne 0 ]; then
2485 diff -u $testroot/content.expected $testroot/content
2486 test_done "$testroot" "$ret"
2487 return 1
2490 if [ ! -e $testroot/wt/beta ]; then
2491 echo "removed file beta should be restored" >&2
2492 test_done "$testroot" "1"
2493 return 1
2496 if [ -e $testroot/wt/new ]; then
2497 echo "new file should no longer exist" >&2
2498 test_done "$testroot" "$ret"
2499 return 1
2502 (cd $testroot/wt && got status > $testroot/stdout)
2504 echo -n > $testroot/stdout.expected
2505 cmp -s $testroot/stdout.expected $testroot/stdout
2506 ret=$?
2507 if [ $ret -ne 0 ]; then
2508 diff -u $testroot/stdout.expected $testroot/stdout
2509 test_done "$testroot" "$ret"
2510 return 1
2513 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
2514 echo "commit $orig_commit (master)" > $testroot/stdout.expected
2515 cmp -s $testroot/stdout.expected $testroot/stdout
2516 ret=$?
2517 if [ $ret -ne 0 ]; then
2518 diff -u $testroot/stdout.expected $testroot/stdout
2520 test_done "$testroot" "$ret"
2523 test_parseargs "$@"
2524 run_test test_histedit_no_op
2525 run_test test_histedit_swap
2526 run_test test_histedit_drop
2527 run_test test_histedit_fold
2528 run_test test_histedit_edit
2529 run_test test_histedit_fold_last_commit
2530 run_test test_histedit_missing_commit
2531 run_test test_histedit_abort
2532 run_test test_histedit_path_prefix_drop
2533 run_test test_histedit_path_prefix_edit
2534 run_test test_histedit_outside_refs_heads
2535 run_test test_histedit_fold_last_commit_swap
2536 run_test test_histedit_split_commit
2537 run_test test_histedit_duplicate_commit_in_script
2538 run_test test_histedit_fold_add_delete
2539 run_test test_histedit_fold_delete_add
2540 run_test test_histedit_fold_only
2541 run_test test_histedit_fold_only_empty_logmsg
2542 run_test test_histedit_edit_only
2543 run_test test_histedit_prepend_line
2544 run_test test_histedit_mesg_invalid
2545 run_test test_histedit_resets_committer
2546 run_test test_histedit_umask
2547 run_test test_histedit_mesg_filemode_change
2548 run_test test_histedit_drop_only