Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_histedit_no_op() {
20 local testroot=`test_init histedit_no_op`
22 local orig_commit=`git_show_head $testroot/repo`
23 local orig_author_time=`git_show_author_time $testroot/repo`
25 echo "modified alpha on master" > $testroot/repo/alpha
26 (cd $testroot/repo && git rm -q beta)
27 echo "new file on master" > $testroot/repo/epsilon/new
28 (cd $testroot/repo && git add epsilon/new)
29 git_commit $testroot/repo -m "committing changes"
30 local old_commit1=`git_show_head $testroot/repo`
31 local old_author_time1=`git_show_author_time $testroot/repo`
33 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
34 git_commit $testroot/repo -m "committing to zeta on master"
35 local old_commit2=`git_show_head $testroot/repo`
36 local old_author_time2=`git_show_author_time $testroot/repo`
38 got diff -r $testroot/repo $orig_commit $old_commit2 \
39 > $testroot/diff.expected
41 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
42 ret=$?
43 if [ $ret -ne 0 ]; then
44 test_done "$testroot" "$ret"
45 return 1
46 fi
48 echo "pick $old_commit1" > $testroot/histedit-script
49 echo "pick $old_commit2" >> $testroot/histedit-script
51 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
52 > $testroot/stdout)
54 local new_commit1=`git_show_parent_commit $testroot/repo`
55 local new_commit2=`git_show_head $testroot/repo`
56 local new_author_time2=`git_show_author_time $testroot/repo`
58 local short_old_commit1=`trim_obj_id 28 $old_commit1`
59 local short_old_commit2=`trim_obj_id 28 $old_commit2`
60 local short_new_commit1=`trim_obj_id 28 $new_commit1`
61 local short_new_commit2=`trim_obj_id 28 $new_commit2`
63 echo "G alpha" > $testroot/stdout.expected
64 echo "D beta" >> $testroot/stdout.expected
65 echo "A epsilon/new" >> $testroot/stdout.expected
66 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
67 >> $testroot/stdout.expected
68 echo "G epsilon/zeta" >> $testroot/stdout.expected
69 echo -n "$short_old_commit2 -> $short_new_commit2: " \
70 >> $testroot/stdout.expected
71 echo "committing to zeta on master" >> $testroot/stdout.expected
72 echo "Switching work tree to refs/heads/master" \
73 >> $testroot/stdout.expected
75 cmp -s $testroot/stdout.expected $testroot/stdout
76 ret=$?
77 if [ $ret -ne 0 ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
80 return 1
81 fi
83 echo "modified alpha on master" > $testroot/content.expected
84 cat $testroot/wt/alpha > $testroot/content
85 cmp -s $testroot/content.expected $testroot/content
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 diff -u $testroot/content.expected $testroot/content
89 test_done "$testroot" "$ret"
90 return 1
91 fi
93 if [ -e $testroot/wt/beta ]; then
94 echo "removed file beta still exists on disk" >&2
95 test_done "$testroot" "1"
96 return 1
97 fi
99 echo "new file on master" > $testroot/content.expected
100 cat $testroot/wt/epsilon/new > $testroot/content
101 cmp -s $testroot/content.expected $testroot/content
102 ret=$?
103 if [ $ret -ne 0 ]; then
104 diff -u $testroot/content.expected $testroot/content
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 (cd $testroot/wt && got status > $testroot/stdout)
111 echo -n > $testroot/stdout.expected
112 cmp -s $testroot/stdout.expected $testroot/stdout
113 ret=$?
114 if [ $ret -ne 0 ]; then
115 diff -u $testroot/stdout.expected $testroot/stdout
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
121 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
122 echo "commit $new_commit1" >> $testroot/stdout.expected
123 echo "commit $orig_commit" >> $testroot/stdout.expected
124 cmp -s $testroot/stdout.expected $testroot/stdout
125 ret=$?
126 if [ $ret -ne 0 ]; then
127 diff -u $testroot/stdout.expected $testroot/stdout
128 test_done "$testroot" "$ret"
129 return 1
130 fi
132 got diff -r $testroot/repo $orig_commit $new_commit2 \
133 > $testroot/diff
134 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
135 cmp -s $testroot/diff.expected $testroot/diff
136 ret=$?
137 if [ $ret -ne 0 ]; then
138 diff -u $testroot/diff.expected $testroot/diff
139 test_done "$testroot" "$ret"
140 return 1
141 fi
143 (cd $testroot/wt && got update > $testroot/stdout)
145 echo 'Already up-to-date' > $testroot/stdout.expected
146 cmp -s $testroot/stdout.expected $testroot/stdout
147 ret=$?
148 if [ $ret -ne 0 ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
150 test_done "$testroot" "$ret"
151 return 1
152 fi
154 # We should have a backup of old commits
155 (cd $testroot/repo && got histedit -l > $testroot/stdout)
156 d_orig1=`date -u -r $old_author_time1 +"%G-%m-%d"`
157 d_orig2=`date -u -r $old_author_time2 +"%a %b %e %X %Y UTC"`
158 d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
159 d_orig=`date -u -r $orig_author_time +"%G-%m-%d"`
160 cat > $testroot/stdout.expected <<EOF
161 -----------------------------------------------
162 commit $old_commit2 (formerly master)
163 from: $GOT_AUTHOR
164 date: $d_orig2
166 committing to zeta on master
168 has become commit $new_commit2 (master)
169 $d_new2 $GOT_AUTHOR_11 committing to zeta on master
170 EOF
172 local is_forked=true d_fork fork_commit fork_commit_msg
174 if [ "$old_commit1" = "$new_commit1" ]; then
175 if [ "$old_commit2" = "$new_commit2" ]; then
176 is_forked=false
177 else
178 d_fork=$d_orig1
179 fork_commit=$new_commit1
180 fork_commit_msg="committing changes"
181 fi
182 else
183 d_fork=$d_orig
184 fork_commit=$orig_commit
185 fork_commit_msg="adding the test tree"
186 fi
188 $is_forked && cat >> $testroot/stdout.expected <<EOF
189 history forked at $fork_commit
190 $d_fork $GOT_AUTHOR_11 $fork_commit_msg
191 EOF
193 cmp -s $testroot/stdout.expected $testroot/stdout
194 ret=$?
195 if [ $ret -ne 0 ]; then
196 diff -u $testroot/stdout.expected $testroot/stdout
197 test_done "$testroot" "$ret"
198 return 1
199 fi
201 (cd $testroot/repo && got histedit -X master \
202 > $testroot/stdout 2> $testroot/stderr)
203 echo -n "Deleted refs/got/backup/histedit/master/$new_commit2: " \
204 > $testroot/stdout.expected
205 echo "$old_commit2" >> $testroot/stdout.expected
206 echo -n > $testroot/stderr.expected
207 cmp -s $testroot/stdout.expected $testroot/stdout
208 ret=$?
209 if [ $ret -ne 0 ]; then
210 diff -u $testroot/stdout.expected $testroot/stdout
211 test_done "$testroot" "$ret"
212 return 1
213 fi
214 cmp -s $testroot/stderr.expected $testroot/stderr
215 ret=$?
216 if [ $ret -ne 0 ]; then
217 diff -u $testroot/stderr.expected $testroot/stderr
218 test_done "$testroot" "$ret"
219 return 1
220 fi
222 (cd $testroot/repo && got histedit -l > $testroot/stdout)
223 echo -n > $testroot/stdout.expected
224 cmp -s $testroot/stdout.expected $testroot/stdout
225 ret=$?
226 if [ $ret -ne 0 ]; then
227 diff -u $testroot/stdout.expected $testroot/stdout
228 fi
229 test_done "$testroot" "$ret"
232 test_histedit_swap() {
233 local testroot=`test_init histedit_swap`
235 local orig_commit=`git_show_head $testroot/repo`
237 echo "modified alpha on master" > $testroot/repo/alpha
238 (cd $testroot/repo && git rm -q beta)
239 echo "new file on master" > $testroot/repo/epsilon/new
240 (cd $testroot/repo && git add epsilon/new)
241 git_commit $testroot/repo -m "committing changes"
242 local old_commit1=`git_show_head $testroot/repo`
244 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
245 git_commit $testroot/repo -m "committing to zeta on master"
246 local old_commit2=`git_show_head $testroot/repo`
248 got diff -r $testroot/repo $orig_commit $old_commit2 \
249 > $testroot/diff.expected
251 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
252 ret=$?
253 if [ $ret -ne 0 ]; then
254 test_done "$testroot" "$ret"
255 return 1
256 fi
258 echo "pick $old_commit2" > $testroot/histedit-script
259 echo "pick $old_commit1" >> $testroot/histedit-script
261 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
262 > $testroot/stdout)
264 local new_commit2=`git_show_parent_commit $testroot/repo`
265 local new_commit1=`git_show_head $testroot/repo`
267 local short_old_commit1=`trim_obj_id 28 $old_commit1`
268 local short_old_commit2=`trim_obj_id 28 $old_commit2`
269 local short_new_commit1=`trim_obj_id 28 $new_commit1`
270 local short_new_commit2=`trim_obj_id 28 $new_commit2`
272 echo "G epsilon/zeta" > $testroot/stdout.expected
273 echo -n "$short_old_commit2 -> $short_new_commit2: " \
274 >> $testroot/stdout.expected
275 echo "committing to zeta on master" >> $testroot/stdout.expected
276 echo "G alpha" >> $testroot/stdout.expected
277 echo "D beta" >> $testroot/stdout.expected
278 echo "A epsilon/new" >> $testroot/stdout.expected
279 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
280 >> $testroot/stdout.expected
281 echo "Switching work tree to refs/heads/master" \
282 >> $testroot/stdout.expected
284 cmp -s $testroot/stdout.expected $testroot/stdout
285 ret=$?
286 if [ $ret -ne 0 ]; then
287 diff -u $testroot/stdout.expected $testroot/stdout
288 test_done "$testroot" "$ret"
289 return 1
290 fi
292 echo "modified alpha on master" > $testroot/content.expected
293 cat $testroot/wt/alpha > $testroot/content
294 cmp -s $testroot/content.expected $testroot/content
295 ret=$?
296 if [ $ret -ne 0 ]; then
297 diff -u $testroot/content.expected $testroot/content
298 test_done "$testroot" "$ret"
299 return 1
300 fi
302 if [ -e $testroot/wt/beta ]; then
303 echo "removed file beta still exists on disk" >&2
304 test_done "$testroot" "1"
305 return 1
306 fi
308 echo "new file on master" > $testroot/content.expected
309 cat $testroot/wt/epsilon/new > $testroot/content
310 cmp -s $testroot/content.expected $testroot/content
311 ret=$?
312 if [ $ret -ne 0 ]; then
313 diff -u $testroot/content.expected $testroot/content
314 test_done "$testroot" "$ret"
315 return 1
316 fi
318 (cd $testroot/wt && got status > $testroot/stdout)
320 echo -n > $testroot/stdout.expected
321 cmp -s $testroot/stdout.expected $testroot/stdout
322 ret=$?
323 if [ $ret -ne 0 ]; then
324 diff -u $testroot/stdout.expected $testroot/stdout
325 test_done "$testroot" "$ret"
326 return 1
327 fi
329 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
330 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
331 echo "commit $new_commit2" >> $testroot/stdout.expected
332 echo "commit $orig_commit" >> $testroot/stdout.expected
333 cmp -s $testroot/stdout.expected $testroot/stdout
334 ret=$?
335 if [ $ret -ne 0 ]; then
336 diff -u $testroot/stdout.expected $testroot/stdout
337 test_done "$testroot" "$ret"
338 return 1
339 fi
341 got diff -r $testroot/repo $orig_commit $new_commit1 \
342 > $testroot/diff
343 sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
344 cmp -s $testroot/diff.expected $testroot/diff
345 ret=$?
346 if [ $ret -ne 0 ]; then
347 diff -u $testroot/diff.expected $testroot/diff
348 fi
349 test_done "$testroot" "$ret"
352 test_histedit_drop() {
353 local testroot=`test_init histedit_drop`
354 local orig_commit=`git_show_head $testroot/repo`
356 echo "modified alpha on master" > $testroot/repo/alpha
357 (cd $testroot/repo && git rm -q beta)
358 echo "new file on master" > $testroot/repo/epsilon/new
359 (cd $testroot/repo && git add epsilon/new)
360 git_commit $testroot/repo -m "committing changes"
361 local old_commit1=`git_show_head $testroot/repo`
363 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
364 git_commit $testroot/repo -m "committing to zeta on master"
365 local old_commit2=`git_show_head $testroot/repo`
367 got diff -r $testroot/repo $old_commit1 $old_commit2 \
368 > $testroot/diff.expected
370 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
371 ret=$?
372 if [ $ret -ne 0 ]; then
373 test_done "$testroot" "$ret"
374 return 1
375 fi
377 echo "drop $old_commit1" > $testroot/histedit-script
378 echo "pick $old_commit2" >> $testroot/histedit-script
380 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
381 > $testroot/stdout)
383 local new_commit2=`git_show_head $testroot/repo`
385 local short_old_commit1=`trim_obj_id 28 $old_commit1`
386 local short_old_commit2=`trim_obj_id 28 $old_commit2`
387 local short_new_commit2=`trim_obj_id 28 $new_commit2`
389 echo "$short_old_commit1 -> drop commit: committing changes" \
390 > $testroot/stdout.expected
391 echo "G epsilon/zeta" >> $testroot/stdout.expected
392 echo -n "$short_old_commit2 -> $short_new_commit2: " \
393 >> $testroot/stdout.expected
394 echo "committing to zeta on master" >> $testroot/stdout.expected
395 echo "Switching work tree to refs/heads/master" \
396 >> $testroot/stdout.expected
398 cmp -s $testroot/stdout.expected $testroot/stdout
399 ret=$?
400 if [ $ret -ne 0 ]; then
401 diff -u $testroot/stdout.expected $testroot/stdout
402 test_done "$testroot" "$ret"
403 return 1
404 fi
406 for f in alpha beta; do
407 echo "$f" > $testroot/content.expected
408 cat $testroot/wt/$f > $testroot/content
409 cmp -s $testroot/content.expected $testroot/content
410 ret=$?
411 if [ $ret -ne 0 ]; then
412 diff -u $testroot/content.expected $testroot/content
413 test_done "$testroot" "$ret"
414 return 1
415 fi
416 done
418 if [ -e $testroot/wt/new ]; then
419 echo "file new exists on disk but should not" >&2
420 test_done "$testroot" "1"
421 return 1
422 fi
424 (cd $testroot/wt && got status > $testroot/stdout)
426 echo -n > $testroot/stdout.expected
427 cmp -s $testroot/stdout.expected $testroot/stdout
428 ret=$?
429 if [ $ret -ne 0 ]; then
430 diff -u $testroot/stdout.expected $testroot/stdout
431 test_done "$testroot" "$ret"
432 return 1
433 fi
435 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
436 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
437 echo "commit $orig_commit" >> $testroot/stdout.expected
438 cmp -s $testroot/stdout.expected $testroot/stdout
439 ret=$?
440 if [ $ret -ne 0 ]; then
441 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
443 return 1
444 fi
446 got diff -r $testroot/repo $orig_commit $new_commit2 \
447 > $testroot/diff
448 sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
449 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
450 cmp -s $testroot/diff.expected $testroot/diff
451 ret=$?
452 if [ $ret -ne 0 ]; then
453 diff -u $testroot/diff.expected $testroot/diff
454 fi
455 test_done "$testroot" "$ret"
458 test_histedit_fold() {
459 local testroot=`test_init histedit_fold`
461 local orig_commit=`git_show_head $testroot/repo`
463 echo "modified alpha on master" > $testroot/repo/alpha
464 (cd $testroot/repo && git rm -q beta)
465 echo "new file on master" > $testroot/repo/epsilon/new
466 (cd $testroot/repo && git add epsilon/new)
467 git_commit $testroot/repo -m "committing changes"
468 local old_commit1=`git_show_head $testroot/repo`
470 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
471 git_commit $testroot/repo -m "committing to zeta on master"
472 local old_commit2=`git_show_head $testroot/repo`
474 echo "modified delta on master" > $testroot/repo/gamma/delta
475 git_commit $testroot/repo -m "committing to delta on master"
476 local old_commit3=`git_show_head $testroot/repo`
478 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
479 ret=$?
480 if [ $ret -ne 0 ]; then
481 test_done "$testroot" "$ret"
482 return 1
483 fi
485 echo "fold $old_commit1" > $testroot/histedit-script
486 echo "drop $old_commit2" >> $testroot/histedit-script
487 echo "pick $old_commit3" >> $testroot/histedit-script
488 echo "mesg committing folded changes" >> $testroot/histedit-script
490 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
491 > $testroot/stdout)
493 local new_commit1=`git_show_parent_commit $testroot/repo`
494 local new_commit2=`git_show_head $testroot/repo`
496 local short_old_commit1=`trim_obj_id 28 $old_commit1`
497 local short_old_commit2=`trim_obj_id 28 $old_commit2`
498 local short_old_commit3=`trim_obj_id 28 $old_commit3`
499 local short_new_commit1=`trim_obj_id 28 $new_commit1`
500 local short_new_commit2=`trim_obj_id 28 $new_commit2`
502 echo "G alpha" > $testroot/stdout.expected
503 echo "D beta" >> $testroot/stdout.expected
504 echo "A epsilon/new" >> $testroot/stdout.expected
505 echo "$short_old_commit1 -> fold commit: committing changes" \
506 >> $testroot/stdout.expected
507 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
508 echo "drop commit: committing to zeta on master" \
509 >> $testroot/stdout.expected
510 echo "G gamma/delta" >> $testroot/stdout.expected
511 echo -n "$short_old_commit3 -> $short_new_commit2: " \
512 >> $testroot/stdout.expected
513 echo "committing folded changes" >> $testroot/stdout.expected
514 echo "Switching work tree to refs/heads/master" \
515 >> $testroot/stdout.expected
517 cmp -s $testroot/stdout.expected $testroot/stdout
518 ret=$?
519 if [ $ret -ne 0 ]; then
520 diff -u $testroot/stdout.expected $testroot/stdout
521 test_done "$testroot" "$ret"
522 return 1
523 fi
525 echo "modified alpha on master" > $testroot/content.expected
526 cat $testroot/wt/alpha > $testroot/content
527 cmp -s $testroot/content.expected $testroot/content
528 ret=$?
529 if [ $ret -ne 0 ]; then
530 diff -u $testroot/content.expected $testroot/content
531 test_done "$testroot" "$ret"
532 return 1
533 fi
535 if [ -e $testroot/wt/beta ]; then
536 echo "removed file beta still exists on disk" >&2
537 test_done "$testroot" "1"
538 return 1
539 fi
541 echo "new file on master" > $testroot/content.expected
542 cat $testroot/wt/epsilon/new > $testroot/content
543 cmp -s $testroot/content.expected $testroot/content
544 ret=$?
545 if [ $ret -ne 0 ]; then
546 diff -u $testroot/content.expected $testroot/content
547 test_done "$testroot" "$ret"
548 return 1
549 fi
551 (cd $testroot/wt && got status > $testroot/stdout)
553 echo -n > $testroot/stdout.expected
554 cmp -s $testroot/stdout.expected $testroot/stdout
555 ret=$?
556 if [ $ret -ne 0 ]; then
557 diff -u $testroot/stdout.expected $testroot/stdout
558 test_done "$testroot" "$ret"
559 return 1
560 fi
562 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
563 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
564 echo "commit $orig_commit" >> $testroot/stdout.expected
565 cmp -s $testroot/stdout.expected $testroot/stdout
566 ret=$?
567 if [ $ret -ne 0 ]; then
568 diff -u $testroot/stdout.expected $testroot/stdout
569 fi
570 test_done "$testroot" "$ret"
573 test_histedit_edit() {
574 local testroot=`test_init histedit_edit`
576 local orig_commit=`git_show_head $testroot/repo`
578 echo "modified alpha on master" > $testroot/repo/alpha
579 (cd $testroot/repo && git rm -q beta)
580 echo "new file on master" > $testroot/repo/epsilon/new
581 (cd $testroot/repo && git add epsilon/new)
582 git_commit $testroot/repo -m "committing changes"
583 local old_commit1=`git_show_head $testroot/repo`
585 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
586 git_commit $testroot/repo -m "committing to zeta on master"
587 local old_commit2=`git_show_head $testroot/repo`
589 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
590 ret=$?
591 if [ $ret -ne 0 ]; then
592 test_done "$testroot" "$ret"
593 return 1
594 fi
596 echo "edit $old_commit1" > $testroot/histedit-script
597 echo "mesg committing changes" >> $testroot/histedit-script
598 echo "pick $old_commit2" >> $testroot/histedit-script
600 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
601 > $testroot/stdout)
603 local short_old_commit1=`trim_obj_id 28 $old_commit1`
604 local short_old_commit2=`trim_obj_id 28 $old_commit2`
606 echo "G alpha" > $testroot/stdout.expected
607 echo "D beta" >> $testroot/stdout.expected
608 echo "A epsilon/new" >> $testroot/stdout.expected
609 echo "Stopping histedit for amending commit $old_commit1" \
610 >> $testroot/stdout.expected
611 cmp -s $testroot/stdout.expected $testroot/stdout
612 ret=$?
613 if [ $ret -ne 0 ]; then
614 diff -u $testroot/stdout.expected $testroot/stdout
615 test_done "$testroot" "$ret"
616 return 1
617 fi
619 echo "edited modified alpha on master" > $testroot/wt/alpha
621 # test interaction of 'got stage' and histedit -c
622 (cd $testroot/wt && got stage alpha > /dev/null)
623 (cd $testroot/wt && got histedit -c > $testroot/stdout \
624 2> $testroot/stderr)
625 ret=$?
626 if [ $ret -eq 0 ]; then
627 echo "histedit succeeded unexpectedly" >&2
628 test_done "$testroot" "1"
629 return 1
630 fi
631 echo -n "got: work tree contains files with staged changes; " \
632 > $testroot/stderr.expected
633 echo "these changes must be committed or unstaged first" \
634 >> $testroot/stderr.expected
635 cmp -s $testroot/stderr.expected $testroot/stderr
636 ret=$?
637 if [ $ret -ne 0 ]; then
638 diff -u $testroot/stderr.expected $testroot/stderr
639 test_done "$testroot" "$ret"
640 return 1
641 fi
643 (cd $testroot/wt && got unstage alpha > /dev/null)
644 (cd $testroot/wt && got histedit -c > $testroot/stdout)
646 local new_commit1=`git_show_parent_commit $testroot/repo`
647 local new_commit2=`git_show_head $testroot/repo`
649 local short_new_commit1=`trim_obj_id 28 $new_commit1`
650 local short_new_commit2=`trim_obj_id 28 $new_commit2`
652 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
653 > $testroot/stdout.expected
654 echo "G epsilon/zeta" >> $testroot/stdout.expected
655 echo -n "$short_old_commit2 -> $short_new_commit2: " \
656 >> $testroot/stdout.expected
657 echo "committing to zeta on master" >> $testroot/stdout.expected
658 echo "Switching work tree to refs/heads/master" \
659 >> $testroot/stdout.expected
661 cmp -s $testroot/stdout.expected $testroot/stdout
662 ret=$?
663 if [ $ret -ne 0 ]; then
664 diff -u $testroot/stdout.expected $testroot/stdout
665 test_done "$testroot" "$ret"
666 return 1
667 fi
669 echo "edited modified alpha on master" > $testroot/content.expected
670 cat $testroot/wt/alpha > $testroot/content
671 cmp -s $testroot/content.expected $testroot/content
672 ret=$?
673 if [ $ret -ne 0 ]; then
674 diff -u $testroot/content.expected $testroot/content
675 test_done "$testroot" "$ret"
676 return 1
677 fi
679 if [ -e $testroot/wt/beta ]; then
680 echo "removed file beta still exists on disk" >&2
681 test_done "$testroot" "1"
682 return 1
683 fi
685 echo "new file on master" > $testroot/content.expected
686 cat $testroot/wt/epsilon/new > $testroot/content
687 cmp -s $testroot/content.expected $testroot/content
688 ret=$?
689 if [ $ret -ne 0 ]; then
690 diff -u $testroot/content.expected $testroot/content
691 test_done "$testroot" "$ret"
692 return 1
693 fi
695 (cd $testroot/wt && got status > $testroot/stdout)
697 echo -n > $testroot/stdout.expected
698 cmp -s $testroot/stdout.expected $testroot/stdout
699 ret=$?
700 if [ $ret -ne 0 ]; then
701 diff -u $testroot/stdout.expected $testroot/stdout
702 test_done "$testroot" "$ret"
703 return 1
704 fi
706 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
707 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
708 echo "commit $new_commit1" >> $testroot/stdout.expected
709 echo "commit $orig_commit" >> $testroot/stdout.expected
710 cmp -s $testroot/stdout.expected $testroot/stdout
711 ret=$?
712 if [ $ret -ne 0 ]; then
713 diff -u $testroot/stdout.expected $testroot/stdout
714 fi
715 test_done "$testroot" "$ret"
718 test_histedit_fold_last_commit() {
719 local testroot=`test_init histedit_fold_last_commit`
721 local orig_commit=`git_show_head $testroot/repo`
723 echo "modified alpha on master" > $testroot/repo/alpha
724 (cd $testroot/repo && git rm -q beta)
725 echo "new file on master" > $testroot/repo/epsilon/new
726 (cd $testroot/repo && git add epsilon/new)
727 git_commit $testroot/repo -m "committing changes"
728 local old_commit1=`git_show_head $testroot/repo`
730 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
731 git_commit $testroot/repo -m "committing to zeta on master"
732 local old_commit2=`git_show_head $testroot/repo`
734 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
735 ret=$?
736 if [ $ret -ne 0 ]; then
737 test_done "$testroot" "$ret"
738 return 1
739 fi
741 echo "pick $old_commit1" > $testroot/histedit-script
742 echo "fold $old_commit2" >> $testroot/histedit-script
744 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
745 > $testroot/stdout 2> $testroot/stderr)
747 ret=$?
748 if [ $ret -eq 0 ]; then
749 echo "histedit succeeded unexpectedly" >&2
750 test_done "$testroot" "1"
751 return 1
752 fi
754 echo "got: last commit in histedit script cannot be folded" \
755 > $testroot/stderr.expected
757 cmp -s $testroot/stderr.expected $testroot/stderr
758 ret=$?
759 if [ $ret -ne 0 ]; then
760 diff -u $testroot/stderr.expected $testroot/stderr
761 fi
762 test_done "$testroot" "$ret"
765 test_histedit_missing_commit() {
766 local testroot=`test_init histedit_missing_commit`
768 local orig_commit=`git_show_head $testroot/repo`
770 echo "modified alpha on master" > $testroot/repo/alpha
771 (cd $testroot/repo && git rm -q beta)
772 echo "new file on master" > $testroot/repo/epsilon/new
773 (cd $testroot/repo && git add epsilon/new)
774 git_commit $testroot/repo -m "committing changes"
775 local old_commit1=`git_show_head $testroot/repo`
777 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
778 git_commit $testroot/repo -m "committing to zeta on master"
779 local old_commit2=`git_show_head $testroot/repo`
781 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
782 ret=$?
783 if [ $ret -ne 0 ]; then
784 test_done "$testroot" "$ret"
785 return 1
786 fi
788 echo "pick $old_commit1" > $testroot/histedit-script
789 echo "mesg committing changes" >> $testroot/histedit-script
791 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
792 > $testroot/stdout 2> $testroot/stderr)
794 ret=$?
795 if [ $ret -eq 0 ]; then
796 echo "histedit succeeded unexpectedly" >&2
797 test_done "$testroot" "1"
798 return 1
799 fi
801 echo "got: commit $old_commit2 missing from histedit script" \
802 > $testroot/stderr.expected
804 cmp -s $testroot/stderr.expected $testroot/stderr
805 ret=$?
806 if [ $ret -ne 0 ]; then
807 diff -u $testroot/stderr.expected $testroot/stderr
808 fi
809 test_done "$testroot" "$ret"
812 test_histedit_abort() {
813 local testroot=`test_init histedit_abort`
815 local orig_commit=`git_show_head $testroot/repo`
817 echo "modified alpha on master" > $testroot/repo/alpha
818 (cd $testroot/repo && git rm -q beta)
819 echo "new file on master" > $testroot/repo/epsilon/new
820 (cd $testroot/repo && git add epsilon/new)
821 git_commit $testroot/repo -m "committing changes"
822 local old_commit1=`git_show_head $testroot/repo`
824 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
825 git_commit $testroot/repo -m "committing to zeta on master"
826 local old_commit2=`git_show_head $testroot/repo`
828 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
829 ret=$?
830 if [ $ret -ne 0 ]; then
831 test_done "$testroot" "$ret"
832 return 1
833 fi
835 # unrelated unversioned file in work tree
836 touch $testroot/wt/unversioned-file
838 echo "edit $old_commit1" > $testroot/histedit-script
839 echo "mesg committing changes" >> $testroot/histedit-script
840 echo "pick $old_commit2" >> $testroot/histedit-script
842 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
843 > $testroot/stdout)
845 local short_old_commit1=`trim_obj_id 28 $old_commit1`
846 local short_old_commit2=`trim_obj_id 28 $old_commit2`
848 echo "G alpha" > $testroot/stdout.expected
849 echo "D beta" >> $testroot/stdout.expected
850 echo "A epsilon/new" >> $testroot/stdout.expected
851 echo "Stopping histedit for amending commit $old_commit1" \
852 >> $testroot/stdout.expected
853 cmp -s $testroot/stdout.expected $testroot/stdout
854 ret=$?
855 if [ $ret -ne 0 ]; then
856 diff -u $testroot/stdout.expected $testroot/stdout
857 test_done "$testroot" "$ret"
858 return 1
859 fi
861 echo "edited modified alpha on master" > $testroot/wt/alpha
863 (cd $testroot/wt && got histedit -a > $testroot/stdout)
865 local new_commit1=`git_show_parent_commit $testroot/repo`
866 local new_commit2=`git_show_head $testroot/repo`
868 echo "Switching work tree to refs/heads/master" \
869 > $testroot/stdout.expected
870 echo "R alpha" >> $testroot/stdout.expected
871 echo "R beta" >> $testroot/stdout.expected
872 echo "R epsilon/new" >> $testroot/stdout.expected
873 echo "Histedit of refs/heads/master aborted" \
874 >> $testroot/stdout.expected
876 cmp -s $testroot/stdout.expected $testroot/stdout
877 ret=$?
878 if [ $ret -ne 0 ]; then
879 diff -u $testroot/stdout.expected $testroot/stdout
880 test_done "$testroot" "$ret"
881 return 1
882 fi
884 for f in alpha beta; do
885 echo "$f" > $testroot/content.expected
886 cat $testroot/wt/$f > $testroot/content
887 cmp -s $testroot/content.expected $testroot/content
888 ret=$?
889 if [ $ret -ne 0 ]; then
890 diff -u $testroot/content.expected $testroot/content
891 test_done "$testroot" "$ret"
892 return 1
893 fi
894 done
896 echo "new file on master" > $testroot/content.expected
897 cat $testroot/wt/epsilon/new > $testroot/content
898 cmp -s $testroot/content.expected $testroot/content
899 ret=$?
900 if [ $ret -ne 0 ]; then
901 diff -u $testroot/content.expected $testroot/content
902 test_done "$testroot" "$ret"
903 return 1
904 fi
906 (cd $testroot/wt && got status > $testroot/stdout)
908 echo "? epsilon/new" > $testroot/stdout.expected
909 echo "? unversioned-file" >> $testroot/stdout.expected
910 cmp -s $testroot/stdout.expected $testroot/stdout
911 ret=$?
912 if [ $ret -ne 0 ]; then
913 diff -u $testroot/stdout.expected $testroot/stdout
914 test_done "$testroot" "$ret"
915 return 1
916 fi
918 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
919 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
920 echo "commit $new_commit1" >> $testroot/stdout.expected
921 echo "commit $orig_commit" >> $testroot/stdout.expected
922 cmp -s $testroot/stdout.expected $testroot/stdout
923 ret=$?
924 if [ $ret -ne 0 ]; then
925 diff -u $testroot/stdout.expected $testroot/stdout
926 fi
927 test_done "$testroot" "$ret"
930 test_histedit_path_prefix_drop() {
931 local testroot=`test_init histedit_path_prefix_drop`
932 local orig_commit=`git_show_head $testroot/repo`
934 echo "modified zeta" > $testroot/repo/epsilon/zeta
935 git_commit $testroot/repo -m "changing zeta"
936 local old_commit1=`git_show_head $testroot/repo`
938 got checkout -c $orig_commit -p gamma $testroot/repo \
939 $testroot/wt > /dev/null
940 ret=$?
941 if [ $ret -ne 0 ]; then
942 test_done "$testroot" "$ret"
943 return 1
944 fi
946 echo "drop $old_commit1" > $testroot/histedit-script
948 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
949 > $testroot/stdout 2> $testroot/stderr)
951 ret=$?
952 if [ $ret -eq 0 ]; then
953 echo "histedit succeeded unexpectedly" >&2
954 test_done "$testroot" "1"
955 return 1
956 fi
958 echo -n "got: cannot edit branch history which contains changes " \
959 > $testroot/stderr.expected
960 echo "outside of this work tree's path prefix" \
961 >> $testroot/stderr.expected
963 cmp -s $testroot/stderr.expected $testroot/stderr
964 ret=$?
965 if [ $ret -ne 0 ]; then
966 diff -u $testroot/stderr.expected $testroot/stderr
967 test_done "$testroot" "$ret"
968 return 1
969 fi
971 rm -rf $testroot/wt
972 got checkout -c $orig_commit -p epsilon $testroot/repo \
973 $testroot/wt > /dev/null
974 ret=$?
975 if [ $ret -ne 0 ]; then
976 test_done "$testroot" "$ret"
977 return 1
978 fi
979 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
980 > $testroot/stdout)
982 local short_old_commit1=`trim_obj_id 28 $old_commit1`
983 local short_old_commit2=`trim_obj_id 28 $old_commit2`
985 echo "$short_old_commit1 -> drop commit: changing zeta" \
986 > $testroot/stdout.expected
987 echo "Switching work tree to refs/heads/master" \
988 >> $testroot/stdout.expected
990 cmp -s $testroot/stdout.expected $testroot/stdout
991 ret=$?
992 if [ $ret -ne 0 ]; then
993 diff -u $testroot/stdout.expected $testroot/stdout
994 test_done "$testroot" "$ret"
995 return 1
996 fi
998 echo "zeta" > $testroot/content.expected
999 cat $testroot/wt/zeta > $testroot/content
1000 cmp -s $testroot/content.expected $testroot/content
1001 ret=$?
1002 if [ $ret -ne 0 ]; then
1003 diff -u $testroot/content.expected $testroot/content
1004 test_done "$testroot" "$ret"
1005 return 1
1009 (cd $testroot/wt && got status > $testroot/stdout)
1011 echo -n > $testroot/stdout.expected
1012 cmp -s $testroot/stdout.expected $testroot/stdout
1013 ret=$?
1014 if [ $ret -ne 0 ]; then
1015 diff -u $testroot/stdout.expected $testroot/stdout
1016 test_done "$testroot" "$ret"
1017 return 1
1020 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1021 echo "commit $orig_commit (master)" > $testroot/stdout.expected
1022 cmp -s $testroot/stdout.expected $testroot/stdout
1023 ret=$?
1024 if [ $ret -ne 0 ]; then
1025 diff -u $testroot/stdout.expected $testroot/stdout
1027 test_done "$testroot" "$ret"
1030 test_histedit_path_prefix_edit() {
1031 local testroot=`test_init histedit_path_prefix_edit`
1032 local orig_commit=`git_show_head $testroot/repo`
1034 echo "modified zeta" > $testroot/repo/epsilon/zeta
1035 git_commit $testroot/repo -m "changing zeta"
1036 local old_commit1=`git_show_head $testroot/repo`
1038 got diff -r $testroot/repo $orig_commit $old_commit1 \
1039 > $testroot/diff.expected
1041 got checkout -c $orig_commit -p gamma $testroot/repo \
1042 $testroot/wt > /dev/null
1043 ret=$?
1044 if [ $ret -ne 0 ]; then
1045 test_done "$testroot" "$ret"
1046 return 1
1049 echo "edit $old_commit1" > $testroot/histedit-script
1050 echo "mesg modified zeta" >> $testroot/histedit-script
1052 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1053 > $testroot/stdout 2> $testroot/stderr)
1055 ret=$?
1056 if [ $ret -eq 0 ]; then
1057 echo "histedit succeeded unexpectedly" >&2
1058 test_done "$testroot" "1"
1059 return 1
1062 echo -n "got: cannot edit branch history which contains changes " \
1063 > $testroot/stderr.expected
1064 echo "outside of this work tree's path prefix" \
1065 >> $testroot/stderr.expected
1067 cmp -s $testroot/stderr.expected $testroot/stderr
1068 ret=$?
1069 if [ $ret -ne 0 ]; then
1070 diff -u $testroot/stderr.expected $testroot/stderr
1071 test_done "$testroot" "$ret"
1072 return 1
1075 rm -rf $testroot/wt
1076 got checkout -c $orig_commit -p epsilon $testroot/repo \
1077 $testroot/wt > /dev/null
1078 ret=$?
1079 if [ $ret -ne 0 ]; then
1080 test_done "$testroot" "$ret"
1081 return 1
1083 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1084 > $testroot/stdout)
1086 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1088 echo "G zeta" > $testroot/stdout.expected
1089 echo "Stopping histedit for amending commit $old_commit1" \
1090 >> $testroot/stdout.expected
1091 cmp -s $testroot/stdout.expected $testroot/stdout
1092 ret=$?
1093 if [ $ret -ne 0 ]; then
1094 diff -u $testroot/stdout.expected $testroot/stdout
1095 test_done "$testroot" "$ret"
1096 return 1
1099 echo "modified zeta" > $testroot/content.expected
1100 cat $testroot/wt/zeta > $testroot/content
1101 cmp -s $testroot/content.expected $testroot/content
1102 ret=$?
1103 if [ $ret -ne 0 ]; then
1104 diff -u $testroot/content.expected $testroot/content
1105 test_done "$testroot" "$ret"
1106 return 1
1109 (cd $testroot/wt && got status > $testroot/stdout)
1111 echo "M zeta"> $testroot/stdout.expected
1112 cmp -s $testroot/stdout.expected $testroot/stdout
1113 ret=$?
1114 if [ $ret -ne 0 ]; then
1115 diff -u $testroot/stdout.expected $testroot/stdout
1116 test_done "$testroot" "$ret"
1117 return 1
1120 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1122 local new_commit1=`git_show_head $testroot/repo`
1123 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1125 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1126 > $testroot/stdout.expected
1127 echo "modified zeta" >> $testroot/stdout.expected
1128 echo "Switching work tree to refs/heads/master" \
1129 >> $testroot/stdout.expected
1131 cmp -s $testroot/stdout.expected $testroot/stdout
1132 ret=$?
1133 if [ $ret -ne 0 ]; then
1134 diff -u $testroot/stdout.expected $testroot/stdout
1135 test_done "$testroot" "$ret"
1136 return 1
1139 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1140 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1141 echo "commit $orig_commit" >> $testroot/stdout.expected
1142 cmp -s $testroot/stdout.expected $testroot/stdout
1143 ret=$?
1144 if [ $ret -ne 0 ]; then
1145 diff -u $testroot/stdout.expected $testroot/stdout
1146 test_done "$testroot" "$ret"
1147 return 1
1150 got diff -r $testroot/repo $orig_commit $new_commit1 \
1151 > $testroot/diff
1152 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1153 cmp -s $testroot/diff.expected $testroot/diff
1154 ret=$?
1155 if [ $ret -ne 0 ]; then
1156 diff -u $testroot/diff.expected $testroot/diff
1158 test_done "$testroot" "$ret"
1161 test_histedit_outside_refs_heads() {
1162 local testroot=`test_init histedit_outside_refs_heads`
1163 local commit1=`git_show_head $testroot/repo`
1165 got checkout $testroot/repo $testroot/wt > /dev/null
1166 ret=$?
1167 if [ $ret -ne 0 ]; then
1168 echo "got checkout failed unexpectedly"
1169 test_done "$testroot" "$ret"
1170 return 1
1173 echo "modified alpha" > $testroot/wt/alpha
1175 (cd $testroot/wt && got commit -m 'change alpha' \
1176 > $testroot/stdout 2> $testroot/stderr)
1177 ret=$?
1178 if [ $ret -ne 0 ]; then
1179 echo "got commit failed unexpectedly" >&2
1180 test_done "$testroot" "1"
1181 return 1
1183 local commit2=`git_show_head $testroot/repo`
1185 got ref -r $testroot/repo -c master refs/remotes/origin/master
1186 ret=$?
1187 if [ $ret -ne 0 ]; then
1188 echo "got ref failed unexpectedly" >&2
1189 test_done "$testroot" "1"
1190 return 1
1193 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1194 ret=$?
1195 if [ $ret -ne 0 ]; then
1196 echo "got update failed unexpectedly"
1197 test_done "$testroot" "$ret"
1198 return 1
1201 echo "edit $commit2" > $testroot/histedit-script
1202 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1203 2> $testroot/stderr)
1205 echo -n "got: will not edit commit history of a branch outside the " \
1206 > $testroot/stderr.expected
1207 echo '"refs/heads/" reference namespace' \
1208 >> $testroot/stderr.expected
1209 cmp -s $testroot/stderr.expected $testroot/stderr
1210 ret=$?
1211 if [ $ret -ne 0 ]; then
1212 diff -u $testroot/stderr.expected $testroot/stderr
1214 test_done "$testroot" "$ret"
1217 test_histedit_fold_last_commit_swap() {
1218 local testroot=`test_init histedit_fold_last_commit_swap`
1220 local orig_commit=`git_show_head $testroot/repo`
1222 echo "modified alpha on master" > $testroot/repo/alpha
1223 (cd $testroot/repo && git rm -q beta)
1224 echo "new file on master" > $testroot/repo/epsilon/new
1225 (cd $testroot/repo && git add epsilon/new)
1226 git_commit $testroot/repo -m "committing changes"
1227 local old_commit1=`git_show_head $testroot/repo`
1229 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1230 git_commit $testroot/repo -m "committing to zeta on master"
1231 local old_commit2=`git_show_head $testroot/repo`
1233 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1234 ret=$?
1235 if [ $ret -ne 0 ]; then
1236 test_done "$testroot" "$ret"
1237 return 1
1240 # fold commit2 into commit1 (requires swapping commits)
1241 echo "fold $old_commit2" > $testroot/histedit-script
1242 echo "pick $old_commit1" >> $testroot/histedit-script
1243 echo "mesg committing folded changes" >> $testroot/histedit-script
1245 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1246 > $testroot/stdout 2> $testroot/stderr)
1248 ret=$?
1249 if [ $ret -ne 0 ]; then
1250 echo "histedit failed unexpectedly" >&2
1251 test_done "$testroot" "$ret"
1252 return 1
1255 local new_commit=`git_show_head $testroot/repo`
1257 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1258 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1259 local short_new_commit=`trim_obj_id 28 $new_commit`
1261 echo "G epsilon/zeta" >> $testroot/stdout.expected
1262 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1263 >> $testroot/stdout.expected
1264 echo "on master" >> $testroot/stdout.expected
1265 echo "G alpha" >> $testroot/stdout.expected
1266 echo "D beta" >> $testroot/stdout.expected
1267 echo "A epsilon/new" >> $testroot/stdout.expected
1268 echo -n "$short_old_commit1 -> $short_new_commit: " \
1269 >> $testroot/stdout.expected
1270 echo "committing folded changes" >> $testroot/stdout.expected
1271 echo "Switching work tree to refs/heads/master" \
1272 >> $testroot/stdout.expected
1274 cmp -s $testroot/stdout.expected $testroot/stdout
1275 ret=$?
1276 if [ $ret -ne 0 ]; then
1277 diff -u $testroot/stdout.expected $testroot/stdout
1279 test_done "$testroot" "$ret"
1282 test_histedit_split_commit() {
1283 local testroot=`test_init histedit_split_commit`
1285 local orig_commit=`git_show_head $testroot/repo`
1287 echo "modified alpha on master" > $testroot/repo/alpha
1288 (cd $testroot/repo && git rm -q beta)
1289 echo "new file on master" > $testroot/repo/epsilon/new
1290 (cd $testroot/repo && git add epsilon/new)
1291 git_commit $testroot/repo -m "committing changes 1"
1292 local old_commit1=`git_show_head $testroot/repo`
1293 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1295 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1296 git_commit $testroot/repo -m "committing changes 2"
1297 local old_commit2=`git_show_head $testroot/repo`
1298 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1300 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1301 ret=$?
1302 if [ $ret -ne 0 ]; then
1303 test_done "$testroot" "$ret"
1304 return 1
1307 # split commit1 into commitA and commitB and commitC
1308 echo "e $old_commit1" > $testroot/histedit-script
1309 echo "p $old_commit2" >> $testroot/histedit-script
1311 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1312 > $testroot/stdout 2> $testroot/stderr)
1313 ret=$?
1314 if [ $ret -ne 0 ]; then
1315 echo "histedit failed unexpectedly:" >&2
1316 cat $testroot/stderr >&2
1317 test_done "$testroot" "$ret"
1318 return 1
1321 echo "G alpha" > $testroot/stdout.expected
1322 echo "D beta" >> $testroot/stdout.expected
1323 echo "A epsilon/new" >> $testroot/stdout.expected
1324 echo "Stopping histedit for amending commit $old_commit1" \
1325 >> $testroot/stdout.expected
1327 cmp -s $testroot/stdout.expected $testroot/stdout
1328 ret=$?
1329 if [ $ret -ne 0 ]; then
1330 diff -u $testroot/stdout.expected $testroot/stdout
1331 test_done "$testroot" "$ret"
1332 return 1
1335 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1336 ret=$?
1337 if [ $ret -ne 0 ]; then
1338 echo "commit failed unexpectedly" >&2
1339 test_done "$testroot" "$ret"
1340 return 1
1343 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1344 ret=$?
1345 if [ $ret -ne 0 ]; then
1346 echo "commit failed unexpectedly" >&2
1347 test_done "$testroot" "$ret"
1348 return 1
1351 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1352 ret=$?
1353 if [ $ret -ne 0 ]; then
1354 echo "commit failed unexpectedly" >&2
1355 test_done "$testroot" "$ret"
1356 return 1
1359 (cd $testroot/wt && got histedit -c \
1360 > $testroot/stdout 2> $testroot/stderr)
1361 ret=$?
1362 if [ $ret -ne 0 ]; then
1363 echo "histedit failed unexpectedly:" >&2
1364 cat $testroot/stderr >&2
1365 test_done "$testroot" "$ret"
1366 return 1
1368 local new_commit2=`git_show_head $testroot/repo`
1369 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1371 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1372 > $testroot/stdout.expected
1373 echo "G epsilon/zeta" >> $testroot/stdout.expected
1374 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1375 >> $testroot/stdout.expected
1376 echo "Switching work tree to refs/heads/master" \
1377 >> $testroot/stdout.expected
1379 cmp -s $testroot/stdout.expected $testroot/stdout
1380 ret=$?
1381 if [ $ret -ne 0 ]; then
1382 diff -u $testroot/stdout.expected $testroot/stdout
1384 test_done "$testroot" "$ret"
1388 test_histedit_duplicate_commit_in_script() {
1389 local testroot=`test_init histedit_duplicate_commit_in_script`
1391 local orig_commit=`git_show_head $testroot/repo`
1393 echo "modified alpha on master" > $testroot/repo/alpha
1394 (cd $testroot/repo && git rm -q beta)
1395 echo "new file on master" > $testroot/repo/epsilon/new
1396 (cd $testroot/repo && git add epsilon/new)
1397 git_commit $testroot/repo -m "committing changes 1"
1398 local old_commit1=`git_show_head $testroot/repo`
1400 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1401 git_commit $testroot/repo -m "committing changes 2"
1402 local old_commit2=`git_show_head $testroot/repo`
1404 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1405 ret=$?
1406 if [ $ret -ne 0 ]; then
1407 test_done "$testroot" "$ret"
1408 return 1
1411 # This histedit script lists commit1 more than once
1412 echo "p $old_commit1" > $testroot/histedit-script
1413 echo "p $old_commit1" >> $testroot/histedit-script
1414 echo "p $old_commit2" >> $testroot/histedit-script
1416 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1417 > $testroot/stdout 2> $testroot/stderr)
1418 ret=$?
1419 if [ $ret -eq 0 ]; then
1420 echo "histedit succeeded unexpectedly:" >&2
1421 cat $testroot/stdout >&2
1422 test_done "$testroot" "$ret"
1423 return 1
1426 echo -n "got: commit $old_commit1 is listed more than once " \
1427 > $testroot/stderr.expected
1428 echo "in histedit script" >> $testroot/stderr.expected
1430 cmp -s $testroot/stderr.expected $testroot/stderr
1431 ret=$?
1432 if [ $ret -ne 0 ]; then
1433 diff -u $testroot/stderr.expected $testroot/stderr
1435 test_done "$testroot" "$ret"
1439 # if a previous commit introduces a new file, and it is folded into a commit
1440 # that deletes the same file, the file still exists after the histedit
1441 test_histedit_fold_add_delete() {
1442 local testroot=`test_init histedit_fold_add_delete`
1444 local orig_commit=`git_show_head $testroot/repo`
1446 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1447 (cd $testroot/repo && git add epsilon/psi)
1448 git_commit $testroot/repo -m "committing changes"
1449 local old_commit1=`git_show_head $testroot/repo`
1451 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1452 git_commit $testroot/repo -m "editing psi"
1453 local old_commit2=`git_show_head $testroot/repo`
1455 (cd $testroot/repo && git rm -q epsilon/psi)
1456 git_commit $testroot/repo -m "removing psi"
1457 local old_commit3=`git_show_head $testroot/repo`
1459 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1460 ret=$?
1461 if [ $ret -ne 0 ]; then
1462 test_done "$testroot" "$ret"
1463 return 1
1466 echo "fold $old_commit1" > $testroot/histedit-script
1467 echo "fold $old_commit2" >> $testroot/histedit-script
1468 echo "pick $old_commit3" >> $testroot/histedit-script
1469 echo "mesg folded changes" >> $testroot/histedit-script
1471 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1472 > $testroot/stdout)
1474 local new_commit1=`git_show_head $testroot/repo`
1476 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1477 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1478 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1479 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1481 echo "A epsilon/psi" >> $testroot/stdout.expected
1482 echo "$short_old_commit1 -> fold commit: committing changes" \
1483 >> $testroot/stdout.expected
1484 echo "G epsilon/psi" >> $testroot/stdout.expected
1485 echo "$short_old_commit2 -> fold commit: editing psi" \
1486 >> $testroot/stdout.expected
1487 echo "D epsilon/psi" >> $testroot/stdout.expected
1488 echo "$short_old_commit3 -> no-op change: folded changes" \
1489 >> $testroot/stdout.expected
1490 echo "Switching work tree to refs/heads/master" \
1491 >> $testroot/stdout.expected
1493 cmp -s $testroot/stdout.expected $testroot/stdout
1494 ret=$?
1495 if [ $ret -ne 0 ]; then
1496 diff -u $testroot/stdout.expected $testroot/stdout
1497 test_done "$testroot" "$ret"
1498 return 1
1501 if [ -e $testroot/wt/epsilon/psi ]; then
1502 echo "removed file psi still exists on disk" >&2
1503 test_done "$testroot" "1"
1504 return 1
1507 (cd $testroot/wt && got status > $testroot/stdout)
1509 echo -n > $testroot/stdout.expected
1510 cmp -s $testroot/stdout.expected $testroot/stdout
1511 ret=$?
1512 if [ $ret -ne 0 ]; then
1513 diff -u $testroot/stdout.expected $testroot/stdout
1514 test_done "$testroot" "$ret"
1515 return 1
1518 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1519 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1520 cmp -s $testroot/stdout.expected $testroot/stdout
1521 ret=$?
1522 if [ $ret -ne 0 ]; then
1523 diff -u $testroot/stdout.expected $testroot/stdout
1524 test_done "$testroot" "$ret"
1525 return 1
1528 got tree -r $testroot/repo epsilon > $testroot/stdout
1529 echo "zeta" > $testroot/stdout.expected
1530 cmp -s $testroot/stdout.expected $testroot/stdout
1531 ret=$?
1532 if [ $ret -ne 0 ]; then
1533 diff -u $testroot/stdout.expected $testroot/stdout
1535 test_done "$testroot" "$ret"
1538 test_histedit_fold_only() {
1539 local testroot=`test_init histedit_fold_only`
1541 local orig_commit=`git_show_head $testroot/repo`
1543 echo "modified alpha on master" > $testroot/repo/alpha
1544 (cd $testroot/repo && git rm -q beta)
1545 echo "new file on master" > $testroot/repo/epsilon/new
1546 (cd $testroot/repo && git add epsilon/new)
1547 git_commit $testroot/repo -m "committing changes"
1548 local old_commit1=`git_show_head $testroot/repo`
1550 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1551 git_commit $testroot/repo -m "committing to zeta on master"
1552 local old_commit2=`git_show_head $testroot/repo`
1554 echo "modified delta on master" > $testroot/repo/gamma/delta
1555 git_commit $testroot/repo -m "committing to delta on master"
1556 local old_commit3=`git_show_head $testroot/repo`
1558 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1559 ret=$?
1560 if [ $ret -ne 0 ]; then
1561 test_done "$testroot" "$ret"
1562 return 1
1565 cat > $testroot/editor.sh <<EOF
1566 #!/bin/sh
1567 sed -i 's/.*/committing folded changes/' "\$1"
1568 EOF
1569 chmod +x $testroot/editor.sh
1571 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1572 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1574 local new_commit1=`git_show_head $testroot/repo`
1576 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1577 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1578 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1579 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1580 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1582 echo "G alpha" > $testroot/stdout.expected
1583 echo "D beta" >> $testroot/stdout.expected
1584 echo "A epsilon/new" >> $testroot/stdout.expected
1585 echo "$short_old_commit1 -> fold commit: committing changes" \
1586 >> $testroot/stdout.expected
1587 echo "G epsilon/zeta" >> $testroot/stdout.expected
1588 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1589 echo "fold commit: committing to zeta on master" \
1590 >> $testroot/stdout.expected
1591 echo "G gamma/delta" >> $testroot/stdout.expected
1592 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1593 >> $testroot/stdout.expected
1594 echo "committing folded changes" >> $testroot/stdout.expected
1595 echo "Switching work tree to refs/heads/master" \
1596 >> $testroot/stdout.expected
1598 cmp -s $testroot/stdout.expected $testroot/stdout
1599 ret=$?
1600 if [ $ret -ne 0 ]; then
1601 diff -u $testroot/stdout.expected $testroot/stdout
1602 test_done "$testroot" "$ret"
1603 return 1
1606 echo "modified alpha on master" > $testroot/content.expected
1607 cat $testroot/wt/alpha > $testroot/content
1608 cmp -s $testroot/content.expected $testroot/content
1609 ret=$?
1610 if [ $ret -ne 0 ]; then
1611 diff -u $testroot/content.expected $testroot/content
1612 test_done "$testroot" "$ret"
1613 return 1
1616 if [ -e $testroot/wt/beta ]; then
1617 echo "removed file beta still exists on disk" >&2
1618 test_done "$testroot" "1"
1619 return 1
1622 echo "new file on master" > $testroot/content.expected
1623 cat $testroot/wt/epsilon/new > $testroot/content
1624 cmp -s $testroot/content.expected $testroot/content
1625 ret=$?
1626 if [ $ret -ne 0 ]; then
1627 diff -u $testroot/content.expected $testroot/content
1628 test_done "$testroot" "$ret"
1629 return 1
1632 (cd $testroot/wt && got status > $testroot/stdout)
1634 echo -n > $testroot/stdout.expected
1635 cmp -s $testroot/stdout.expected $testroot/stdout
1636 ret=$?
1637 if [ $ret -ne 0 ]; then
1638 diff -u $testroot/stdout.expected $testroot/stdout
1639 test_done "$testroot" "$ret"
1640 return 1
1643 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1644 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1645 echo "commit $orig_commit" >> $testroot/stdout.expected
1646 cmp -s $testroot/stdout.expected $testroot/stdout
1647 ret=$?
1648 if [ $ret -ne 0 ]; then
1649 diff -u $testroot/stdout.expected $testroot/stdout
1651 test_done "$testroot" "$ret"
1654 test_histedit_fold_only_empty_logmsg() {
1655 local testroot=`test_init histedit_fold_only_empty_logmsg`
1657 local orig_commit=`git_show_head $testroot/repo`
1659 echo "modified alpha on master" > $testroot/repo/alpha
1660 (cd $testroot/repo && git rm -q beta)
1661 echo "new file on master" > $testroot/repo/epsilon/new
1662 (cd $testroot/repo && git add epsilon/new)
1663 git_commit $testroot/repo -m "committing changes"
1664 local old_commit1=`git_show_head $testroot/repo`
1666 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1667 git_commit $testroot/repo -m "committing to zeta on master"
1668 local old_commit2=`git_show_head $testroot/repo`
1670 echo "modified delta on master" > $testroot/repo/gamma/delta
1671 git_commit $testroot/repo -m "committing to delta on master"
1672 local old_commit3=`git_show_head $testroot/repo`
1674 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1675 ret=$?
1676 if [ $ret -ne 0 ]; then
1677 test_done "$testroot" "$ret"
1678 return 1
1681 cat > $testroot/editor.sh <<EOF
1682 #!/bin/sh
1683 sed -i 'd' "\$1"
1684 EOF
1685 chmod +x $testroot/editor.sh
1687 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1688 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1690 local new_commit1=`git_show_head $testroot/repo`
1692 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1693 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1694 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1695 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1696 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1697 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1699 echo "G alpha" > $testroot/stdout.expected
1700 echo "D beta" >> $testroot/stdout.expected
1701 echo "A epsilon/new" >> $testroot/stdout.expected
1702 echo "$short_old_commit1 -> fold commit: committing changes" \
1703 >> $testroot/stdout.expected
1704 echo "G epsilon/zeta" >> $testroot/stdout.expected
1705 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1706 echo "fold commit: committing to zeta on master" \
1707 >> $testroot/stdout.expected
1708 echo "G gamma/delta" >> $testroot/stdout.expected
1709 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1710 >> $testroot/stdout.expected
1711 echo "# log message of folded commit $very_short_old_commit1" \
1712 >> $testroot/stdout.expected
1713 echo "Switching work tree to refs/heads/master" \
1714 >> $testroot/stdout.expected
1716 cmp -s $testroot/stdout.expected $testroot/stdout
1717 ret=$?
1718 if [ $ret -ne 0 ]; then
1719 diff -u $testroot/stdout.expected $testroot/stdout
1720 test_done "$testroot" "$ret"
1721 return 1
1724 echo "modified alpha on master" > $testroot/content.expected
1725 cat $testroot/wt/alpha > $testroot/content
1726 cmp -s $testroot/content.expected $testroot/content
1727 ret=$?
1728 if [ $ret -ne 0 ]; then
1729 diff -u $testroot/content.expected $testroot/content
1730 test_done "$testroot" "$ret"
1731 return 1
1734 if [ -e $testroot/wt/beta ]; then
1735 echo "removed file beta still exists on disk" >&2
1736 test_done "$testroot" "1"
1737 return 1
1740 echo "new file on master" > $testroot/content.expected
1741 cat $testroot/wt/epsilon/new > $testroot/content
1742 cmp -s $testroot/content.expected $testroot/content
1743 ret=$?
1744 if [ $ret -ne 0 ]; then
1745 diff -u $testroot/content.expected $testroot/content
1746 test_done "$testroot" "$ret"
1747 return 1
1750 (cd $testroot/wt && got status > $testroot/stdout)
1752 echo -n > $testroot/stdout.expected
1753 cmp -s $testroot/stdout.expected $testroot/stdout
1754 ret=$?
1755 if [ $ret -ne 0 ]; then
1756 diff -u $testroot/stdout.expected $testroot/stdout
1757 test_done "$testroot" "$ret"
1758 return 1
1761 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1762 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1763 echo "commit $orig_commit" >> $testroot/stdout.expected
1764 cmp -s $testroot/stdout.expected $testroot/stdout
1765 ret=$?
1766 if [ $ret -ne 0 ]; then
1767 diff -u $testroot/stdout.expected $testroot/stdout
1769 test_done "$testroot" "$ret"
1772 test_histedit_edit_only() {
1773 local testroot=`test_init histedit_edit_only`
1775 local orig_commit=`git_show_head $testroot/repo`
1777 echo "modified alpha on master" > $testroot/repo/alpha
1778 (cd $testroot/repo && git rm -q beta)
1779 echo "new file on master" > $testroot/repo/epsilon/new
1780 (cd $testroot/repo && git add epsilon/new)
1781 git_commit $testroot/repo -m "committing changes"
1782 local old_commit1=`git_show_head $testroot/repo`
1784 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1785 git_commit $testroot/repo -m "committing to zeta on master"
1786 local old_commit2=`git_show_head $testroot/repo`
1788 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1789 ret=$?
1790 if [ $ret -ne 0 ]; then
1791 test_done "$testroot" "$ret"
1792 return 1
1795 (cd $testroot/wt && got histedit -e > $testroot/stdout)
1797 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1798 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1800 echo "G alpha" > $testroot/stdout.expected
1801 echo "D beta" >> $testroot/stdout.expected
1802 echo "A epsilon/new" >> $testroot/stdout.expected
1803 echo "Stopping histedit for amending commit $old_commit1" \
1804 >> $testroot/stdout.expected
1805 cmp -s $testroot/stdout.expected $testroot/stdout
1806 ret=$?
1807 if [ $ret -ne 0 ]; then
1808 diff -u $testroot/stdout.expected $testroot/stdout
1809 test_done "$testroot" "$ret"
1810 return 1
1813 echo "edited modified alpha on master" > $testroot/wt/alpha
1815 cat > $testroot/editor.sh <<EOF
1816 #!/bin/sh
1817 sed -i 's/.*/committing edited changes 1/' "\$1"
1818 EOF
1819 chmod +x $testroot/editor.sh
1821 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1822 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1824 local new_commit1=$(cd $testroot/wt && got info | \
1825 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1826 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1828 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1829 > $testroot/stdout.expected
1830 echo "committing edited changes 1" >> $testroot/stdout.expected
1831 echo "G epsilon/zeta" >> $testroot/stdout.expected
1832 echo "Stopping histedit for amending commit $old_commit2" \
1833 >> $testroot/stdout.expected
1834 cmp -s $testroot/stdout.expected $testroot/stdout
1835 ret=$?
1836 if [ $ret -ne 0 ]; then
1837 diff -u $testroot/stdout.expected $testroot/stdout
1838 test_done "$testroot" "$ret"
1839 return 1
1842 echo "edited zeta on master" > $testroot/wt/epsilon/zeta
1844 cat > $testroot/editor.sh <<EOF
1845 #!/bin/sh
1846 sed -i 's/.*/committing edited changes 2/' "\$1"
1847 EOF
1848 chmod +x $testroot/editor.sh
1850 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1851 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1853 local new_commit2=`git_show_head $testroot/repo`
1854 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1856 echo -n "$short_old_commit2 -> $short_new_commit2: " \
1857 > $testroot/stdout.expected
1858 echo "committing edited changes 2" >> $testroot/stdout.expected
1859 echo "Switching work tree to refs/heads/master" \
1860 >> $testroot/stdout.expected
1862 cmp -s $testroot/stdout.expected $testroot/stdout
1863 ret=$?
1864 if [ $ret -ne 0 ]; then
1865 diff -u $testroot/stdout.expected $testroot/stdout
1866 test_done "$testroot" "$ret"
1867 return 1
1870 echo "edited modified alpha on master" > $testroot/content.expected
1871 cat $testroot/wt/alpha > $testroot/content
1872 cmp -s $testroot/content.expected $testroot/content
1873 ret=$?
1874 if [ $ret -ne 0 ]; then
1875 diff -u $testroot/content.expected $testroot/content
1876 test_done "$testroot" "$ret"
1877 return 1
1880 if [ -e $testroot/wt/beta ]; then
1881 echo "removed file beta still exists on disk" >&2
1882 test_done "$testroot" "1"
1883 return 1
1886 echo "new file on master" > $testroot/content.expected
1887 cat $testroot/wt/epsilon/new > $testroot/content
1888 cmp -s $testroot/content.expected $testroot/content
1889 ret=$?
1890 if [ $ret -ne 0 ]; then
1891 diff -u $testroot/content.expected $testroot/content
1892 test_done "$testroot" "$ret"
1893 return 1
1896 (cd $testroot/wt && got status > $testroot/stdout)
1898 echo -n > $testroot/stdout.expected
1899 cmp -s $testroot/stdout.expected $testroot/stdout
1900 ret=$?
1901 if [ $ret -ne 0 ]; then
1902 diff -u $testroot/stdout.expected $testroot/stdout
1903 test_done "$testroot" "$ret"
1904 return 1
1907 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1908 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
1909 echo "commit $new_commit1" >> $testroot/stdout.expected
1910 echo "commit $orig_commit" >> $testroot/stdout.expected
1911 cmp -s $testroot/stdout.expected $testroot/stdout
1912 ret=$?
1913 if [ $ret -ne 0 ]; then
1914 diff -u $testroot/stdout.expected $testroot/stdout
1916 test_done "$testroot" "$ret"
1919 test_histedit_prepend_line() {
1920 local testroot=`test_init histedit_prepend_line`
1921 local orig_commit=`git_show_head $testroot/repo`
1923 got checkout $testroot/repo $testroot/wt > /dev/null
1925 ed -s "$testroot/wt/alpha" <<EOF
1927 first line
1930 EOF
1932 cp $testroot/wt/alpha $testroot/content.expected
1934 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
1935 alpha > /dev/null)
1936 ret=$?
1937 if [ "$?" != 0 ]; then
1938 echo "got commit failed unexpectedly" >&2
1939 test_done "$testroot" "$ret"
1940 return 1
1943 local top_commit=`git_show_head $testroot/repo`
1944 echo "pick $top_commit" > "$testroot/histedit-script"
1946 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
1947 ret=$?
1948 if [ "$?" != 0 ]; then
1949 echo "got update failed unexpectedly" >&2
1950 test_done "$testroot" "$ret"
1951 return 1
1954 (cd $testroot/wt && got histedit -F "$testroot/histedit-script" \
1955 > /dev/null)
1956 ret=$?
1957 if [ "$?" != 0 ]; then
1958 echo "got histedit failed unexpectedly" >&2
1959 test_done "$testroot" "$ret"
1960 return 1
1963 cp $testroot/wt/alpha $testroot/content
1964 cmp -s $testroot/content.expected $testroot/content
1965 ret=$?
1966 if [ $ret -ne 0 ]; then
1967 diff -u $testroot/content.expected $testroot/content
1968 test_done "$testroot" "$ret"
1969 return 1
1972 test_done "$testroot" $ret
1975 test_histedit_mesg_invalid() {
1976 local testroot=`test_init mesg_invalid`
1978 local orig_commit=`git_show_head $testroot/repo`
1980 echo "modified alpha on master" > $testroot/repo/alpha
1981 (cd $testroot/repo && git rm -q beta)
1982 echo "new file on master" > $testroot/repo/epsilon/new
1983 (cd $testroot/repo && git add epsilon/new)
1984 git_commit $testroot/repo -m 'committing changes'
1985 local old_commit1=`git_show_head $testroot/repo`
1987 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1988 git_commit $testroot/repo -m 'committing to zeto on master'
1989 local old_commit2=`git_show_head $testroot/repo`
1991 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1992 ret=$?
1993 if [ $ret -ne 0 ]; then
1994 test_done "$testroot" $ret
1995 return 1
1998 # try with a leading mesg
2000 echo "mesg something something" > $testroot/histedit-script
2001 echo "pick $old_commit1" >> $testroot/histedit-script
2002 echo "pick $old_commit2" >> $testroot/histedit-script
2004 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2005 > $testroot/stdout 2> $testroot/stderr)
2006 ret=$?
2007 if [ $ret -eq 0 ]; then
2008 echo "histedit succeeded unexpectedly" >&2
2009 test_done "$testroot" 1
2010 return 1
2013 echo "got: bad histedit command" > $testroot/stderr.expected
2014 cmp -s $testroot/stderr.expected $testroot/stderr
2015 ret=$?
2016 if [ $ret -ne 0 ]; then
2017 diff -u $testroot/stderr.expected $testroot/stderr
2018 test_done "$testroot" $ret
2019 return 1
2022 # try again with mesg -> mesg
2024 echo "pick $old_commit1" > $testroot/histedit-script
2025 echo "mesg something something" >> $testroot/histedit-script
2026 echo "mesg something something else" >> $testroot/histedit-script
2027 echo "pick $old_commit2" >> $testroot/histedit-script
2029 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2030 > $testroot/stdout 2> $testroot/stderr)
2031 ret=$?
2032 if [ $ret -eq 0 ]; then
2033 echo "histedit succeeded unexpectedly" >&2
2034 test_done "$testroot" 1
2035 return 1
2038 echo "got: bad histedit command" > $testroot/stderr.expected
2039 cmp -s $testroot/stderr.expected $testroot/stderr
2040 ret=$?
2041 if [ $ret -ne 0 ]; then
2042 diff -u $testroot/stderr.expected $testroot/stderr
2043 test_done "$testroot" $ret
2044 return 1
2047 # try again with drop -> mesg
2049 echo "drop $old_commit1" > $testroot/histedit-script
2050 echo "mesg something something" >> $testroot/histedit-script
2051 echo "pick $old_commit2" >> $testroot/histedit-script
2053 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2054 > $testroot/stdout 2> $testroot/stderr)
2055 ret=$?
2056 if [ $ret -eq 0 ]; then
2057 echo "histedit succeeded unexpectedly" >&2
2058 test_done "$testroot" 1
2059 return 1
2062 echo "got: bad histedit command" > $testroot/stderr.expected
2063 cmp -s $testroot/stderr.expected $testroot/stderr
2064 ret=$?
2065 if [ $ret -ne 0 ]; then
2066 diff -u $testroot/stderr.expected $testroot/stderr
2067 test_done "$testroot" $ret
2068 return 1
2071 # try again with fold -> mesg
2073 echo "fold $old_commit1" > $testroot/histedit-script
2074 echo "mesg something something" >> $testroot/histedit-script
2075 echo "pick $old_commit2" >> $testroot/histedit-script
2077 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2078 > $testroot/stdout 2> $testroot/stderr)
2079 ret=$?
2080 if [ $ret -eq 0 ]; then
2081 echo "histedit succeeded unexpectedly" >&2
2082 test_done "$testroot" 1
2083 return 1
2086 echo "got: bad histedit command" > $testroot/stderr.expected
2087 cmp -s $testroot/stderr.expected $testroot/stderr
2088 ret=$?
2089 if [ $ret -ne 0 ]; then
2090 diff -u $testroot/stderr.expected $testroot/stderr
2092 test_done "$testroot" $ret
2095 test_histedit_resets_committer() {
2096 local testroot=`test_init histedit_resets_committer`
2097 local orig_commit=`git_show_head $testroot/repo`
2098 local committer="Flan Luck <flan_luck@openbsd.org>"
2100 got checkout $testroot/repo $testroot/wt > /dev/null
2102 echo "modified alpha" > $testroot/wt/alpha
2104 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2105 alpha > /dev/null)
2106 ret=$?
2107 if [ "$?" != 0 ]; then
2108 echo "got commit failed unexpectedly" >&2
2109 test_done "$testroot" "$ret"
2110 return 1
2113 local top_commit=`git_show_head $testroot/repo`
2114 echo "pick $top_commit" > "$testroot/histedit-script"
2116 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2117 ret=$?
2118 if [ "$?" != 0 ]; then
2119 echo "got update failed unexpectedly" >&2
2120 test_done "$testroot" "$ret"
2121 return 1
2124 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
2125 got histedit -F "$testroot/histedit-script" > /dev/null)
2126 ret=$?
2127 if [ "$?" != 0 ]; then
2128 echo "got histedit failed unexpectedly" >&2
2129 test_done "$testroot" "$ret"
2130 return 1
2132 local edited_commit=`git_show_head $testroot/repo`
2134 # Original commit only had one author
2135 (cd $testroot/repo && got log -l1 -c $top_commit | \
2136 egrep '^(from|via):' > $testroot/stdout)
2137 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2138 cmp -s $testroot/stdout.expected $testroot/stdout
2139 ret=$?
2140 if [ $ret -ne 0 ]; then
2141 diff -u $testroot/stdout.expected $testroot/stdout
2142 test_done "$testroot" "$ret"
2143 return 1
2146 # Edited commit should have new committer name added
2147 (cd $testroot/repo && got log -l1 -c $edited_commit | \
2148 egrep '^(from|via):' > $testroot/stdout)
2149 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2150 echo "via: $committer" >> $testroot/stdout.expected
2152 cmp -s $testroot/stdout.expected $testroot/stdout
2153 ret=$?
2154 if [ $ret -ne 0 ]; then
2155 diff -u $testroot/stdout.expected $testroot/stdout
2157 test_done "$testroot" "$ret"
2160 test_histedit_umask() {
2161 local testroot=`test_init histedit_umask`
2162 local orig_commit=`git_show_head "$testroot/repo"`
2164 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
2166 echo "modified alpha" > $testroot/wt/alpha
2167 (cd "$testroot/wt" && got commit -m 'edit #1') >/dev/null
2168 local commit1=`git_show_head "$testroot/repo"`
2170 echo "modified again" > $testroot/wt/alpha
2171 (cd "$testroot/wt" && got commit -m 'edit #2') >/dev/null
2172 local commit2=`git_show_head "$testroot/repo"`
2174 echo "modified again!" > $testroot/wt/alpha
2175 echo "modify beta too!" > $testroot/wt/beta
2176 (cd "$testroot/wt" && got commit -m 'edit #3') >/dev/null
2177 local commit3=`git_show_head "$testroot/repo"`
2179 (cd "$testroot/wt" && got update -c "$orig_commit") >/dev/null
2180 ret=$?
2181 if [ $ret -ne 0 ]; then
2182 echo "update to $orig_commit failed!" >&2
2183 test_done "$testroot" 1
2184 return 1
2187 echo fold $commit1 >$testroot/histedit-script
2188 echo fold $commit2 >>$testroot/histedit-script
2189 echo pick $commit3 >>$testroot/histedit-script
2190 echo mesg folding changes >>$testroot/histedit-script
2192 # using a subshell to avoid clobbering global umask
2193 (umask 077 && cd "$testroot/wt" && \
2194 got histedit -F "$testroot/histedit-script") >/dev/null
2195 ret=$?
2197 if [ $ret -ne 0 ]; then
2198 echo "histedit operation failed" >&2
2199 test_done "$testroot" $ret
2200 return 1
2203 for f in alpha beta; do
2204 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
2205 if [ $? -ne 0 ]; then
2206 echo "$f is not 0600 after histedi" >&2
2207 ls -l "$testroot/wt/$f" >&2
2208 test_done "$testroot" 1
2209 return 1
2211 done
2213 test_done "$testroot" 0
2216 test_histedit_mesg_filemode_change() {
2217 local testroot=`test_init histedit_mode_change`
2219 local orig_commit=`git_show_head $testroot/repo`
2220 local orig_author_time=`git_show_author_time $testroot/repo`
2222 chmod +x $testroot/repo/alpha
2223 git_commit $testroot/repo -m "set x bit on alpha"
2224 local old_commit1=`git_show_head $testroot/repo`
2225 local old_author_time1=`git_show_author_time $testroot/repo`
2227 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2228 ret=$?
2229 if [ $ret -ne 0 ]; then
2230 test_done "$testroot" "$ret"
2231 return 1
2234 if [ -x $testroot/wt/alpha ]; then
2235 echo "file alpha has unexpected executable bit" >&2
2236 test_done "$testroot" "1"
2237 return 1
2240 cat > $testroot/editor.sh <<EOF
2241 #!/bin/sh
2242 sed -i 's/ x bit / executable bit /' "\$1"
2243 EOF
2245 chmod +x $testroot/editor.sh
2247 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
2248 got histedit -m > $testroot/stdout)
2250 local new_commit1=`git_show_head $testroot/repo`
2251 local new_author_time1=`git_show_author_time $testroot/repo`
2253 local short_old_commit1=`trim_obj_id 28 $old_commit1`
2254 local short_new_commit1=`trim_obj_id 28 $new_commit1`
2256 echo "G alpha" > $testroot/stdout.expected
2257 echo "$short_old_commit1 -> $short_new_commit1: set executable bit on alpha" \
2258 >> $testroot/stdout.expected
2259 echo "Switching work tree to refs/heads/master" \
2260 >> $testroot/stdout.expected
2262 cmp -s $testroot/stdout.expected $testroot/stdout
2263 ret=$?
2264 if [ $ret -ne 0 ]; then
2265 diff -u $testroot/stdout.expected $testroot/stdout
2266 test_done "$testroot" "$ret"
2267 return 1
2270 echo "alpha" > $testroot/content.expected
2271 cmp -s $testroot/content.expected $testroot/wt/alpha
2272 ret=$?
2273 if [ $ret -ne 0 ]; then
2274 diff -u $testroot/content.expected $testroot/wt/alpha
2275 test_done "$testroot" "$ret"
2276 return 1
2279 if [ ! -x $testroot/wt/alpha ]; then
2280 echo "file alpha lost its executable bit" >&2
2281 test_done "$testroot" "1"
2282 return 1
2285 (cd $testroot/wt && got status > $testroot/stdout)
2287 echo -n > $testroot/stdout.expected
2288 cmp -s $testroot/stdout.expected $testroot/stdout
2289 ret=$?
2290 if [ $ret -ne 0 ]; then
2291 diff -u $testroot/stdout.expected $testroot/stdout
2292 test_done "$testroot" "$ret"
2293 return 1
2296 (cd $testroot/wt && got log -l1 | grep ' set executable bit on alpha' \
2297 > $testroot/stdout)
2299 echo ' set executable bit on alpha' > $testroot/stdout.expected
2300 cmp -s $testroot/stdout.expected $testroot/stdout
2301 ret=$?
2302 if [ $ret -ne 0 ]; then
2303 diff -u $testroot/stdout.expected $testroot/stdout
2304 test_done "$testroot" "$ret"
2305 return 1
2308 test_done "$testroot" "$ret"
2311 test_histedit_drop_only() {
2312 local testroot=`test_init histedit_drop_only`
2314 local orig_commit=`git_show_head $testroot/repo`
2315 local drop="-> drop commit:"
2316 local dropmsg="commit changes to drop"
2318 echo "modified alpha on master" > $testroot/repo/alpha
2319 (cd $testroot/repo && git rm -q beta)
2320 echo "new file on master" > $testroot/repo/epsilon/new
2321 (cd $testroot/repo && git add epsilon/new)
2323 git_commit $testroot/repo -m "$dropmsg 1"
2324 local drop_commit1=`git_show_head $testroot/repo`
2326 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2328 git_commit $testroot/repo -m "$dropmsg 2"
2329 local drop_commit2=`git_show_head $testroot/repo`
2331 echo "modified delta on master" > $testroot/repo/gamma/delta
2333 git_commit $testroot/repo -m "$dropmsg 3"
2334 local drop_commit3=`git_show_head $testroot/repo`
2336 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2337 ret=$?
2338 if [ $ret -ne 0 ]; then
2339 test_done "$testroot" "$ret"
2340 return 1
2343 (cd $testroot/wt && got histedit -d > $testroot/stdout)
2344 local new_commit1=`git_show_head $testroot/repo`
2346 local short_commit1=`trim_obj_id 28 $drop_commit1`
2347 local short_commit2=`trim_obj_id 28 $drop_commit2`
2348 local short_commit3=`trim_obj_id 28 $drop_commit3`
2350 echo "$short_commit1 $drop $dropmsg 1" > $testroot/stdout.expected
2351 echo "$short_commit2 $drop $dropmsg 2" >> $testroot/stdout.expected
2352 echo "$short_commit3 $drop $dropmsg 3" >> $testroot/stdout.expected
2353 echo "Switching work tree to refs/heads/master" \
2354 >> $testroot/stdout.expected
2356 cmp -s $testroot/stdout.expected $testroot/stdout
2357 ret=$?
2358 if [ $ret -ne 0 ]; then
2359 diff -u $testroot/stdout.expected $testroot/stdout
2360 test_done "$testroot" "$ret"
2361 return 1
2364 echo "alpha" > $testroot/content.expected
2365 cat $testroot/wt/alpha > $testroot/content
2366 cmp -s $testroot/content.expected $testroot/content
2367 ret=$?
2368 if [ $ret -ne 0 ]; then
2369 diff -u $testroot/content.expected $testroot/content
2370 test_done "$testroot" "$ret"
2371 return 1
2374 echo "zeta" > $testroot/content.expected
2375 cat $testroot/wt/epsilon/zeta > $testroot/content
2376 cmp -s $testroot/content.expected $testroot/content
2377 ret=$?
2378 if [ $ret -ne 0 ]; then
2379 diff -u $testroot/content.expected $testroot/content
2380 test_done "$testroot" "$ret"
2381 return 1
2384 echo "delta" > $testroot/content.expected
2385 cat $testroot/wt/gamma/delta > $testroot/content
2386 cmp -s $testroot/content.expected $testroot/content
2387 ret=$?
2388 if [ $ret -ne 0 ]; then
2389 diff -u $testroot/content.expected $testroot/content
2390 test_done "$testroot" "$ret"
2391 return 1
2394 if [ ! -e $testroot/wt/beta ]; then
2395 echo "removed file beta should be restored" >&2
2396 test_done "$testroot" "1"
2397 return 1
2400 if [ -e $testroot/wt/new ]; then
2401 echo "new file should no longer exist" >&2
2402 test_done "$testroot" "$ret"
2403 return 1
2406 (cd $testroot/wt && got status > $testroot/stdout)
2408 echo -n > $testroot/stdout.expected
2409 cmp -s $testroot/stdout.expected $testroot/stdout
2410 ret=$?
2411 if [ $ret -ne 0 ]; then
2412 diff -u $testroot/stdout.expected $testroot/stdout
2413 test_done "$testroot" "$ret"
2414 return 1
2417 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
2418 echo "commit $orig_commit (master)" > $testroot/stdout.expected
2419 cmp -s $testroot/stdout.expected $testroot/stdout
2420 ret=$?
2421 if [ $ret -ne 0 ]; then
2422 diff -u $testroot/stdout.expected $testroot/stdout
2424 test_done "$testroot" "$ret"
2427 test_parseargs "$@"
2428 run_test test_histedit_no_op
2429 run_test test_histedit_swap
2430 run_test test_histedit_drop
2431 run_test test_histedit_fold
2432 run_test test_histedit_edit
2433 run_test test_histedit_fold_last_commit
2434 run_test test_histedit_missing_commit
2435 run_test test_histedit_abort
2436 run_test test_histedit_path_prefix_drop
2437 run_test test_histedit_path_prefix_edit
2438 run_test test_histedit_outside_refs_heads
2439 run_test test_histedit_fold_last_commit_swap
2440 run_test test_histedit_split_commit
2441 run_test test_histedit_duplicate_commit_in_script
2442 run_test test_histedit_fold_add_delete
2443 run_test test_histedit_fold_only
2444 run_test test_histedit_fold_only_empty_logmsg
2445 run_test test_histedit_edit_only
2446 run_test test_histedit_prepend_line
2447 run_test test_histedit_mesg_invalid
2448 run_test test_histedit_resets_committer
2449 run_test test_histedit_umask
2450 run_test test_histedit_mesg_filemode_change
2451 run_test test_histedit_drop_only