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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "0" ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
150 test_done "$testroot" "$ret"
151 return 1
152 fi
154 # We should have a backup of old commits
155 (cd $testroot/repo && got histedit -l > $testroot/stdout)
156 d_orig1=`date -u -d "@$old_author_time1" +"%G-%m-%d"`
157 d_orig2=`env LC_TIME=C date -u -d "@$old_author_time2" +"%a %b %e %X %Y UTC"`
158 d_new2=`date -u -d "@$new_author_time2" +"%G-%m-%d"`
159 d_orig=`date -u -d "@$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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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
743 echo "mesg committing folded changes" >> $testroot/histedit-script
745 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
746 > $testroot/stdout 2> $testroot/stderr)
748 ret="$?"
749 if [ "$ret" = "0" ]; then
750 echo "histedit succeeded unexpectedly" >&2
751 test_done "$testroot" "1"
752 return 1
753 fi
755 echo "got: last commit in histedit script cannot be folded" \
756 > $testroot/stderr.expected
758 cmp -s $testroot/stderr.expected $testroot/stderr
759 ret="$?"
760 if [ "$ret" != "0" ]; then
761 diff -u $testroot/stderr.expected $testroot/stderr
762 fi
763 test_done "$testroot" "$ret"
766 test_histedit_missing_commit() {
767 local testroot=`test_init histedit_missing_commit`
769 local orig_commit=`git_show_head $testroot/repo`
771 echo "modified alpha on master" > $testroot/repo/alpha
772 (cd $testroot/repo && git rm -q beta)
773 echo "new file on master" > $testroot/repo/epsilon/new
774 (cd $testroot/repo && git add epsilon/new)
775 git_commit $testroot/repo -m "committing changes"
776 local old_commit1=`git_show_head $testroot/repo`
778 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
779 git_commit $testroot/repo -m "committing to zeta on master"
780 local old_commit2=`git_show_head $testroot/repo`
782 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
783 ret="$?"
784 if [ "$ret" != "0" ]; then
785 test_done "$testroot" "$ret"
786 return 1
787 fi
789 echo "pick $old_commit1" > $testroot/histedit-script
790 echo "mesg committing changes" >> $testroot/histedit-script
792 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
793 > $testroot/stdout 2> $testroot/stderr)
795 ret="$?"
796 if [ "$ret" = "0" ]; then
797 echo "histedit succeeded unexpectedly" >&2
798 test_done "$testroot" "1"
799 return 1
800 fi
802 echo "got: commit $old_commit2 missing from histedit script" \
803 > $testroot/stderr.expected
805 cmp -s $testroot/stderr.expected $testroot/stderr
806 ret="$?"
807 if [ "$ret" != "0" ]; then
808 diff -u $testroot/stderr.expected $testroot/stderr
809 fi
810 test_done "$testroot" "$ret"
813 test_histedit_abort() {
814 local testroot=`test_init histedit_abort`
816 local orig_commit=`git_show_head $testroot/repo`
818 echo "modified alpha on master" > $testroot/repo/alpha
819 (cd $testroot/repo && git rm -q beta)
820 echo "new file on master" > $testroot/repo/epsilon/new
821 (cd $testroot/repo && git add epsilon/new)
822 git_commit $testroot/repo -m "committing changes"
823 local old_commit1=`git_show_head $testroot/repo`
825 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
826 git_commit $testroot/repo -m "committing to zeta on master"
827 local old_commit2=`git_show_head $testroot/repo`
829 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
830 ret="$?"
831 if [ "$ret" != "0" ]; then
832 test_done "$testroot" "$ret"
833 return 1
834 fi
836 echo "edit $old_commit1" > $testroot/histedit-script
837 echo "mesg committing changes" >> $testroot/histedit-script
838 echo "pick $old_commit2" >> $testroot/histedit-script
840 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
841 > $testroot/stdout)
843 local short_old_commit1=`trim_obj_id 28 $old_commit1`
844 local short_old_commit2=`trim_obj_id 28 $old_commit2`
846 echo "G alpha" > $testroot/stdout.expected
847 echo "D beta" >> $testroot/stdout.expected
848 echo "A epsilon/new" >> $testroot/stdout.expected
849 echo "Stopping histedit for amending commit $old_commit1" \
850 >> $testroot/stdout.expected
851 cmp -s $testroot/stdout.expected $testroot/stdout
852 ret="$?"
853 if [ "$ret" != "0" ]; then
854 diff -u $testroot/stdout.expected $testroot/stdout
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 echo "edited modified alpha on master" > $testroot/wt/alpha
861 (cd $testroot/wt && got histedit -a > $testroot/stdout)
863 local new_commit1=`git_show_parent_commit $testroot/repo`
864 local new_commit2=`git_show_head $testroot/repo`
866 echo "Switching work tree to refs/heads/master" \
867 > $testroot/stdout.expected
868 echo "R alpha" >> $testroot/stdout.expected
869 echo "R beta" >> $testroot/stdout.expected
870 echo "R epsilon/new" >> $testroot/stdout.expected
871 echo "Histedit of refs/heads/master aborted" \
872 >> $testroot/stdout.expected
874 cmp -s $testroot/stdout.expected $testroot/stdout
875 ret="$?"
876 if [ "$ret" != "0" ]; then
877 diff -u $testroot/stdout.expected $testroot/stdout
878 test_done "$testroot" "$ret"
879 return 1
880 fi
882 for f in alpha beta; do
883 echo "$f" > $testroot/content.expected
884 cat $testroot/wt/$f > $testroot/content
885 cmp -s $testroot/content.expected $testroot/content
886 ret="$?"
887 if [ "$ret" != "0" ]; then
888 diff -u $testroot/content.expected $testroot/content
889 test_done "$testroot" "$ret"
890 return 1
891 fi
892 done
894 echo "new file on master" > $testroot/content.expected
895 cat $testroot/wt/epsilon/new > $testroot/content
896 cmp -s $testroot/content.expected $testroot/content
897 ret="$?"
898 if [ "$ret" != "0" ]; then
899 diff -u $testroot/content.expected $testroot/content
900 test_done "$testroot" "$ret"
901 return 1
902 fi
904 (cd $testroot/wt && got status > $testroot/stdout)
906 echo "? epsilon/new" > $testroot/stdout.expected
907 cmp -s $testroot/stdout.expected $testroot/stdout
908 ret="$?"
909 if [ "$ret" != "0" ]; then
910 diff -u $testroot/stdout.expected $testroot/stdout
911 test_done "$testroot" "$ret"
912 return 1
913 fi
915 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
916 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
917 echo "commit $new_commit1" >> $testroot/stdout.expected
918 echo "commit $orig_commit" >> $testroot/stdout.expected
919 cmp -s $testroot/stdout.expected $testroot/stdout
920 ret="$?"
921 if [ "$ret" != "0" ]; then
922 diff -u $testroot/stdout.expected $testroot/stdout
923 fi
924 test_done "$testroot" "$ret"
927 test_histedit_path_prefix_drop() {
928 local testroot=`test_init histedit_path_prefix_drop`
929 local orig_commit=`git_show_head $testroot/repo`
931 echo "modified zeta" > $testroot/repo/epsilon/zeta
932 git_commit $testroot/repo -m "changing zeta"
933 local old_commit1=`git_show_head $testroot/repo`
935 got checkout -c $orig_commit -p gamma $testroot/repo \
936 $testroot/wt > /dev/null
937 ret="$?"
938 if [ "$ret" != "0" ]; then
939 test_done "$testroot" "$ret"
940 return 1
941 fi
943 echo "drop $old_commit1" > $testroot/histedit-script
945 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
946 > $testroot/stdout 2> $testroot/stderr)
948 ret="$?"
949 if [ "$ret" = "0" ]; then
950 echo "histedit succeeded unexpectedly" >&2
951 test_done "$testroot" "1"
952 return 1
953 fi
955 echo -n "got: cannot edit branch history which contains changes " \
956 > $testroot/stderr.expected
957 echo "outside of this work tree's path prefix" \
958 >> $testroot/stderr.expected
960 cmp -s $testroot/stderr.expected $testroot/stderr
961 ret="$?"
962 if [ "$ret" != "0" ]; then
963 diff -u $testroot/stderr.expected $testroot/stderr
964 test_done "$testroot" "$ret"
965 return 1
966 fi
968 rm -rf $testroot/wt
969 got checkout -c $orig_commit -p epsilon $testroot/repo \
970 $testroot/wt > /dev/null
971 ret="$?"
972 if [ "$ret" != "0" ]; then
973 test_done "$testroot" "$ret"
974 return 1
975 fi
976 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
977 > $testroot/stdout)
979 local short_old_commit1=`trim_obj_id 28 $old_commit1`
980 local short_old_commit2=`trim_obj_id 28 $old_commit2`
982 echo "$short_old_commit1 -> drop commit: changing zeta" \
983 > $testroot/stdout.expected
984 echo "Switching work tree to refs/heads/master" \
985 >> $testroot/stdout.expected
987 cmp -s $testroot/stdout.expected $testroot/stdout
988 ret="$?"
989 if [ "$ret" != "0" ]; then
990 diff -u $testroot/stdout.expected $testroot/stdout
991 test_done "$testroot" "$ret"
992 return 1
993 fi
995 echo "zeta" > $testroot/content.expected
996 cat $testroot/wt/zeta > $testroot/content
997 cmp -s $testroot/content.expected $testroot/content
998 ret="$?"
999 if [ "$ret" != "0" ]; then
1000 diff -u $testroot/content.expected $testroot/content
1001 test_done "$testroot" "$ret"
1002 return 1
1006 (cd $testroot/wt && got status > $testroot/stdout)
1008 echo -n > $testroot/stdout.expected
1009 cmp -s $testroot/stdout.expected $testroot/stdout
1010 ret="$?"
1011 if [ "$ret" != "0" ]; then
1012 diff -u $testroot/stdout.expected $testroot/stdout
1013 test_done "$testroot" "$ret"
1014 return 1
1017 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1018 echo "commit $orig_commit (master)" > $testroot/stdout.expected
1019 cmp -s $testroot/stdout.expected $testroot/stdout
1020 ret="$?"
1021 if [ "$ret" != "0" ]; then
1022 diff -u $testroot/stdout.expected $testroot/stdout
1024 test_done "$testroot" "$ret"
1027 test_histedit_path_prefix_edit() {
1028 local testroot=`test_init histedit_path_prefix_edit`
1029 local orig_commit=`git_show_head $testroot/repo`
1031 echo "modified zeta" > $testroot/repo/epsilon/zeta
1032 git_commit $testroot/repo -m "changing zeta"
1033 local old_commit1=`git_show_head $testroot/repo`
1035 got diff -r $testroot/repo $orig_commit $old_commit1 \
1036 > $testroot/diff.expected
1038 got checkout -c $orig_commit -p gamma $testroot/repo \
1039 $testroot/wt > /dev/null
1040 ret="$?"
1041 if [ "$ret" != "0" ]; then
1042 test_done "$testroot" "$ret"
1043 return 1
1046 echo "edit $old_commit1" > $testroot/histedit-script
1047 echo "mesg modified zeta" >> $testroot/histedit-script
1049 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1050 > $testroot/stdout 2> $testroot/stderr)
1052 ret="$?"
1053 if [ "$ret" = "0" ]; then
1054 echo "histedit succeeded unexpectedly" >&2
1055 test_done "$testroot" "1"
1056 return 1
1059 echo -n "got: cannot edit branch history which contains changes " \
1060 > $testroot/stderr.expected
1061 echo "outside of this work tree's path prefix" \
1062 >> $testroot/stderr.expected
1064 cmp -s $testroot/stderr.expected $testroot/stderr
1065 ret="$?"
1066 if [ "$ret" != "0" ]; then
1067 diff -u $testroot/stderr.expected $testroot/stderr
1068 test_done "$testroot" "$ret"
1069 return 1
1072 rm -rf $testroot/wt
1073 got checkout -c $orig_commit -p epsilon $testroot/repo \
1074 $testroot/wt > /dev/null
1075 ret="$?"
1076 if [ "$ret" != "0" ]; then
1077 test_done "$testroot" "$ret"
1078 return 1
1080 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1081 > $testroot/stdout)
1083 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1085 echo "G zeta" > $testroot/stdout.expected
1086 echo "Stopping histedit for amending commit $old_commit1" \
1087 >> $testroot/stdout.expected
1088 cmp -s $testroot/stdout.expected $testroot/stdout
1089 ret="$?"
1090 if [ "$ret" != "0" ]; then
1091 diff -u $testroot/stdout.expected $testroot/stdout
1092 test_done "$testroot" "$ret"
1093 return 1
1096 echo "modified zeta" > $testroot/content.expected
1097 cat $testroot/wt/zeta > $testroot/content
1098 cmp -s $testroot/content.expected $testroot/content
1099 ret="$?"
1100 if [ "$ret" != "0" ]; then
1101 diff -u $testroot/content.expected $testroot/content
1102 test_done "$testroot" "$ret"
1103 return 1
1106 (cd $testroot/wt && got status > $testroot/stdout)
1108 echo "M zeta"> $testroot/stdout.expected
1109 cmp -s $testroot/stdout.expected $testroot/stdout
1110 ret="$?"
1111 if [ "$ret" != "0" ]; then
1112 diff -u $testroot/stdout.expected $testroot/stdout
1113 test_done "$testroot" "$ret"
1114 return 1
1117 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1119 local new_commit1=`git_show_head $testroot/repo`
1120 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1122 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1123 > $testroot/stdout.expected
1124 echo "modified zeta" >> $testroot/stdout.expected
1125 echo "Switching work tree to refs/heads/master" \
1126 >> $testroot/stdout.expected
1128 cmp -s $testroot/stdout.expected $testroot/stdout
1129 ret="$?"
1130 if [ "$ret" != "0" ]; then
1131 diff -u $testroot/stdout.expected $testroot/stdout
1132 test_done "$testroot" "$ret"
1133 return 1
1136 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1137 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1138 echo "commit $orig_commit" >> $testroot/stdout.expected
1139 cmp -s $testroot/stdout.expected $testroot/stdout
1140 ret="$?"
1141 if [ "$ret" != "0" ]; then
1142 diff -u $testroot/stdout.expected $testroot/stdout
1143 test_done "$testroot" "$ret"
1144 return 1
1147 got diff -r $testroot/repo $orig_commit $new_commit1 \
1148 > $testroot/diff
1149 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1150 cmp -s $testroot/diff.expected $testroot/diff
1151 ret="$?"
1152 if [ "$ret" != "0" ]; then
1153 diff -u $testroot/diff.expected $testroot/diff
1155 test_done "$testroot" "$ret"
1158 test_histedit_outside_refs_heads() {
1159 local testroot=`test_init histedit_outside_refs_heads`
1160 local commit1=`git_show_head $testroot/repo`
1162 got checkout $testroot/repo $testroot/wt > /dev/null
1163 ret="$?"
1164 if [ "$ret" != "0" ]; then
1165 echo "got checkout failed unexpectedly"
1166 test_done "$testroot" "$ret"
1167 return 1
1170 echo "modified alpha" > $testroot/wt/alpha
1172 (cd $testroot/wt && got commit -m 'change alpha' \
1173 > $testroot/stdout 2> $testroot/stderr)
1174 ret="$?"
1175 if [ "$ret" != "0" ]; then
1176 echo "got commit failed unexpectedly" >&2
1177 test_done "$testroot" "1"
1178 return 1
1180 local commit2=`git_show_head $testroot/repo`
1182 got ref -r $testroot/repo -c master refs/remotes/origin/master
1183 ret="$?"
1184 if [ "$ret" != "0" ]; then
1185 echo "got ref failed unexpectedly" >&2
1186 test_done "$testroot" "1"
1187 return 1
1190 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1191 ret="$?"
1192 if [ "$ret" != "0" ]; then
1193 echo "got update failed unexpectedly"
1194 test_done "$testroot" "$ret"
1195 return 1
1198 echo "edit $commit2" > $testroot/histedit-script
1199 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1200 2> $testroot/stderr)
1202 echo -n "got: will not edit commit history of a branch outside the " \
1203 > $testroot/stderr.expected
1204 echo '"refs/heads/" reference namespace' \
1205 >> $testroot/stderr.expected
1206 cmp -s $testroot/stderr.expected $testroot/stderr
1207 ret="$?"
1208 if [ "$ret" != "0" ]; then
1209 diff -u $testroot/stderr.expected $testroot/stderr
1211 test_done "$testroot" "$ret"
1214 test_histedit_fold_last_commit_swap() {
1215 local testroot=`test_init histedit_fold_last_commit_swap`
1217 local orig_commit=`git_show_head $testroot/repo`
1219 echo "modified alpha on master" > $testroot/repo/alpha
1220 (cd $testroot/repo && git rm -q beta)
1221 echo "new file on master" > $testroot/repo/epsilon/new
1222 (cd $testroot/repo && git add epsilon/new)
1223 git_commit $testroot/repo -m "committing changes"
1224 local old_commit1=`git_show_head $testroot/repo`
1226 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1227 git_commit $testroot/repo -m "committing to zeta on master"
1228 local old_commit2=`git_show_head $testroot/repo`
1230 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1231 ret="$?"
1232 if [ "$ret" != "0" ]; then
1233 test_done "$testroot" "$ret"
1234 return 1
1237 # fold commit2 into commit1 (requires swapping commits)
1238 echo "fold $old_commit2" > $testroot/histedit-script
1239 echo "pick $old_commit1" >> $testroot/histedit-script
1240 echo "mesg committing folded changes" >> $testroot/histedit-script
1242 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1243 > $testroot/stdout 2> $testroot/stderr)
1245 ret="$?"
1246 if [ "$ret" != "0" ]; then
1247 echo "histedit failed unexpectedly" >&2
1248 test_done "$testroot" "$ret"
1249 return 1
1252 local new_commit=`git_show_head $testroot/repo`
1254 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1255 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1256 local short_new_commit=`trim_obj_id 28 $new_commit`
1258 echo "G epsilon/zeta" >> $testroot/stdout.expected
1259 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1260 >> $testroot/stdout.expected
1261 echo "on master" >> $testroot/stdout.expected
1262 echo "G alpha" >> $testroot/stdout.expected
1263 echo "D beta" >> $testroot/stdout.expected
1264 echo "A epsilon/new" >> $testroot/stdout.expected
1265 echo -n "$short_old_commit1 -> $short_new_commit: " \
1266 >> $testroot/stdout.expected
1267 echo "committing folded changes" >> $testroot/stdout.expected
1268 echo "Switching work tree to refs/heads/master" \
1269 >> $testroot/stdout.expected
1271 cmp -s $testroot/stdout.expected $testroot/stdout
1272 ret="$?"
1273 if [ "$ret" != "0" ]; then
1274 diff -u $testroot/stdout.expected $testroot/stdout
1276 test_done "$testroot" "$ret"
1279 test_histedit_split_commit() {
1280 local testroot=`test_init histedit_split_commit`
1282 local orig_commit=`git_show_head $testroot/repo`
1284 echo "modified alpha on master" > $testroot/repo/alpha
1285 (cd $testroot/repo && git rm -q beta)
1286 echo "new file on master" > $testroot/repo/epsilon/new
1287 (cd $testroot/repo && git add epsilon/new)
1288 git_commit $testroot/repo -m "committing changes 1"
1289 local old_commit1=`git_show_head $testroot/repo`
1290 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1292 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1293 git_commit $testroot/repo -m "committing changes 2"
1294 local old_commit2=`git_show_head $testroot/repo`
1295 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1297 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1298 ret="$?"
1299 if [ "$ret" != "0" ]; then
1300 test_done "$testroot" "$ret"
1301 return 1
1304 # split commit1 into commitA and commitB and commitC
1305 echo "e $old_commit1" > $testroot/histedit-script
1306 echo "p $old_commit2" >> $testroot/histedit-script
1308 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1309 > $testroot/stdout 2> $testroot/stderr)
1310 ret="$?"
1311 if [ "$ret" != "0" ]; then
1312 echo "histedit failed unexpectedly:" >&2
1313 cat $testroot/stderr >&2
1314 test_done "$testroot" "$ret"
1315 return 1
1318 echo "G alpha" > $testroot/stdout.expected
1319 echo "D beta" >> $testroot/stdout.expected
1320 echo "A epsilon/new" >> $testroot/stdout.expected
1321 echo "Stopping histedit for amending commit $old_commit1" \
1322 >> $testroot/stdout.expected
1324 cmp -s $testroot/stdout.expected $testroot/stdout
1325 ret="$?"
1326 if [ "$ret" != "0" ]; then
1327 diff -u $testroot/stdout.expected $testroot/stdout
1328 test_done "$testroot" "$ret"
1329 return 1
1332 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1333 ret="$?"
1334 if [ "$ret" != "0" ]; then
1335 echo "commit failed unexpectedly" >&2
1336 test_done "$testroot" "$ret"
1337 return 1
1340 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1341 ret="$?"
1342 if [ "$ret" != "0" ]; then
1343 echo "commit failed unexpectedly" >&2
1344 test_done "$testroot" "$ret"
1345 return 1
1348 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1349 ret="$?"
1350 if [ "$ret" != "0" ]; then
1351 echo "commit failed unexpectedly" >&2
1352 test_done "$testroot" "$ret"
1353 return 1
1356 (cd $testroot/wt && got histedit -c \
1357 > $testroot/stdout 2> $testroot/stderr)
1358 ret="$?"
1359 if [ "$ret" != "0" ]; then
1360 echo "histedit failed unexpectedly:" >&2
1361 cat $testroot/stderr >&2
1362 test_done "$testroot" "$ret"
1363 return 1
1365 local new_commit2=`git_show_head $testroot/repo`
1366 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1368 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1369 > $testroot/stdout.expected
1370 echo "G epsilon/zeta" >> $testroot/stdout.expected
1371 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1372 >> $testroot/stdout.expected
1373 echo "Switching work tree to refs/heads/master" \
1374 >> $testroot/stdout.expected
1376 cmp -s $testroot/stdout.expected $testroot/stdout
1377 ret="$?"
1378 if [ "$ret" != "0" ]; then
1379 diff -u $testroot/stdout.expected $testroot/stdout
1381 test_done "$testroot" "$ret"
1385 test_histedit_duplicate_commit_in_script() {
1386 local testroot=`test_init histedit_duplicate_commit_in_script`
1388 local orig_commit=`git_show_head $testroot/repo`
1390 echo "modified alpha on master" > $testroot/repo/alpha
1391 (cd $testroot/repo && git rm -q beta)
1392 echo "new file on master" > $testroot/repo/epsilon/new
1393 (cd $testroot/repo && git add epsilon/new)
1394 git_commit $testroot/repo -m "committing changes 1"
1395 local old_commit1=`git_show_head $testroot/repo`
1397 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1398 git_commit $testroot/repo -m "committing changes 2"
1399 local old_commit2=`git_show_head $testroot/repo`
1401 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1402 ret="$?"
1403 if [ "$ret" != "0" ]; then
1404 test_done "$testroot" "$ret"
1405 return 1
1408 # This histedit script lists commit1 more than once
1409 echo "p $old_commit1" > $testroot/histedit-script
1410 echo "p $old_commit1" >> $testroot/histedit-script
1411 echo "p $old_commit2" >> $testroot/histedit-script
1413 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1414 > $testroot/stdout 2> $testroot/stderr)
1415 ret="$?"
1416 if [ "$ret" = "0" ]; then
1417 echo "histedit succeeded unexpectedly:" >&2
1418 cat $testroot/stdout >&2
1419 test_done "$testroot" "$ret"
1420 return 1
1423 echo -n "got: commit $old_commit1 is listed more than once " \
1424 > $testroot/stderr.expected
1425 echo "in histedit script" >> $testroot/stderr.expected
1427 cmp -s $testroot/stderr.expected $testroot/stderr
1428 ret="$?"
1429 if [ "$ret" != "0" ]; then
1430 diff -u $testroot/stderr.expected $testroot/stderr
1432 test_done "$testroot" "$ret"
1436 # if a previous commit introduces a new file, and it is folded into a commit
1437 # that deletes the same file, the file still exists after the histedit
1438 test_histedit_fold_add_delete() {
1439 local testroot=`test_init histedit_fold_add_delete`
1441 local orig_commit=`git_show_head $testroot/repo`
1443 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1444 (cd $testroot/repo && git add epsilon/psi)
1445 git_commit $testroot/repo -m "committing changes"
1446 local old_commit1=`git_show_head $testroot/repo`
1448 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1449 git_commit $testroot/repo -m "editing psi"
1450 local old_commit2=`git_show_head $testroot/repo`
1452 (cd $testroot/repo && git rm -q epsilon/psi)
1453 git_commit $testroot/repo -m "removing psi"
1454 local old_commit3=`git_show_head $testroot/repo`
1456 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1457 ret="$?"
1458 if [ "$ret" != "0" ]; then
1459 test_done "$testroot" "$ret"
1460 return 1
1463 echo "fold $old_commit1" > $testroot/histedit-script
1464 echo "fold $old_commit2" >> $testroot/histedit-script
1465 echo "pick $old_commit3" >> $testroot/histedit-script
1466 echo "mesg folded changes" >> $testroot/histedit-script
1468 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1469 > $testroot/stdout)
1471 local new_commit1=`git_show_head $testroot/repo`
1473 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1474 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1475 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1476 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1478 echo "A epsilon/psi" >> $testroot/stdout.expected
1479 echo "$short_old_commit1 -> fold commit: committing changes" \
1480 >> $testroot/stdout.expected
1481 echo "G epsilon/psi" >> $testroot/stdout.expected
1482 echo "$short_old_commit2 -> fold commit: editing psi" \
1483 >> $testroot/stdout.expected
1484 echo "D epsilon/psi" >> $testroot/stdout.expected
1485 echo "$short_old_commit3 -> no-op change: folded changes" \
1486 >> $testroot/stdout.expected
1487 echo "Switching work tree to refs/heads/master" \
1488 >> $testroot/stdout.expected
1490 cmp -s $testroot/stdout.expected $testroot/stdout
1491 ret="$?"
1492 if [ "$ret" != "0" ]; then
1493 diff -u $testroot/stdout.expected $testroot/stdout
1494 test_done "$testroot" "$ret"
1495 return 1
1498 if [ -e $testroot/wt/epsilon/psi ]; then
1499 echo "removed file psi still exists on disk" >&2
1500 test_done "$testroot" "1"
1501 return 1
1504 (cd $testroot/wt && got status > $testroot/stdout)
1506 echo -n > $testroot/stdout.expected
1507 cmp -s $testroot/stdout.expected $testroot/stdout
1508 ret="$?"
1509 if [ "$ret" != "0" ]; then
1510 diff -u $testroot/stdout.expected $testroot/stdout
1511 test_done "$testroot" "$ret"
1512 return 1
1515 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1516 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1517 cmp -s $testroot/stdout.expected $testroot/stdout
1518 ret="$?"
1519 if [ "$ret" != "0" ]; then
1520 diff -u $testroot/stdout.expected $testroot/stdout
1521 test_done "$testroot" "$ret"
1522 return 1
1525 got tree -r $testroot/repo epsilon > $testroot/stdout
1526 echo "zeta" > $testroot/stdout.expected
1527 cmp -s $testroot/stdout.expected $testroot/stdout
1528 ret="$?"
1529 if [ "$ret" != "0" ]; then
1530 diff -u $testroot/stdout.expected $testroot/stdout
1532 test_done "$testroot" "$ret"
1535 test_histedit_fold_only() {
1536 local testroot=`test_init histedit_fold_only`
1538 local orig_commit=`git_show_head $testroot/repo`
1540 echo "modified alpha on master" > $testroot/repo/alpha
1541 (cd $testroot/repo && git rm -q beta)
1542 echo "new file on master" > $testroot/repo/epsilon/new
1543 (cd $testroot/repo && git add epsilon/new)
1544 git_commit $testroot/repo -m "committing changes"
1545 local old_commit1=`git_show_head $testroot/repo`
1547 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1548 git_commit $testroot/repo -m "committing to zeta on master"
1549 local old_commit2=`git_show_head $testroot/repo`
1551 echo "modified delta on master" > $testroot/repo/gamma/delta
1552 git_commit $testroot/repo -m "committing to delta on master"
1553 local old_commit3=`git_show_head $testroot/repo`
1555 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1556 ret="$?"
1557 if [ "$ret" != "0" ]; then
1558 test_done "$testroot" "$ret"
1559 return 1
1562 cat > $testroot/editor.sh <<EOF
1563 #!/bin/sh
1564 sed -i 's/.*/committing folded changes/' "\$1"
1565 EOF
1566 chmod +x $testroot/editor.sh
1568 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1569 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1571 local new_commit1=`git_show_head $testroot/repo`
1573 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1574 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1575 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1576 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1577 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1579 echo "G alpha" > $testroot/stdout.expected
1580 echo "D beta" >> $testroot/stdout.expected
1581 echo "A epsilon/new" >> $testroot/stdout.expected
1582 echo "$short_old_commit1 -> fold commit: committing changes" \
1583 >> $testroot/stdout.expected
1584 echo "G epsilon/zeta" >> $testroot/stdout.expected
1585 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1586 echo "fold commit: committing to zeta on master" \
1587 >> $testroot/stdout.expected
1588 echo "G gamma/delta" >> $testroot/stdout.expected
1589 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1590 >> $testroot/stdout.expected
1591 echo "committing folded changes" >> $testroot/stdout.expected
1592 echo "Switching work tree to refs/heads/master" \
1593 >> $testroot/stdout.expected
1595 cmp -s $testroot/stdout.expected $testroot/stdout
1596 ret="$?"
1597 if [ "$ret" != "0" ]; then
1598 diff -u $testroot/stdout.expected $testroot/stdout
1599 test_done "$testroot" "$ret"
1600 return 1
1603 echo "modified alpha on master" > $testroot/content.expected
1604 cat $testroot/wt/alpha > $testroot/content
1605 cmp -s $testroot/content.expected $testroot/content
1606 ret="$?"
1607 if [ "$ret" != "0" ]; then
1608 diff -u $testroot/content.expected $testroot/content
1609 test_done "$testroot" "$ret"
1610 return 1
1613 if [ -e $testroot/wt/beta ]; then
1614 echo "removed file beta still exists on disk" >&2
1615 test_done "$testroot" "1"
1616 return 1
1619 echo "new file on master" > $testroot/content.expected
1620 cat $testroot/wt/epsilon/new > $testroot/content
1621 cmp -s $testroot/content.expected $testroot/content
1622 ret="$?"
1623 if [ "$ret" != "0" ]; then
1624 diff -u $testroot/content.expected $testroot/content
1625 test_done "$testroot" "$ret"
1626 return 1
1629 (cd $testroot/wt && got status > $testroot/stdout)
1631 echo -n > $testroot/stdout.expected
1632 cmp -s $testroot/stdout.expected $testroot/stdout
1633 ret="$?"
1634 if [ "$ret" != "0" ]; then
1635 diff -u $testroot/stdout.expected $testroot/stdout
1636 test_done "$testroot" "$ret"
1637 return 1
1640 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1641 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1642 echo "commit $orig_commit" >> $testroot/stdout.expected
1643 cmp -s $testroot/stdout.expected $testroot/stdout
1644 ret="$?"
1645 if [ "$ret" != "0" ]; then
1646 diff -u $testroot/stdout.expected $testroot/stdout
1648 test_done "$testroot" "$ret"
1651 test_histedit_fold_only_empty_logmsg() {
1652 local testroot=`test_init histedit_fold_only_empty_logmsg`
1654 local orig_commit=`git_show_head $testroot/repo`
1656 echo "modified alpha on master" > $testroot/repo/alpha
1657 (cd $testroot/repo && git rm -q beta)
1658 echo "new file on master" > $testroot/repo/epsilon/new
1659 (cd $testroot/repo && git add epsilon/new)
1660 git_commit $testroot/repo -m "committing changes"
1661 local old_commit1=`git_show_head $testroot/repo`
1663 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1664 git_commit $testroot/repo -m "committing to zeta on master"
1665 local old_commit2=`git_show_head $testroot/repo`
1667 echo "modified delta on master" > $testroot/repo/gamma/delta
1668 git_commit $testroot/repo -m "committing to delta on master"
1669 local old_commit3=`git_show_head $testroot/repo`
1671 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1672 ret="$?"
1673 if [ "$ret" != "0" ]; then
1674 test_done "$testroot" "$ret"
1675 return 1
1678 cat > $testroot/editor.sh <<EOF
1679 #!/bin/sh
1680 sed -i 'd' "\$1"
1681 EOF
1682 chmod +x $testroot/editor.sh
1684 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1685 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1687 local new_commit1=`git_show_head $testroot/repo`
1689 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1690 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1691 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1692 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1693 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1694 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1696 echo "G alpha" > $testroot/stdout.expected
1697 echo "D beta" >> $testroot/stdout.expected
1698 echo "A epsilon/new" >> $testroot/stdout.expected
1699 echo "$short_old_commit1 -> fold commit: committing changes" \
1700 >> $testroot/stdout.expected
1701 echo "G epsilon/zeta" >> $testroot/stdout.expected
1702 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1703 echo "fold commit: committing to zeta on master" \
1704 >> $testroot/stdout.expected
1705 echo "G gamma/delta" >> $testroot/stdout.expected
1706 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1707 >> $testroot/stdout.expected
1708 echo "# log message of folded commit $very_short_old_commit1" \
1709 >> $testroot/stdout.expected
1710 echo "Switching work tree to refs/heads/master" \
1711 >> $testroot/stdout.expected
1713 cmp -s $testroot/stdout.expected $testroot/stdout
1714 ret="$?"
1715 if [ "$ret" != "0" ]; then
1716 diff -u $testroot/stdout.expected $testroot/stdout
1717 test_done "$testroot" "$ret"
1718 return 1
1721 echo "modified alpha on master" > $testroot/content.expected
1722 cat $testroot/wt/alpha > $testroot/content
1723 cmp -s $testroot/content.expected $testroot/content
1724 ret="$?"
1725 if [ "$ret" != "0" ]; then
1726 diff -u $testroot/content.expected $testroot/content
1727 test_done "$testroot" "$ret"
1728 return 1
1731 if [ -e $testroot/wt/beta ]; then
1732 echo "removed file beta still exists on disk" >&2
1733 test_done "$testroot" "1"
1734 return 1
1737 echo "new file on master" > $testroot/content.expected
1738 cat $testroot/wt/epsilon/new > $testroot/content
1739 cmp -s $testroot/content.expected $testroot/content
1740 ret="$?"
1741 if [ "$ret" != "0" ]; then
1742 diff -u $testroot/content.expected $testroot/content
1743 test_done "$testroot" "$ret"
1744 return 1
1747 (cd $testroot/wt && got status > $testroot/stdout)
1749 echo -n > $testroot/stdout.expected
1750 cmp -s $testroot/stdout.expected $testroot/stdout
1751 ret="$?"
1752 if [ "$ret" != "0" ]; then
1753 diff -u $testroot/stdout.expected $testroot/stdout
1754 test_done "$testroot" "$ret"
1755 return 1
1758 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1759 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1760 echo "commit $orig_commit" >> $testroot/stdout.expected
1761 cmp -s $testroot/stdout.expected $testroot/stdout
1762 ret="$?"
1763 if [ "$ret" != "0" ]; then
1764 diff -u $testroot/stdout.expected $testroot/stdout
1766 test_done "$testroot" "$ret"
1769 test_parseargs "$@"
1770 run_test test_histedit_no_op
1771 run_test test_histedit_swap
1772 run_test test_histedit_drop
1773 run_test test_histedit_fold
1774 run_test test_histedit_edit
1775 run_test test_histedit_fold_last_commit
1776 run_test test_histedit_missing_commit
1777 run_test test_histedit_abort
1778 run_test test_histedit_path_prefix_drop
1779 run_test test_histedit_path_prefix_edit
1780 run_test test_histedit_outside_refs_heads
1781 run_test test_histedit_fold_last_commit_swap
1782 run_test test_histedit_split_commit
1783 run_test test_histedit_duplicate_commit_in_script
1784 run_test test_histedit_fold_add_delete
1785 run_test test_histedit_fold_only
1786 run_test test_histedit_fold_only_empty_logmsg