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`
32 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
33 git_commit $testroot/repo -m "committing to zeta on master"
34 local old_commit2=`git_show_head $testroot/repo`
35 local old_author_time2=`git_show_author_time $testroot/repo`
37 got diff -r $testroot/repo $orig_commit $old_commit2 \
38 > $testroot/diff.expected
40 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
41 ret="$?"
42 if [ "$ret" != "0" ]; then
43 test_done "$testroot" "$ret"
44 return 1
45 fi
47 echo "pick $old_commit1" > $testroot/histedit-script
48 echo "pick $old_commit2" >> $testroot/histedit-script
50 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
51 > $testroot/stdout)
53 local new_commit1=`git_show_parent_commit $testroot/repo`
54 local new_commit2=`git_show_head $testroot/repo`
55 local new_author_time2=`git_show_author_time $testroot/repo`
57 local short_old_commit1=`trim_obj_id 28 $old_commit1`
58 local short_old_commit2=`trim_obj_id 28 $old_commit2`
59 local short_new_commit1=`trim_obj_id 28 $new_commit1`
60 local short_new_commit2=`trim_obj_id 28 $new_commit2`
62 echo "G alpha" > $testroot/stdout.expected
63 echo "D beta" >> $testroot/stdout.expected
64 echo "A epsilon/new" >> $testroot/stdout.expected
65 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
66 >> $testroot/stdout.expected
67 echo "G epsilon/zeta" >> $testroot/stdout.expected
68 echo -n "$short_old_commit2 -> $short_new_commit2: " \
69 >> $testroot/stdout.expected
70 echo "committing to zeta on master" >> $testroot/stdout.expected
71 echo "Switching work tree to refs/heads/master" \
72 >> $testroot/stdout.expected
74 cmp -s $testroot/stdout.expected $testroot/stdout
75 ret="$?"
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 echo "modified alpha on master" > $testroot/content.expected
83 cat $testroot/wt/alpha > $testroot/content
84 cmp -s $testroot/content.expected $testroot/content
85 ret="$?"
86 if [ "$ret" != "0" ]; then
87 diff -u $testroot/content.expected $testroot/content
88 test_done "$testroot" "$ret"
89 return 1
90 fi
92 if [ -e $testroot/wt/beta ]; then
93 echo "removed file beta still exists on disk" >&2
94 test_done "$testroot" "1"
95 return 1
96 fi
98 echo "new file on master" > $testroot/content.expected
99 cat $testroot/wt/epsilon/new > $testroot/content
100 cmp -s $testroot/content.expected $testroot/content
101 ret="$?"
102 if [ "$ret" != "0" ]; then
103 diff -u $testroot/content.expected $testroot/content
104 test_done "$testroot" "$ret"
105 return 1
106 fi
108 (cd $testroot/wt && got status > $testroot/stdout)
110 echo -n > $testroot/stdout.expected
111 cmp -s $testroot/stdout.expected $testroot/stdout
112 ret="$?"
113 if [ "$ret" != "0" ]; then
114 diff -u $testroot/stdout.expected $testroot/stdout
115 test_done "$testroot" "$ret"
116 return 1
117 fi
119 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
120 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
121 echo "commit $new_commit1" >> $testroot/stdout.expected
122 echo "commit $orig_commit" >> $testroot/stdout.expected
123 cmp -s $testroot/stdout.expected $testroot/stdout
124 ret="$?"
125 if [ "$ret" != "0" ]; then
126 diff -u $testroot/stdout.expected $testroot/stdout
127 test_done "$testroot" "$ret"
128 return 1
129 fi
131 got diff -r $testroot/repo $orig_commit $new_commit2 \
132 > $testroot/diff
133 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
134 cmp -s $testroot/diff.expected $testroot/diff
135 ret="$?"
136 if [ "$ret" != "0" ]; then
137 diff -u $testroot/diff.expected $testroot/diff
138 test_done "$testroot" "$ret"
139 return 1
140 fi
142 (cd $testroot/wt && got update > $testroot/stdout)
144 echo 'Already up-to-date' > $testroot/stdout.expected
145 cmp -s $testroot/stdout.expected $testroot/stdout
146 ret="$?"
147 if [ "$ret" != "0" ]; then
148 diff -u $testroot/stdout.expected $testroot/stdout
149 test_done "$testroot" "$ret"
150 return 1
151 fi
153 # We should have a backup of old commits
154 (cd $testroot/repo && got histedit -l > $testroot/stdout)
155 d_orig2=`date -u -r $old_author_time2 +"%a %b %e %X %Y UTC"`
156 d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
157 d_orig=`date -u -r $orig_author_time +"%G-%m-%d"`
158 cat > $testroot/stdout.expected <<EOF
159 -----------------------------------------------
160 commit $old_commit2 (formerly master)
161 from: $GOT_AUTHOR
162 date: $d_orig2
164 committing to zeta on master
166 has become commit $new_commit2 (master)
167 $d_new2 $GOT_AUTHOR_11 committing to zeta on master
168 history forked at $orig_commit
169 $d_orig $GOT_AUTHOR_11 adding the test tree
170 EOF
171 cmp -s $testroot/stdout.expected $testroot/stdout
172 ret="$?"
173 if [ "$ret" != "0" ]; then
174 diff -u $testroot/stdout.expected $testroot/stdout
175 test_done "$testroot" "$ret"
176 return 1
177 fi
179 (cd $testroot/repo && got histedit -X master \
180 > $testroot/stdout 2> $testroot/stderr)
181 echo -n "Deleted refs/got/backup/histedit/master/$new_commit2: " \
182 > $testroot/stdout.expected
183 echo "$old_commit2" >> $testroot/stdout.expected
184 echo -n > $testroot/stderr.expected
185 cmp -s $testroot/stdout.expected $testroot/stdout
186 ret="$?"
187 if [ "$ret" != "0" ]; then
188 diff -u $testroot/stdout.expected $testroot/stdout
189 test_done "$testroot" "$ret"
190 return 1
191 fi
192 cmp -s $testroot/stderr.expected $testroot/stderr
193 ret="$?"
194 if [ "$ret" != "0" ]; then
195 diff -u $testroot/stderr.expected $testroot/stderr
196 test_done "$testroot" "$ret"
197 return 1
198 fi
200 (cd $testroot/repo && got histedit -l > $testroot/stdout)
201 echo -n > $testroot/stdout.expected
202 cmp -s $testroot/stdout.expected $testroot/stdout
203 ret="$?"
204 if [ "$ret" != "0" ]; then
205 diff -u $testroot/stdout.expected $testroot/stdout
206 fi
207 test_done "$testroot" "$ret"
210 test_histedit_swap() {
211 local testroot=`test_init histedit_swap`
213 local orig_commit=`git_show_head $testroot/repo`
215 echo "modified alpha on master" > $testroot/repo/alpha
216 (cd $testroot/repo && git rm -q beta)
217 echo "new file on master" > $testroot/repo/epsilon/new
218 (cd $testroot/repo && git add epsilon/new)
219 git_commit $testroot/repo -m "committing changes"
220 local old_commit1=`git_show_head $testroot/repo`
222 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
223 git_commit $testroot/repo -m "committing to zeta on master"
224 local old_commit2=`git_show_head $testroot/repo`
226 got diff -r $testroot/repo $orig_commit $old_commit2 \
227 > $testroot/diff.expected
229 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
230 ret="$?"
231 if [ "$ret" != "0" ]; then
232 test_done "$testroot" "$ret"
233 return 1
234 fi
236 echo "pick $old_commit2" > $testroot/histedit-script
237 echo "pick $old_commit1" >> $testroot/histedit-script
239 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
240 > $testroot/stdout)
242 local new_commit2=`git_show_parent_commit $testroot/repo`
243 local new_commit1=`git_show_head $testroot/repo`
245 local short_old_commit1=`trim_obj_id 28 $old_commit1`
246 local short_old_commit2=`trim_obj_id 28 $old_commit2`
247 local short_new_commit1=`trim_obj_id 28 $new_commit1`
248 local short_new_commit2=`trim_obj_id 28 $new_commit2`
250 echo "G epsilon/zeta" > $testroot/stdout.expected
251 echo -n "$short_old_commit2 -> $short_new_commit2: " \
252 >> $testroot/stdout.expected
253 echo "committing to zeta on master" >> $testroot/stdout.expected
254 echo "G alpha" >> $testroot/stdout.expected
255 echo "D beta" >> $testroot/stdout.expected
256 echo "A epsilon/new" >> $testroot/stdout.expected
257 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
258 >> $testroot/stdout.expected
259 echo "Switching work tree to refs/heads/master" \
260 >> $testroot/stdout.expected
262 cmp -s $testroot/stdout.expected $testroot/stdout
263 ret="$?"
264 if [ "$ret" != "0" ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 echo "modified alpha on master" > $testroot/content.expected
271 cat $testroot/wt/alpha > $testroot/content
272 cmp -s $testroot/content.expected $testroot/content
273 ret="$?"
274 if [ "$ret" != "0" ]; then
275 diff -u $testroot/content.expected $testroot/content
276 test_done "$testroot" "$ret"
277 return 1
278 fi
280 if [ -e $testroot/wt/beta ]; then
281 echo "removed file beta still exists on disk" >&2
282 test_done "$testroot" "1"
283 return 1
284 fi
286 echo "new file on master" > $testroot/content.expected
287 cat $testroot/wt/epsilon/new > $testroot/content
288 cmp -s $testroot/content.expected $testroot/content
289 ret="$?"
290 if [ "$ret" != "0" ]; then
291 diff -u $testroot/content.expected $testroot/content
292 test_done "$testroot" "$ret"
293 return 1
294 fi
296 (cd $testroot/wt && got status > $testroot/stdout)
298 echo -n > $testroot/stdout.expected
299 cmp -s $testroot/stdout.expected $testroot/stdout
300 ret="$?"
301 if [ "$ret" != "0" ]; then
302 diff -u $testroot/stdout.expected $testroot/stdout
303 test_done "$testroot" "$ret"
304 return 1
305 fi
307 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
308 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
309 echo "commit $new_commit2" >> $testroot/stdout.expected
310 echo "commit $orig_commit" >> $testroot/stdout.expected
311 cmp -s $testroot/stdout.expected $testroot/stdout
312 ret="$?"
313 if [ "$ret" != "0" ]; then
314 diff -u $testroot/stdout.expected $testroot/stdout
315 test_done "$testroot" "$ret"
316 return 1
317 fi
319 got diff -r $testroot/repo $orig_commit $new_commit1 \
320 > $testroot/diff
321 sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
322 cmp -s $testroot/diff.expected $testroot/diff
323 ret="$?"
324 if [ "$ret" != "0" ]; then
325 diff -u $testroot/diff.expected $testroot/diff
326 fi
327 test_done "$testroot" "$ret"
330 test_histedit_drop() {
331 local testroot=`test_init histedit_drop`
332 local orig_commit=`git_show_head $testroot/repo`
334 echo "modified alpha on master" > $testroot/repo/alpha
335 (cd $testroot/repo && git rm -q beta)
336 echo "new file on master" > $testroot/repo/epsilon/new
337 (cd $testroot/repo && git add epsilon/new)
338 git_commit $testroot/repo -m "committing changes"
339 local old_commit1=`git_show_head $testroot/repo`
341 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
342 git_commit $testroot/repo -m "committing to zeta on master"
343 local old_commit2=`git_show_head $testroot/repo`
345 got diff -r $testroot/repo $old_commit1 $old_commit2 \
346 > $testroot/diff.expected
348 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
349 ret="$?"
350 if [ "$ret" != "0" ]; then
351 test_done "$testroot" "$ret"
352 return 1
353 fi
355 echo "drop $old_commit1" > $testroot/histedit-script
356 echo "pick $old_commit2" >> $testroot/histedit-script
358 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
359 > $testroot/stdout)
361 local new_commit2=`git_show_head $testroot/repo`
363 local short_old_commit1=`trim_obj_id 28 $old_commit1`
364 local short_old_commit2=`trim_obj_id 28 $old_commit2`
365 local short_new_commit2=`trim_obj_id 28 $new_commit2`
367 echo "$short_old_commit1 -> drop commit: committing changes" \
368 > $testroot/stdout.expected
369 echo "G epsilon/zeta" >> $testroot/stdout.expected
370 echo -n "$short_old_commit2 -> $short_new_commit2: " \
371 >> $testroot/stdout.expected
372 echo "committing to zeta on master" >> $testroot/stdout.expected
373 echo "Switching work tree to refs/heads/master" \
374 >> $testroot/stdout.expected
376 cmp -s $testroot/stdout.expected $testroot/stdout
377 ret="$?"
378 if [ "$ret" != "0" ]; then
379 diff -u $testroot/stdout.expected $testroot/stdout
380 test_done "$testroot" "$ret"
381 return 1
382 fi
384 for f in alpha beta; do
385 echo "$f" > $testroot/content.expected
386 cat $testroot/wt/$f > $testroot/content
387 cmp -s $testroot/content.expected $testroot/content
388 ret="$?"
389 if [ "$ret" != "0" ]; then
390 diff -u $testroot/content.expected $testroot/content
391 test_done "$testroot" "$ret"
392 return 1
393 fi
394 done
396 if [ -e $testroot/wt/new ]; then
397 echo "file new exists on disk but should not" >&2
398 test_done "$testroot" "1"
399 return 1
400 fi
402 (cd $testroot/wt && got status > $testroot/stdout)
404 echo -n > $testroot/stdout.expected
405 cmp -s $testroot/stdout.expected $testroot/stdout
406 ret="$?"
407 if [ "$ret" != "0" ]; then
408 diff -u $testroot/stdout.expected $testroot/stdout
409 test_done "$testroot" "$ret"
410 return 1
411 fi
413 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
414 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
415 echo "commit $orig_commit" >> $testroot/stdout.expected
416 cmp -s $testroot/stdout.expected $testroot/stdout
417 ret="$?"
418 if [ "$ret" != "0" ]; then
419 diff -u $testroot/stdout.expected $testroot/stdout
420 test_done "$testroot" "$ret"
421 return 1
422 fi
424 got diff -r $testroot/repo $orig_commit $new_commit2 \
425 > $testroot/diff
426 sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
427 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
428 cmp -s $testroot/diff.expected $testroot/diff
429 ret="$?"
430 if [ "$ret" != "0" ]; then
431 diff -u $testroot/diff.expected $testroot/diff
432 fi
433 test_done "$testroot" "$ret"
436 test_histedit_fold() {
437 local testroot=`test_init histedit_fold`
439 local orig_commit=`git_show_head $testroot/repo`
441 echo "modified alpha on master" > $testroot/repo/alpha
442 (cd $testroot/repo && git rm -q beta)
443 echo "new file on master" > $testroot/repo/epsilon/new
444 (cd $testroot/repo && git add epsilon/new)
445 git_commit $testroot/repo -m "committing changes"
446 local old_commit1=`git_show_head $testroot/repo`
448 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
449 git_commit $testroot/repo -m "committing to zeta on master"
450 local old_commit2=`git_show_head $testroot/repo`
452 echo "modified delta on master" > $testroot/repo/gamma/delta
453 git_commit $testroot/repo -m "committing to delta on master"
454 local old_commit3=`git_show_head $testroot/repo`
456 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
457 ret="$?"
458 if [ "$ret" != "0" ]; then
459 test_done "$testroot" "$ret"
460 return 1
461 fi
463 echo "fold $old_commit1" > $testroot/histedit-script
464 echo "drop $old_commit2" >> $testroot/histedit-script
465 echo "pick $old_commit3" >> $testroot/histedit-script
466 echo "mesg committing folded changes" >> $testroot/histedit-script
468 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
469 > $testroot/stdout)
471 local new_commit1=`git_show_parent_commit $testroot/repo`
472 local new_commit2=`git_show_head $testroot/repo`
474 local short_old_commit1=`trim_obj_id 28 $old_commit1`
475 local short_old_commit2=`trim_obj_id 28 $old_commit2`
476 local short_old_commit3=`trim_obj_id 28 $old_commit3`
477 local short_new_commit1=`trim_obj_id 28 $new_commit1`
478 local short_new_commit2=`trim_obj_id 28 $new_commit2`
480 echo "G alpha" > $testroot/stdout.expected
481 echo "D beta" >> $testroot/stdout.expected
482 echo "A epsilon/new" >> $testroot/stdout.expected
483 echo "$short_old_commit1 -> fold commit: committing changes" \
484 >> $testroot/stdout.expected
485 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
486 echo "drop commit: committing to zeta on master" \
487 >> $testroot/stdout.expected
488 echo "G gamma/delta" >> $testroot/stdout.expected
489 echo -n "$short_old_commit3 -> $short_new_commit2: " \
490 >> $testroot/stdout.expected
491 echo "committing folded changes" >> $testroot/stdout.expected
492 echo "Switching work tree to refs/heads/master" \
493 >> $testroot/stdout.expected
495 cmp -s $testroot/stdout.expected $testroot/stdout
496 ret="$?"
497 if [ "$ret" != "0" ]; then
498 diff -u $testroot/stdout.expected $testroot/stdout
499 test_done "$testroot" "$ret"
500 return 1
501 fi
503 echo "modified alpha on master" > $testroot/content.expected
504 cat $testroot/wt/alpha > $testroot/content
505 cmp -s $testroot/content.expected $testroot/content
506 ret="$?"
507 if [ "$ret" != "0" ]; then
508 diff -u $testroot/content.expected $testroot/content
509 test_done "$testroot" "$ret"
510 return 1
511 fi
513 if [ -e $testroot/wt/beta ]; then
514 echo "removed file beta still exists on disk" >&2
515 test_done "$testroot" "1"
516 return 1
517 fi
519 echo "new file on master" > $testroot/content.expected
520 cat $testroot/wt/epsilon/new > $testroot/content
521 cmp -s $testroot/content.expected $testroot/content
522 ret="$?"
523 if [ "$ret" != "0" ]; then
524 diff -u $testroot/content.expected $testroot/content
525 test_done "$testroot" "$ret"
526 return 1
527 fi
529 (cd $testroot/wt && got status > $testroot/stdout)
531 echo -n > $testroot/stdout.expected
532 cmp -s $testroot/stdout.expected $testroot/stdout
533 ret="$?"
534 if [ "$ret" != "0" ]; then
535 diff -u $testroot/stdout.expected $testroot/stdout
536 test_done "$testroot" "$ret"
537 return 1
538 fi
540 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
541 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
542 echo "commit $orig_commit" >> $testroot/stdout.expected
543 cmp -s $testroot/stdout.expected $testroot/stdout
544 ret="$?"
545 if [ "$ret" != "0" ]; then
546 diff -u $testroot/stdout.expected $testroot/stdout
547 fi
548 test_done "$testroot" "$ret"
551 test_histedit_edit() {
552 local testroot=`test_init histedit_edit`
554 local orig_commit=`git_show_head $testroot/repo`
556 echo "modified alpha on master" > $testroot/repo/alpha
557 (cd $testroot/repo && git rm -q beta)
558 echo "new file on master" > $testroot/repo/epsilon/new
559 (cd $testroot/repo && git add epsilon/new)
560 git_commit $testroot/repo -m "committing changes"
561 local old_commit1=`git_show_head $testroot/repo`
563 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
564 git_commit $testroot/repo -m "committing to zeta on master"
565 local old_commit2=`git_show_head $testroot/repo`
567 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
568 ret="$?"
569 if [ "$ret" != "0" ]; then
570 test_done "$testroot" "$ret"
571 return 1
572 fi
574 echo "edit $old_commit1" > $testroot/histedit-script
575 echo "mesg committing changes" >> $testroot/histedit-script
576 echo "pick $old_commit2" >> $testroot/histedit-script
578 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
579 > $testroot/stdout)
581 local short_old_commit1=`trim_obj_id 28 $old_commit1`
582 local short_old_commit2=`trim_obj_id 28 $old_commit2`
584 echo "G alpha" > $testroot/stdout.expected
585 echo "D beta" >> $testroot/stdout.expected
586 echo "A epsilon/new" >> $testroot/stdout.expected
587 echo "Stopping histedit for amending commit $old_commit1" \
588 >> $testroot/stdout.expected
589 cmp -s $testroot/stdout.expected $testroot/stdout
590 ret="$?"
591 if [ "$ret" != "0" ]; then
592 diff -u $testroot/stdout.expected $testroot/stdout
593 test_done "$testroot" "$ret"
594 return 1
595 fi
597 echo "edited modified alpha on master" > $testroot/wt/alpha
599 # test interaction of 'got stage' and histedit -c
600 (cd $testroot/wt && got stage alpha > /dev/null)
601 (cd $testroot/wt && got histedit -c > $testroot/stdout \
602 2> $testroot/stderr)
603 ret="$?"
604 if [ "$ret" = "0" ]; then
605 echo "histedit succeeded unexpectedly" >&2
606 test_done "$testroot" "1"
607 return 1
608 fi
609 echo -n "got: work tree contains files with staged changes; " \
610 > $testroot/stderr.expected
611 echo "these changes must be committed or unstaged first" \
612 >> $testroot/stderr.expected
613 cmp -s $testroot/stderr.expected $testroot/stderr
614 ret="$?"
615 if [ "$ret" != "0" ]; then
616 diff -u $testroot/stderr.expected $testroot/stderr
617 test_done "$testroot" "$ret"
618 return 1
619 fi
621 (cd $testroot/wt && got unstage alpha > /dev/null)
622 (cd $testroot/wt && got histedit -c > $testroot/stdout)
624 local new_commit1=`git_show_parent_commit $testroot/repo`
625 local new_commit2=`git_show_head $testroot/repo`
627 local short_new_commit1=`trim_obj_id 28 $new_commit1`
628 local short_new_commit2=`trim_obj_id 28 $new_commit2`
630 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
631 > $testroot/stdout.expected
632 echo "G epsilon/zeta" >> $testroot/stdout.expected
633 echo -n "$short_old_commit2 -> $short_new_commit2: " \
634 >> $testroot/stdout.expected
635 echo "committing to zeta on master" >> $testroot/stdout.expected
636 echo "Switching work tree to refs/heads/master" \
637 >> $testroot/stdout.expected
639 cmp -s $testroot/stdout.expected $testroot/stdout
640 ret="$?"
641 if [ "$ret" != "0" ]; then
642 diff -u $testroot/stdout.expected $testroot/stdout
643 test_done "$testroot" "$ret"
644 return 1
645 fi
647 echo "edited modified alpha on master" > $testroot/content.expected
648 cat $testroot/wt/alpha > $testroot/content
649 cmp -s $testroot/content.expected $testroot/content
650 ret="$?"
651 if [ "$ret" != "0" ]; then
652 diff -u $testroot/content.expected $testroot/content
653 test_done "$testroot" "$ret"
654 return 1
655 fi
657 if [ -e $testroot/wt/beta ]; then
658 echo "removed file beta still exists on disk" >&2
659 test_done "$testroot" "1"
660 return 1
661 fi
663 echo "new file on master" > $testroot/content.expected
664 cat $testroot/wt/epsilon/new > $testroot/content
665 cmp -s $testroot/content.expected $testroot/content
666 ret="$?"
667 if [ "$ret" != "0" ]; then
668 diff -u $testroot/content.expected $testroot/content
669 test_done "$testroot" "$ret"
670 return 1
671 fi
673 (cd $testroot/wt && got status > $testroot/stdout)
675 echo -n > $testroot/stdout.expected
676 cmp -s $testroot/stdout.expected $testroot/stdout
677 ret="$?"
678 if [ "$ret" != "0" ]; then
679 diff -u $testroot/stdout.expected $testroot/stdout
680 test_done "$testroot" "$ret"
681 return 1
682 fi
684 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
685 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
686 echo "commit $new_commit1" >> $testroot/stdout.expected
687 echo "commit $orig_commit" >> $testroot/stdout.expected
688 cmp -s $testroot/stdout.expected $testroot/stdout
689 ret="$?"
690 if [ "$ret" != "0" ]; then
691 diff -u $testroot/stdout.expected $testroot/stdout
692 fi
693 test_done "$testroot" "$ret"
696 test_histedit_fold_last_commit() {
697 local testroot=`test_init histedit_fold_last_commit`
699 local orig_commit=`git_show_head $testroot/repo`
701 echo "modified alpha on master" > $testroot/repo/alpha
702 (cd $testroot/repo && git rm -q beta)
703 echo "new file on master" > $testroot/repo/epsilon/new
704 (cd $testroot/repo && git add epsilon/new)
705 git_commit $testroot/repo -m "committing changes"
706 local old_commit1=`git_show_head $testroot/repo`
708 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
709 git_commit $testroot/repo -m "committing to zeta on master"
710 local old_commit2=`git_show_head $testroot/repo`
712 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
713 ret="$?"
714 if [ "$ret" != "0" ]; then
715 test_done "$testroot" "$ret"
716 return 1
717 fi
719 echo "pick $old_commit1" > $testroot/histedit-script
720 echo "fold $old_commit2" >> $testroot/histedit-script
721 echo "mesg committing folded changes" >> $testroot/histedit-script
723 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
724 > $testroot/stdout 2> $testroot/stderr)
726 ret="$?"
727 if [ "$ret" = "0" ]; then
728 echo "histedit succeeded unexpectedly" >&2
729 test_done "$testroot" "1"
730 return 1
731 fi
733 echo "got: last commit in histedit script cannot be folded" \
734 > $testroot/stderr.expected
736 cmp -s $testroot/stderr.expected $testroot/stderr
737 ret="$?"
738 if [ "$ret" != "0" ]; then
739 diff -u $testroot/stderr.expected $testroot/stderr
740 fi
741 test_done "$testroot" "$ret"
744 test_histedit_missing_commit() {
745 local testroot=`test_init histedit_missing_commit`
747 local orig_commit=`git_show_head $testroot/repo`
749 echo "modified alpha on master" > $testroot/repo/alpha
750 (cd $testroot/repo && git rm -q beta)
751 echo "new file on master" > $testroot/repo/epsilon/new
752 (cd $testroot/repo && git add epsilon/new)
753 git_commit $testroot/repo -m "committing changes"
754 local old_commit1=`git_show_head $testroot/repo`
756 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
757 git_commit $testroot/repo -m "committing to zeta on master"
758 local old_commit2=`git_show_head $testroot/repo`
760 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
761 ret="$?"
762 if [ "$ret" != "0" ]; then
763 test_done "$testroot" "$ret"
764 return 1
765 fi
767 echo "pick $old_commit1" > $testroot/histedit-script
768 echo "mesg committing changes" >> $testroot/histedit-script
770 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
771 > $testroot/stdout 2> $testroot/stderr)
773 ret="$?"
774 if [ "$ret" = "0" ]; then
775 echo "histedit succeeded unexpectedly" >&2
776 test_done "$testroot" "1"
777 return 1
778 fi
780 echo "got: commit $old_commit2 missing from histedit script" \
781 > $testroot/stderr.expected
783 cmp -s $testroot/stderr.expected $testroot/stderr
784 ret="$?"
785 if [ "$ret" != "0" ]; then
786 diff -u $testroot/stderr.expected $testroot/stderr
787 fi
788 test_done "$testroot" "$ret"
791 test_histedit_abort() {
792 local testroot=`test_init histedit_abort`
794 local orig_commit=`git_show_head $testroot/repo`
796 echo "modified alpha on master" > $testroot/repo/alpha
797 (cd $testroot/repo && git rm -q beta)
798 echo "new file on master" > $testroot/repo/epsilon/new
799 (cd $testroot/repo && git add epsilon/new)
800 git_commit $testroot/repo -m "committing changes"
801 local old_commit1=`git_show_head $testroot/repo`
803 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
804 git_commit $testroot/repo -m "committing to zeta on master"
805 local old_commit2=`git_show_head $testroot/repo`
807 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
808 ret="$?"
809 if [ "$ret" != "0" ]; then
810 test_done "$testroot" "$ret"
811 return 1
812 fi
814 echo "edit $old_commit1" > $testroot/histedit-script
815 echo "mesg committing changes" >> $testroot/histedit-script
816 echo "pick $old_commit2" >> $testroot/histedit-script
818 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
819 > $testroot/stdout)
821 local short_old_commit1=`trim_obj_id 28 $old_commit1`
822 local short_old_commit2=`trim_obj_id 28 $old_commit2`
824 echo "G alpha" > $testroot/stdout.expected
825 echo "D beta" >> $testroot/stdout.expected
826 echo "A epsilon/new" >> $testroot/stdout.expected
827 echo "Stopping histedit for amending commit $old_commit1" \
828 >> $testroot/stdout.expected
829 cmp -s $testroot/stdout.expected $testroot/stdout
830 ret="$?"
831 if [ "$ret" != "0" ]; then
832 diff -u $testroot/stdout.expected $testroot/stdout
833 test_done "$testroot" "$ret"
834 return 1
835 fi
837 echo "edited modified alpha on master" > $testroot/wt/alpha
839 (cd $testroot/wt && got histedit -a > $testroot/stdout)
841 local new_commit1=`git_show_parent_commit $testroot/repo`
842 local new_commit2=`git_show_head $testroot/repo`
844 echo "Switching work tree to refs/heads/master" \
845 > $testroot/stdout.expected
846 echo "R alpha" >> $testroot/stdout.expected
847 echo "R beta" >> $testroot/stdout.expected
848 echo "R epsilon/new" >> $testroot/stdout.expected
849 echo "Histedit of refs/heads/master aborted" \
850 >> $testroot/stdout.expected
852 cmp -s $testroot/stdout.expected $testroot/stdout
853 ret="$?"
854 if [ "$ret" != "0" ]; then
855 diff -u $testroot/stdout.expected $testroot/stdout
856 test_done "$testroot" "$ret"
857 return 1
858 fi
860 for f in alpha beta; do
861 echo "$f" > $testroot/content.expected
862 cat $testroot/wt/$f > $testroot/content
863 cmp -s $testroot/content.expected $testroot/content
864 ret="$?"
865 if [ "$ret" != "0" ]; then
866 diff -u $testroot/content.expected $testroot/content
867 test_done "$testroot" "$ret"
868 return 1
869 fi
870 done
872 echo "new file on master" > $testroot/content.expected
873 cat $testroot/wt/epsilon/new > $testroot/content
874 cmp -s $testroot/content.expected $testroot/content
875 ret="$?"
876 if [ "$ret" != "0" ]; then
877 diff -u $testroot/content.expected $testroot/content
878 test_done "$testroot" "$ret"
879 return 1
880 fi
882 (cd $testroot/wt && got status > $testroot/stdout)
884 echo "? epsilon/new" > $testroot/stdout.expected
885 cmp -s $testroot/stdout.expected $testroot/stdout
886 ret="$?"
887 if [ "$ret" != "0" ]; then
888 diff -u $testroot/stdout.expected $testroot/stdout
889 test_done "$testroot" "$ret"
890 return 1
891 fi
893 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
894 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
895 echo "commit $new_commit1" >> $testroot/stdout.expected
896 echo "commit $orig_commit" >> $testroot/stdout.expected
897 cmp -s $testroot/stdout.expected $testroot/stdout
898 ret="$?"
899 if [ "$ret" != "0" ]; then
900 diff -u $testroot/stdout.expected $testroot/stdout
901 fi
902 test_done "$testroot" "$ret"
905 test_histedit_path_prefix_drop() {
906 local testroot=`test_init histedit_path_prefix_drop`
907 local orig_commit=`git_show_head $testroot/repo`
909 echo "modified zeta" > $testroot/repo/epsilon/zeta
910 git_commit $testroot/repo -m "changing zeta"
911 local old_commit1=`git_show_head $testroot/repo`
913 got checkout -c $orig_commit -p gamma $testroot/repo \
914 $testroot/wt > /dev/null
915 ret="$?"
916 if [ "$ret" != "0" ]; then
917 test_done "$testroot" "$ret"
918 return 1
919 fi
921 echo "drop $old_commit1" > $testroot/histedit-script
923 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
924 > $testroot/stdout 2> $testroot/stderr)
926 ret="$?"
927 if [ "$ret" = "0" ]; then
928 echo "histedit succeeded unexpectedly" >&2
929 test_done "$testroot" "1"
930 return 1
931 fi
933 echo -n "got: cannot edit branch history which contains changes " \
934 > $testroot/stderr.expected
935 echo "outside of this work tree's path prefix" \
936 >> $testroot/stderr.expected
938 cmp -s $testroot/stderr.expected $testroot/stderr
939 ret="$?"
940 if [ "$ret" != "0" ]; then
941 diff -u $testroot/stderr.expected $testroot/stderr
942 test_done "$testroot" "$ret"
943 return 1
944 fi
946 rm -rf $testroot/wt
947 got checkout -c $orig_commit -p epsilon $testroot/repo \
948 $testroot/wt > /dev/null
949 ret="$?"
950 if [ "$ret" != "0" ]; then
951 test_done "$testroot" "$ret"
952 return 1
953 fi
954 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
955 > $testroot/stdout)
957 local short_old_commit1=`trim_obj_id 28 $old_commit1`
958 local short_old_commit2=`trim_obj_id 28 $old_commit2`
960 echo "$short_old_commit1 -> drop commit: changing zeta" \
961 > $testroot/stdout.expected
962 echo "Switching work tree to refs/heads/master" \
963 >> $testroot/stdout.expected
965 cmp -s $testroot/stdout.expected $testroot/stdout
966 ret="$?"
967 if [ "$ret" != "0" ]; then
968 diff -u $testroot/stdout.expected $testroot/stdout
969 test_done "$testroot" "$ret"
970 return 1
971 fi
973 echo "zeta" > $testroot/content.expected
974 cat $testroot/wt/zeta > $testroot/content
975 cmp -s $testroot/content.expected $testroot/content
976 ret="$?"
977 if [ "$ret" != "0" ]; then
978 diff -u $testroot/content.expected $testroot/content
979 test_done "$testroot" "$ret"
980 return 1
981 fi
984 (cd $testroot/wt && got status > $testroot/stdout)
986 echo -n > $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 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
996 echo "commit $orig_commit (master)" > $testroot/stdout.expected
997 cmp -s $testroot/stdout.expected $testroot/stdout
998 ret="$?"
999 if [ "$ret" != "0" ]; then
1000 diff -u $testroot/stdout.expected $testroot/stdout
1002 test_done "$testroot" "$ret"
1005 test_histedit_path_prefix_edit() {
1006 local testroot=`test_init histedit_path_prefix_edit`
1007 local orig_commit=`git_show_head $testroot/repo`
1009 echo "modified zeta" > $testroot/repo/epsilon/zeta
1010 git_commit $testroot/repo -m "changing zeta"
1011 local old_commit1=`git_show_head $testroot/repo`
1013 got diff -r $testroot/repo $orig_commit $old_commit1 \
1014 > $testroot/diff.expected
1016 got checkout -c $orig_commit -p gamma $testroot/repo \
1017 $testroot/wt > /dev/null
1018 ret="$?"
1019 if [ "$ret" != "0" ]; then
1020 test_done "$testroot" "$ret"
1021 return 1
1024 echo "edit $old_commit1" > $testroot/histedit-script
1025 echo "mesg modified zeta" >> $testroot/histedit-script
1027 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1028 > $testroot/stdout 2> $testroot/stderr)
1030 ret="$?"
1031 if [ "$ret" = "0" ]; then
1032 echo "histedit succeeded unexpectedly" >&2
1033 test_done "$testroot" "1"
1034 return 1
1037 echo -n "got: cannot edit branch history which contains changes " \
1038 > $testroot/stderr.expected
1039 echo "outside of this work tree's path prefix" \
1040 >> $testroot/stderr.expected
1042 cmp -s $testroot/stderr.expected $testroot/stderr
1043 ret="$?"
1044 if [ "$ret" != "0" ]; then
1045 diff -u $testroot/stderr.expected $testroot/stderr
1046 test_done "$testroot" "$ret"
1047 return 1
1050 rm -rf $testroot/wt
1051 got checkout -c $orig_commit -p epsilon $testroot/repo \
1052 $testroot/wt > /dev/null
1053 ret="$?"
1054 if [ "$ret" != "0" ]; then
1055 test_done "$testroot" "$ret"
1056 return 1
1058 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1059 > $testroot/stdout)
1061 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1063 echo "G zeta" > $testroot/stdout.expected
1064 echo "Stopping histedit for amending commit $old_commit1" \
1065 >> $testroot/stdout.expected
1066 cmp -s $testroot/stdout.expected $testroot/stdout
1067 ret="$?"
1068 if [ "$ret" != "0" ]; then
1069 diff -u $testroot/stdout.expected $testroot/stdout
1070 test_done "$testroot" "$ret"
1071 return 1
1074 echo "modified zeta" > $testroot/content.expected
1075 cat $testroot/wt/zeta > $testroot/content
1076 cmp -s $testroot/content.expected $testroot/content
1077 ret="$?"
1078 if [ "$ret" != "0" ]; then
1079 diff -u $testroot/content.expected $testroot/content
1080 test_done "$testroot" "$ret"
1081 return 1
1084 (cd $testroot/wt && got status > $testroot/stdout)
1086 echo "M zeta"> $testroot/stdout.expected
1087 cmp -s $testroot/stdout.expected $testroot/stdout
1088 ret="$?"
1089 if [ "$ret" != "0" ]; then
1090 diff -u $testroot/stdout.expected $testroot/stdout
1091 test_done "$testroot" "$ret"
1092 return 1
1095 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1097 local new_commit1=`git_show_head $testroot/repo`
1098 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1100 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1101 > $testroot/stdout.expected
1102 echo "modified zeta" >> $testroot/stdout.expected
1103 echo "Switching work tree to refs/heads/master" \
1104 >> $testroot/stdout.expected
1106 cmp -s $testroot/stdout.expected $testroot/stdout
1107 ret="$?"
1108 if [ "$ret" != "0" ]; then
1109 diff -u $testroot/stdout.expected $testroot/stdout
1110 test_done "$testroot" "$ret"
1111 return 1
1114 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1115 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1116 echo "commit $orig_commit" >> $testroot/stdout.expected
1117 cmp -s $testroot/stdout.expected $testroot/stdout
1118 ret="$?"
1119 if [ "$ret" != "0" ]; then
1120 diff -u $testroot/stdout.expected $testroot/stdout
1121 test_done "$testroot" "$ret"
1122 return 1
1125 got diff -r $testroot/repo $orig_commit $new_commit1 \
1126 > $testroot/diff
1127 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1128 cmp -s $testroot/diff.expected $testroot/diff
1129 ret="$?"
1130 if [ "$ret" != "0" ]; then
1131 diff -u $testroot/diff.expected $testroot/diff
1133 test_done "$testroot" "$ret"
1136 test_histedit_outside_refs_heads() {
1137 local testroot=`test_init histedit_outside_refs_heads`
1138 local commit1=`git_show_head $testroot/repo`
1140 got checkout $testroot/repo $testroot/wt > /dev/null
1141 ret="$?"
1142 if [ "$ret" != "0" ]; then
1143 echo "got checkout failed unexpectedly"
1144 test_done "$testroot" "$ret"
1145 return 1
1148 echo "modified alpha" > $testroot/wt/alpha
1150 (cd $testroot/wt && got commit -m 'change alpha' \
1151 > $testroot/stdout 2> $testroot/stderr)
1152 ret="$?"
1153 if [ "$ret" != "0" ]; then
1154 echo "got commit failed unexpectedly" >&2
1155 test_done "$testroot" "1"
1156 return 1
1158 local commit2=`git_show_head $testroot/repo`
1160 got ref -r $testroot/repo -c master refs/remotes/origin/master
1161 ret="$?"
1162 if [ "$ret" != "0" ]; then
1163 echo "got ref failed unexpectedly" >&2
1164 test_done "$testroot" "1"
1165 return 1
1168 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1169 ret="$?"
1170 if [ "$ret" != "0" ]; then
1171 echo "got update failed unexpectedly"
1172 test_done "$testroot" "$ret"
1173 return 1
1176 echo "edit $commit2" > $testroot/histedit-script
1177 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1178 2> $testroot/stderr)
1180 echo -n "got: will not edit commit history of a branch outside the " \
1181 > $testroot/stderr.expected
1182 echo '"refs/heads/" reference namespace' \
1183 >> $testroot/stderr.expected
1184 cmp -s $testroot/stderr.expected $testroot/stderr
1185 ret="$?"
1186 if [ "$ret" != "0" ]; then
1187 diff -u $testroot/stderr.expected $testroot/stderr
1189 test_done "$testroot" "$ret"
1192 test_histedit_fold_last_commit_swap() {
1193 local testroot=`test_init histedit_fold_last_commit_swap`
1195 local orig_commit=`git_show_head $testroot/repo`
1197 echo "modified alpha on master" > $testroot/repo/alpha
1198 (cd $testroot/repo && git rm -q beta)
1199 echo "new file on master" > $testroot/repo/epsilon/new
1200 (cd $testroot/repo && git add epsilon/new)
1201 git_commit $testroot/repo -m "committing changes"
1202 local old_commit1=`git_show_head $testroot/repo`
1204 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1205 git_commit $testroot/repo -m "committing to zeta on master"
1206 local old_commit2=`git_show_head $testroot/repo`
1208 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1209 ret="$?"
1210 if [ "$ret" != "0" ]; then
1211 test_done "$testroot" "$ret"
1212 return 1
1215 # fold commit2 into commit1 (requires swapping commits)
1216 echo "fold $old_commit2" > $testroot/histedit-script
1217 echo "pick $old_commit1" >> $testroot/histedit-script
1218 echo "mesg committing folded changes" >> $testroot/histedit-script
1220 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1221 > $testroot/stdout 2> $testroot/stderr)
1223 ret="$?"
1224 if [ "$ret" != "0" ]; then
1225 echo "histedit failed unexpectedly" >&2
1226 test_done "$testroot" "$ret"
1227 return 1
1230 local new_commit=`git_show_head $testroot/repo`
1232 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1233 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1234 local short_new_commit=`trim_obj_id 28 $new_commit`
1236 echo "G epsilon/zeta" >> $testroot/stdout.expected
1237 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1238 >> $testroot/stdout.expected
1239 echo "on master" >> $testroot/stdout.expected
1240 echo "G alpha" >> $testroot/stdout.expected
1241 echo "D beta" >> $testroot/stdout.expected
1242 echo "A epsilon/new" >> $testroot/stdout.expected
1243 echo -n "$short_old_commit1 -> $short_new_commit: " \
1244 >> $testroot/stdout.expected
1245 echo "committing folded changes" >> $testroot/stdout.expected
1246 echo "Switching work tree to refs/heads/master" \
1247 >> $testroot/stdout.expected
1249 cmp -s $testroot/stdout.expected $testroot/stdout
1250 ret="$?"
1251 if [ "$ret" != "0" ]; then
1252 diff -u $testroot/stdout.expected $testroot/stdout
1254 test_done "$testroot" "$ret"
1257 test_histedit_split_commit() {
1258 local testroot=`test_init histedit_split_commit`
1260 local orig_commit=`git_show_head $testroot/repo`
1262 echo "modified alpha on master" > $testroot/repo/alpha
1263 (cd $testroot/repo && git rm -q beta)
1264 echo "new file on master" > $testroot/repo/epsilon/new
1265 (cd $testroot/repo && git add epsilon/new)
1266 git_commit $testroot/repo -m "committing changes 1"
1267 local old_commit1=`git_show_head $testroot/repo`
1268 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1270 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1271 git_commit $testroot/repo -m "committing changes 2"
1272 local old_commit2=`git_show_head $testroot/repo`
1273 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1275 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1276 ret="$?"
1277 if [ "$ret" != "0" ]; then
1278 test_done "$testroot" "$ret"
1279 return 1
1282 # split commit1 into commitA and commitB and commitC
1283 echo "e $old_commit1" > $testroot/histedit-script
1284 echo "p $old_commit2" >> $testroot/histedit-script
1286 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1287 > $testroot/stdout 2> $testroot/stderr)
1288 ret="$?"
1289 if [ "$ret" != "0" ]; then
1290 echo "histedit failed unexpectedly:" >&2
1291 cat $testroot/stderr >&2
1292 test_done "$testroot" "$ret"
1293 return 1
1296 echo "G alpha" > $testroot/stdout.expected
1297 echo "D beta" >> $testroot/stdout.expected
1298 echo "A epsilon/new" >> $testroot/stdout.expected
1299 echo "Stopping histedit for amending commit $old_commit1" \
1300 >> $testroot/stdout.expected
1302 cmp -s $testroot/stdout.expected $testroot/stdout
1303 ret="$?"
1304 if [ "$ret" != "0" ]; then
1305 diff -u $testroot/stdout.expected $testroot/stdout
1306 test_done "$testroot" "$ret"
1307 return 1
1310 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1311 ret="$?"
1312 if [ "$ret" != "0" ]; then
1313 echo "commit failed unexpectedly" >&2
1314 test_done "$testroot" "$ret"
1315 return 1
1318 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1319 ret="$?"
1320 if [ "$ret" != "0" ]; then
1321 echo "commit failed unexpectedly" >&2
1322 test_done "$testroot" "$ret"
1323 return 1
1326 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1327 ret="$?"
1328 if [ "$ret" != "0" ]; then
1329 echo "commit failed unexpectedly" >&2
1330 test_done "$testroot" "$ret"
1331 return 1
1334 (cd $testroot/wt && got histedit -c \
1335 > $testroot/stdout 2> $testroot/stderr)
1336 ret="$?"
1337 if [ "$ret" != "0" ]; then
1338 echo "histedit failed unexpectedly:" >&2
1339 cat $testroot/stderr >&2
1340 test_done "$testroot" "$ret"
1341 return 1
1343 local new_commit2=`git_show_head $testroot/repo`
1344 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1346 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1347 > $testroot/stdout.expected
1348 echo "G epsilon/zeta" >> $testroot/stdout.expected
1349 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1350 >> $testroot/stdout.expected
1351 echo "Switching work tree to refs/heads/master" \
1352 >> $testroot/stdout.expected
1354 cmp -s $testroot/stdout.expected $testroot/stdout
1355 ret="$?"
1356 if [ "$ret" != "0" ]; then
1357 diff -u $testroot/stdout.expected $testroot/stdout
1359 test_done "$testroot" "$ret"
1363 test_histedit_duplicate_commit_in_script() {
1364 local testroot=`test_init histedit_duplicate_commit_in_script`
1366 local orig_commit=`git_show_head $testroot/repo`
1368 echo "modified alpha on master" > $testroot/repo/alpha
1369 (cd $testroot/repo && git rm -q beta)
1370 echo "new file on master" > $testroot/repo/epsilon/new
1371 (cd $testroot/repo && git add epsilon/new)
1372 git_commit $testroot/repo -m "committing changes 1"
1373 local old_commit1=`git_show_head $testroot/repo`
1375 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1376 git_commit $testroot/repo -m "committing changes 2"
1377 local old_commit2=`git_show_head $testroot/repo`
1379 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1380 ret="$?"
1381 if [ "$ret" != "0" ]; then
1382 test_done "$testroot" "$ret"
1383 return 1
1386 # This histedit script lists commit1 more than once
1387 echo "p $old_commit1" > $testroot/histedit-script
1388 echo "p $old_commit1" >> $testroot/histedit-script
1389 echo "p $old_commit2" >> $testroot/histedit-script
1391 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1392 > $testroot/stdout 2> $testroot/stderr)
1393 ret="$?"
1394 if [ "$ret" = "0" ]; then
1395 echo "histedit succeeded unexpectedly:" >&2
1396 cat $testroot/stdout >&2
1397 test_done "$testroot" "$ret"
1398 return 1
1401 echo -n "got: commit $old_commit1 is listed more than once " \
1402 > $testroot/stderr.expected
1403 echo "in histedit script" >> $testroot/stderr.expected
1405 cmp -s $testroot/stderr.expected $testroot/stderr
1406 ret="$?"
1407 if [ "$ret" != "0" ]; then
1408 diff -u $testroot/stderr.expected $testroot/stderr
1410 test_done "$testroot" "$ret"
1414 # if a previous commit introduces a new file, and it is folded into a commit
1415 # that deletes the same file, the file still exists after the histedit
1416 test_histedit_fold_add_delete() {
1417 local testroot=`test_init histedit_fold_add_delete`
1419 local orig_commit=`git_show_head $testroot/repo`
1421 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1422 (cd $testroot/repo && git add epsilon/psi)
1423 git_commit $testroot/repo -m "committing changes"
1424 local old_commit1=`git_show_head $testroot/repo`
1426 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1427 git_commit $testroot/repo -m "editing psi"
1428 local old_commit2=`git_show_head $testroot/repo`
1430 (cd $testroot/repo && git rm -q epsilon/psi)
1431 git_commit $testroot/repo -m "removing psi"
1432 local old_commit3=`git_show_head $testroot/repo`
1434 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1435 ret="$?"
1436 if [ "$ret" != "0" ]; then
1437 test_done "$testroot" "$ret"
1438 return 1
1441 echo "fold $old_commit1" > $testroot/histedit-script
1442 echo "fold $old_commit2" >> $testroot/histedit-script
1443 echo "pick $old_commit3" >> $testroot/histedit-script
1444 echo "mesg folded changes" >> $testroot/histedit-script
1446 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1447 > $testroot/stdout)
1449 local new_commit1=`git_show_head $testroot/repo`
1451 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1452 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1453 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1454 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1456 echo "A epsilon/psi" >> $testroot/stdout.expected
1457 echo "$short_old_commit1 -> fold commit: committing changes" \
1458 >> $testroot/stdout.expected
1459 echo "G epsilon/psi" >> $testroot/stdout.expected
1460 echo "$short_old_commit2 -> fold commit: editing psi" \
1461 >> $testroot/stdout.expected
1462 echo "D epsilon/psi" >> $testroot/stdout.expected
1463 echo "$short_old_commit3 -> no-op change: folded changes" \
1464 >> $testroot/stdout.expected
1465 echo "Switching work tree to refs/heads/master" \
1466 >> $testroot/stdout.expected
1468 cmp -s $testroot/stdout.expected $testroot/stdout
1469 ret="$?"
1470 if [ "$ret" != "0" ]; then
1471 diff -u $testroot/stdout.expected $testroot/stdout
1472 test_done "$testroot" "$ret"
1473 return 1
1476 if [ -e $testroot/wt/epsilon/psi ]; then
1477 echo "removed file psi still exists on disk" >&2
1478 test_done "$testroot" "1"
1479 return 1
1482 (cd $testroot/wt && got status > $testroot/stdout)
1484 echo -n > $testroot/stdout.expected
1485 cmp -s $testroot/stdout.expected $testroot/stdout
1486 ret="$?"
1487 if [ "$ret" != "0" ]; then
1488 diff -u $testroot/stdout.expected $testroot/stdout
1489 test_done "$testroot" "$ret"
1490 return 1
1493 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1494 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1495 cmp -s $testroot/stdout.expected $testroot/stdout
1496 ret="$?"
1497 if [ "$ret" != "0" ]; then
1498 diff -u $testroot/stdout.expected $testroot/stdout
1499 test_done "$testroot" "$ret"
1500 return 1
1503 got tree -r $testroot/repo epsilon > $testroot/stdout
1504 echo "zeta" > $testroot/stdout.expected
1505 cmp -s $testroot/stdout.expected $testroot/stdout
1506 ret="$?"
1507 if [ "$ret" != "0" ]; then
1508 diff -u $testroot/stdout.expected $testroot/stdout
1510 test_done "$testroot" "$ret"
1513 test_histedit_fold_only() {
1514 local testroot=`test_init histedit_fold_only`
1516 local orig_commit=`git_show_head $testroot/repo`
1518 echo "modified alpha on master" > $testroot/repo/alpha
1519 (cd $testroot/repo && git rm -q beta)
1520 echo "new file on master" > $testroot/repo/epsilon/new
1521 (cd $testroot/repo && git add epsilon/new)
1522 git_commit $testroot/repo -m "committing changes"
1523 local old_commit1=`git_show_head $testroot/repo`
1525 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1526 git_commit $testroot/repo -m "committing to zeta on master"
1527 local old_commit2=`git_show_head $testroot/repo`
1529 echo "modified delta on master" > $testroot/repo/gamma/delta
1530 git_commit $testroot/repo -m "committing to delta on master"
1531 local old_commit3=`git_show_head $testroot/repo`
1533 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1534 ret="$?"
1535 if [ "$ret" != "0" ]; then
1536 test_done "$testroot" "$ret"
1537 return 1
1540 cat > $testroot/editor.sh <<EOF
1541 #!/bin/sh
1542 sed -i 's/.*/committing folded changes/' "\$1"
1543 EOF
1544 chmod +x $testroot/editor.sh
1546 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1547 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1549 local new_commit1=`git_show_head $testroot/repo`
1551 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1552 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1553 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1554 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1555 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1557 echo "G alpha" > $testroot/stdout.expected
1558 echo "D beta" >> $testroot/stdout.expected
1559 echo "A epsilon/new" >> $testroot/stdout.expected
1560 echo "$short_old_commit1 -> fold commit: committing changes" \
1561 >> $testroot/stdout.expected
1562 echo "G epsilon/zeta" >> $testroot/stdout.expected
1563 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1564 echo "fold commit: committing to zeta on master" \
1565 >> $testroot/stdout.expected
1566 echo "G gamma/delta" >> $testroot/stdout.expected
1567 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1568 >> $testroot/stdout.expected
1569 echo "committing folded changes" >> $testroot/stdout.expected
1570 echo "Switching work tree to refs/heads/master" \
1571 >> $testroot/stdout.expected
1573 cmp -s $testroot/stdout.expected $testroot/stdout
1574 ret="$?"
1575 if [ "$ret" != "0" ]; then
1576 diff -u $testroot/stdout.expected $testroot/stdout
1577 test_done "$testroot" "$ret"
1578 return 1
1581 echo "modified alpha on master" > $testroot/content.expected
1582 cat $testroot/wt/alpha > $testroot/content
1583 cmp -s $testroot/content.expected $testroot/content
1584 ret="$?"
1585 if [ "$ret" != "0" ]; then
1586 diff -u $testroot/content.expected $testroot/content
1587 test_done "$testroot" "$ret"
1588 return 1
1591 if [ -e $testroot/wt/beta ]; then
1592 echo "removed file beta still exists on disk" >&2
1593 test_done "$testroot" "1"
1594 return 1
1597 echo "new file on master" > $testroot/content.expected
1598 cat $testroot/wt/epsilon/new > $testroot/content
1599 cmp -s $testroot/content.expected $testroot/content
1600 ret="$?"
1601 if [ "$ret" != "0" ]; then
1602 diff -u $testroot/content.expected $testroot/content
1603 test_done "$testroot" "$ret"
1604 return 1
1607 (cd $testroot/wt && got status > $testroot/stdout)
1609 echo -n > $testroot/stdout.expected
1610 cmp -s $testroot/stdout.expected $testroot/stdout
1611 ret="$?"
1612 if [ "$ret" != "0" ]; then
1613 diff -u $testroot/stdout.expected $testroot/stdout
1614 test_done "$testroot" "$ret"
1615 return 1
1618 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1619 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1620 echo "commit $orig_commit" >> $testroot/stdout.expected
1621 cmp -s $testroot/stdout.expected $testroot/stdout
1622 ret="$?"
1623 if [ "$ret" != "0" ]; then
1624 diff -u $testroot/stdout.expected $testroot/stdout
1626 test_done "$testroot" "$ret"
1629 test_histedit_fold_only_empty_logmsg() {
1630 local testroot=`test_init histedit_fold_only_empty_logmsg`
1632 local orig_commit=`git_show_head $testroot/repo`
1634 echo "modified alpha on master" > $testroot/repo/alpha
1635 (cd $testroot/repo && git rm -q beta)
1636 echo "new file on master" > $testroot/repo/epsilon/new
1637 (cd $testroot/repo && git add epsilon/new)
1638 git_commit $testroot/repo -m "committing changes"
1639 local old_commit1=`git_show_head $testroot/repo`
1641 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1642 git_commit $testroot/repo -m "committing to zeta on master"
1643 local old_commit2=`git_show_head $testroot/repo`
1645 echo "modified delta on master" > $testroot/repo/gamma/delta
1646 git_commit $testroot/repo -m "committing to delta on master"
1647 local old_commit3=`git_show_head $testroot/repo`
1649 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1650 ret="$?"
1651 if [ "$ret" != "0" ]; then
1652 test_done "$testroot" "$ret"
1653 return 1
1656 cat > $testroot/editor.sh <<EOF
1657 #!/bin/sh
1658 sed -i 'd' "\$1"
1659 EOF
1660 chmod +x $testroot/editor.sh
1662 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1663 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1665 local new_commit1=`git_show_head $testroot/repo`
1667 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1668 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1669 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1670 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1671 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1672 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1674 echo "G alpha" > $testroot/stdout.expected
1675 echo "D beta" >> $testroot/stdout.expected
1676 echo "A epsilon/new" >> $testroot/stdout.expected
1677 echo "$short_old_commit1 -> fold commit: committing changes" \
1678 >> $testroot/stdout.expected
1679 echo "G epsilon/zeta" >> $testroot/stdout.expected
1680 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1681 echo "fold commit: committing to zeta on master" \
1682 >> $testroot/stdout.expected
1683 echo "G gamma/delta" >> $testroot/stdout.expected
1684 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1685 >> $testroot/stdout.expected
1686 echo "# log message of folded commit $very_short_old_commit1" \
1687 >> $testroot/stdout.expected
1688 echo "Switching work tree to refs/heads/master" \
1689 >> $testroot/stdout.expected
1691 cmp -s $testroot/stdout.expected $testroot/stdout
1692 ret="$?"
1693 if [ "$ret" != "0" ]; then
1694 diff -u $testroot/stdout.expected $testroot/stdout
1695 test_done "$testroot" "$ret"
1696 return 1
1699 echo "modified alpha on master" > $testroot/content.expected
1700 cat $testroot/wt/alpha > $testroot/content
1701 cmp -s $testroot/content.expected $testroot/content
1702 ret="$?"
1703 if [ "$ret" != "0" ]; then
1704 diff -u $testroot/content.expected $testroot/content
1705 test_done "$testroot" "$ret"
1706 return 1
1709 if [ -e $testroot/wt/beta ]; then
1710 echo "removed file beta still exists on disk" >&2
1711 test_done "$testroot" "1"
1712 return 1
1715 echo "new file on master" > $testroot/content.expected
1716 cat $testroot/wt/epsilon/new > $testroot/content
1717 cmp -s $testroot/content.expected $testroot/content
1718 ret="$?"
1719 if [ "$ret" != "0" ]; then
1720 diff -u $testroot/content.expected $testroot/content
1721 test_done "$testroot" "$ret"
1722 return 1
1725 (cd $testroot/wt && got status > $testroot/stdout)
1727 echo -n > $testroot/stdout.expected
1728 cmp -s $testroot/stdout.expected $testroot/stdout
1729 ret="$?"
1730 if [ "$ret" != "0" ]; then
1731 diff -u $testroot/stdout.expected $testroot/stdout
1732 test_done "$testroot" "$ret"
1733 return 1
1736 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1737 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1738 echo "commit $orig_commit" >> $testroot/stdout.expected
1739 cmp -s $testroot/stdout.expected $testroot/stdout
1740 ret="$?"
1741 if [ "$ret" != "0" ]; then
1742 diff -u $testroot/stdout.expected $testroot/stdout
1744 test_done "$testroot" "$ret"
1747 test_parseargs "$@"
1748 run_test test_histedit_no_op
1749 run_test test_histedit_swap
1750 run_test test_histedit_drop
1751 run_test test_histedit_fold
1752 run_test test_histedit_edit
1753 run_test test_histedit_fold_last_commit
1754 run_test test_histedit_missing_commit
1755 run_test test_histedit_abort
1756 run_test test_histedit_path_prefix_drop
1757 run_test test_histedit_path_prefix_edit
1758 run_test test_histedit_outside_refs_heads
1759 run_test test_histedit_fold_last_commit_swap
1760 run_test test_histedit_split_commit
1761 run_test test_histedit_duplicate_commit_in_script
1762 run_test test_histedit_fold_add_delete
1763 run_test test_histedit_fold_only
1764 run_test test_histedit_fold_only_empty_logmsg