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 fi
152 # We should have a backup of old commits
153 (cd $testroot/repo && got histedit -l > $testroot/stdout)
154 d_orig2=`env TZ=UTC date -r $old_author_time2 +"%a %b %e %X %Y UTC"`
155 d_new2=`env TZ=UTC date -r $new_author_time2 +"%G-%m-%d"`
156 d_orig=`env TZ=UTC date -r $orig_author_time +"%G-%m-%d"`
157 cat > $testroot/stdout.expected <<EOF
158 -----------------------------------------------
159 commit $old_commit2 (formerly master)
160 from: $GOT_AUTHOR
161 date: $d_orig2
163 committing to zeta on master
165 has become commit $new_commit2 (master)
166 $d_new2 $GOT_AUTHOR_11 committing to zeta on master
167 history forked at $orig_commit
168 $d_orig $GOT_AUTHOR_11 adding the test tree
169 EOF
170 cmp -s $testroot/stdout.expected $testroot/stdout
171 ret="$?"
172 if [ "$ret" != "0" ]; then
173 diff -u $testroot/stdout.expected $testroot/stdout
174 test_done "$testroot" "$ret"
175 return 1
176 fi
178 (cd $testroot/repo && got histedit -X master \
179 > $testroot/stdout 2> $testroot/stderr)
180 echo -n "Deleted refs/got/backup/histedit/master/$new_commit2: " \
181 > $testroot/stdout.expected
182 echo "$old_commit2" >> $testroot/stdout.expected
183 echo -n > $testroot/stderr.expected
184 cmp -s $testroot/stdout.expected $testroot/stdout
185 ret="$?"
186 if [ "$ret" != "0" ]; then
187 diff -u $testroot/stdout.expected $testroot/stdout
188 test_done "$testroot" "$ret"
189 return 1
190 fi
191 cmp -s $testroot/stderr.expected $testroot/stderr
192 ret="$?"
193 if [ "$ret" != "0" ]; then
194 diff -u $testroot/stderr.expected $testroot/stderr
195 test_done "$testroot" "$ret"
196 return 1
197 fi
199 (cd $testroot/repo && got histedit -l > $testroot/stdout)
200 echo -n > $testroot/stdout.expected
201 cmp -s $testroot/stdout.expected $testroot/stdout
202 ret="$?"
203 if [ "$ret" != "0" ]; then
204 diff -u $testroot/stdout.expected $testroot/stdout
205 fi
206 test_done "$testroot" "$ret"
209 test_histedit_swap() {
210 local testroot=`test_init histedit_swap`
212 local orig_commit=`git_show_head $testroot/repo`
214 echo "modified alpha on master" > $testroot/repo/alpha
215 (cd $testroot/repo && git rm -q beta)
216 echo "new file on master" > $testroot/repo/epsilon/new
217 (cd $testroot/repo && git add epsilon/new)
218 git_commit $testroot/repo -m "committing changes"
219 local old_commit1=`git_show_head $testroot/repo`
221 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
222 git_commit $testroot/repo -m "committing to zeta on master"
223 local old_commit2=`git_show_head $testroot/repo`
225 got diff -r $testroot/repo $orig_commit $old_commit2 \
226 > $testroot/diff.expected
228 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
229 ret="$?"
230 if [ "$ret" != "0" ]; then
231 test_done "$testroot" "$ret"
232 return 1
233 fi
235 echo "pick $old_commit2" > $testroot/histedit-script
236 echo "pick $old_commit1" >> $testroot/histedit-script
238 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
239 > $testroot/stdout)
241 local new_commit2=`git_show_parent_commit $testroot/repo`
242 local new_commit1=`git_show_head $testroot/repo`
244 local short_old_commit1=`trim_obj_id 28 $old_commit1`
245 local short_old_commit2=`trim_obj_id 28 $old_commit2`
246 local short_new_commit1=`trim_obj_id 28 $new_commit1`
247 local short_new_commit2=`trim_obj_id 28 $new_commit2`
249 echo "G epsilon/zeta" > $testroot/stdout.expected
250 echo -n "$short_old_commit2 -> $short_new_commit2: " \
251 >> $testroot/stdout.expected
252 echo "committing to zeta on master" >> $testroot/stdout.expected
253 echo "G alpha" >> $testroot/stdout.expected
254 echo "D beta" >> $testroot/stdout.expected
255 echo "A epsilon/new" >> $testroot/stdout.expected
256 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
257 >> $testroot/stdout.expected
258 echo "Switching work tree to refs/heads/master" \
259 >> $testroot/stdout.expected
261 cmp -s $testroot/stdout.expected $testroot/stdout
262 ret="$?"
263 if [ "$ret" != "0" ]; then
264 diff -u $testroot/stdout.expected $testroot/stdout
265 test_done "$testroot" "$ret"
266 return 1
267 fi
269 echo "modified alpha on master" > $testroot/content.expected
270 cat $testroot/wt/alpha > $testroot/content
271 cmp -s $testroot/content.expected $testroot/content
272 ret="$?"
273 if [ "$ret" != "0" ]; then
274 diff -u $testroot/content.expected $testroot/content
275 test_done "$testroot" "$ret"
276 return 1
277 fi
279 if [ -e $testroot/wt/beta ]; then
280 echo "removed file beta still exists on disk" >&2
281 test_done "$testroot" "1"
282 return 1
283 fi
285 echo "new file on master" > $testroot/content.expected
286 cat $testroot/wt/epsilon/new > $testroot/content
287 cmp -s $testroot/content.expected $testroot/content
288 ret="$?"
289 if [ "$ret" != "0" ]; then
290 diff -u $testroot/content.expected $testroot/content
291 test_done "$testroot" "$ret"
292 return 1
293 fi
295 (cd $testroot/wt && got status > $testroot/stdout)
297 echo -n > $testroot/stdout.expected
298 cmp -s $testroot/stdout.expected $testroot/stdout
299 ret="$?"
300 if [ "$ret" != "0" ]; then
301 diff -u $testroot/stdout.expected $testroot/stdout
302 test_done "$testroot" "$ret"
303 return 1
304 fi
306 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
307 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
308 echo "commit $new_commit2" >> $testroot/stdout.expected
309 echo "commit $orig_commit" >> $testroot/stdout.expected
310 cmp -s $testroot/stdout.expected $testroot/stdout
311 ret="$?"
312 if [ "$ret" != "0" ]; then
313 diff -u $testroot/stdout.expected $testroot/stdout
314 test_done "$testroot" "$ret"
315 return 1
316 fi
318 got diff -r $testroot/repo $orig_commit $new_commit1 \
319 > $testroot/diff
320 sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
321 cmp -s $testroot/diff.expected $testroot/diff
322 ret="$?"
323 if [ "$ret" != "0" ]; then
324 diff -u $testroot/diff.expected $testroot/diff
325 fi
326 test_done "$testroot" "$ret"
329 test_histedit_drop() {
330 local testroot=`test_init histedit_drop`
331 local orig_commit=`git_show_head $testroot/repo`
333 echo "modified alpha on master" > $testroot/repo/alpha
334 (cd $testroot/repo && git rm -q beta)
335 echo "new file on master" > $testroot/repo/epsilon/new
336 (cd $testroot/repo && git add epsilon/new)
337 git_commit $testroot/repo -m "committing changes"
338 local old_commit1=`git_show_head $testroot/repo`
340 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
341 git_commit $testroot/repo -m "committing to zeta on master"
342 local old_commit2=`git_show_head $testroot/repo`
344 got diff -r $testroot/repo $old_commit1 $old_commit2 \
345 > $testroot/diff.expected
347 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
348 ret="$?"
349 if [ "$ret" != "0" ]; then
350 test_done "$testroot" "$ret"
351 return 1
352 fi
354 echo "drop $old_commit1" > $testroot/histedit-script
355 echo "pick $old_commit2" >> $testroot/histedit-script
357 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
358 > $testroot/stdout)
360 local new_commit2=`git_show_head $testroot/repo`
362 local short_old_commit1=`trim_obj_id 28 $old_commit1`
363 local short_old_commit2=`trim_obj_id 28 $old_commit2`
364 local short_new_commit2=`trim_obj_id 28 $new_commit2`
366 echo "$short_old_commit1 -> drop commit: committing changes" \
367 > $testroot/stdout.expected
368 echo "G epsilon/zeta" >> $testroot/stdout.expected
369 echo -n "$short_old_commit2 -> $short_new_commit2: " \
370 >> $testroot/stdout.expected
371 echo "committing to zeta on master" >> $testroot/stdout.expected
372 echo "Switching work tree to refs/heads/master" \
373 >> $testroot/stdout.expected
375 cmp -s $testroot/stdout.expected $testroot/stdout
376 ret="$?"
377 if [ "$ret" != "0" ]; then
378 diff -u $testroot/stdout.expected $testroot/stdout
379 test_done "$testroot" "$ret"
380 return 1
381 fi
383 for f in alpha beta; do
384 echo "$f" > $testroot/content.expected
385 cat $testroot/wt/$f > $testroot/content
386 cmp -s $testroot/content.expected $testroot/content
387 ret="$?"
388 if [ "$ret" != "0" ]; then
389 diff -u $testroot/content.expected $testroot/content
390 test_done "$testroot" "$ret"
391 return 1
392 fi
393 done
395 if [ -e $testroot/wt/new ]; then
396 echo "file new exists on disk but should not" >&2
397 test_done "$testroot" "1"
398 return 1
399 fi
401 (cd $testroot/wt && got status > $testroot/stdout)
403 echo -n > $testroot/stdout.expected
404 cmp -s $testroot/stdout.expected $testroot/stdout
405 ret="$?"
406 if [ "$ret" != "0" ]; then
407 diff -u $testroot/stdout.expected $testroot/stdout
408 test_done "$testroot" "$ret"
409 return 1
410 fi
412 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
413 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
414 echo "commit $orig_commit" >> $testroot/stdout.expected
415 cmp -s $testroot/stdout.expected $testroot/stdout
416 ret="$?"
417 if [ "$ret" != "0" ]; then
418 diff -u $testroot/stdout.expected $testroot/stdout
419 test_done "$testroot" "$ret"
420 return 1
421 fi
423 got diff -r $testroot/repo $orig_commit $new_commit2 \
424 > $testroot/diff
425 sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
426 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
427 cmp -s $testroot/diff.expected $testroot/diff
428 ret="$?"
429 if [ "$ret" != "0" ]; then
430 diff -u $testroot/diff.expected $testroot/diff
431 fi
432 test_done "$testroot" "$ret"
435 test_histedit_fold() {
436 local testroot=`test_init histedit_fold`
438 local orig_commit=`git_show_head $testroot/repo`
440 echo "modified alpha on master" > $testroot/repo/alpha
441 (cd $testroot/repo && git rm -q beta)
442 echo "new file on master" > $testroot/repo/epsilon/new
443 (cd $testroot/repo && git add epsilon/new)
444 git_commit $testroot/repo -m "committing changes"
445 local old_commit1=`git_show_head $testroot/repo`
447 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
448 git_commit $testroot/repo -m "committing to zeta on master"
449 local old_commit2=`git_show_head $testroot/repo`
451 echo "modified delta on master" > $testroot/repo/gamma/delta
452 git_commit $testroot/repo -m "committing to delta on master"
453 local old_commit3=`git_show_head $testroot/repo`
455 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
456 ret="$?"
457 if [ "$ret" != "0" ]; then
458 test_done "$testroot" "$ret"
459 return 1
460 fi
462 echo "fold $old_commit1" > $testroot/histedit-script
463 echo "drop $old_commit2" >> $testroot/histedit-script
464 echo "pick $old_commit3" >> $testroot/histedit-script
465 echo "mesg committing folded changes" >> $testroot/histedit-script
467 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
468 > $testroot/stdout)
470 local new_commit1=`git_show_parent_commit $testroot/repo`
471 local new_commit2=`git_show_head $testroot/repo`
473 local short_old_commit1=`trim_obj_id 28 $old_commit1`
474 local short_old_commit2=`trim_obj_id 28 $old_commit2`
475 local short_old_commit3=`trim_obj_id 28 $old_commit3`
476 local short_new_commit1=`trim_obj_id 28 $new_commit1`
477 local short_new_commit2=`trim_obj_id 28 $new_commit2`
479 echo "G alpha" > $testroot/stdout.expected
480 echo "D beta" >> $testroot/stdout.expected
481 echo "A epsilon/new" >> $testroot/stdout.expected
482 echo "$short_old_commit1 -> fold commit: committing changes" \
483 >> $testroot/stdout.expected
484 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
485 echo "drop commit: committing to zeta on master" \
486 >> $testroot/stdout.expected
487 echo "G gamma/delta" >> $testroot/stdout.expected
488 echo -n "$short_old_commit3 -> $short_new_commit2: " \
489 >> $testroot/stdout.expected
490 echo "committing folded changes" >> $testroot/stdout.expected
491 echo "Switching work tree to refs/heads/master" \
492 >> $testroot/stdout.expected
494 cmp -s $testroot/stdout.expected $testroot/stdout
495 ret="$?"
496 if [ "$ret" != "0" ]; then
497 diff -u $testroot/stdout.expected $testroot/stdout
498 test_done "$testroot" "$ret"
499 return 1
500 fi
502 echo "modified alpha on master" > $testroot/content.expected
503 cat $testroot/wt/alpha > $testroot/content
504 cmp -s $testroot/content.expected $testroot/content
505 ret="$?"
506 if [ "$ret" != "0" ]; then
507 diff -u $testroot/content.expected $testroot/content
508 test_done "$testroot" "$ret"
509 return 1
510 fi
512 if [ -e $testroot/wt/beta ]; then
513 echo "removed file beta still exists on disk" >&2
514 test_done "$testroot" "1"
515 return 1
516 fi
518 echo "new file on master" > $testroot/content.expected
519 cat $testroot/wt/epsilon/new > $testroot/content
520 cmp -s $testroot/content.expected $testroot/content
521 ret="$?"
522 if [ "$ret" != "0" ]; then
523 diff -u $testroot/content.expected $testroot/content
524 test_done "$testroot" "$ret"
525 return 1
526 fi
528 (cd $testroot/wt && got status > $testroot/stdout)
530 echo -n > $testroot/stdout.expected
531 cmp -s $testroot/stdout.expected $testroot/stdout
532 ret="$?"
533 if [ "$ret" != "0" ]; then
534 diff -u $testroot/stdout.expected $testroot/stdout
535 test_done "$testroot" "$ret"
536 return 1
537 fi
539 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
540 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
541 echo "commit $orig_commit" >> $testroot/stdout.expected
542 cmp -s $testroot/stdout.expected $testroot/stdout
543 ret="$?"
544 if [ "$ret" != "0" ]; then
545 diff -u $testroot/stdout.expected $testroot/stdout
546 fi
547 test_done "$testroot" "$ret"
550 test_histedit_edit() {
551 local testroot=`test_init histedit_edit`
553 local orig_commit=`git_show_head $testroot/repo`
555 echo "modified alpha on master" > $testroot/repo/alpha
556 (cd $testroot/repo && git rm -q beta)
557 echo "new file on master" > $testroot/repo/epsilon/new
558 (cd $testroot/repo && git add epsilon/new)
559 git_commit $testroot/repo -m "committing changes"
560 local old_commit1=`git_show_head $testroot/repo`
562 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
563 git_commit $testroot/repo -m "committing to zeta on master"
564 local old_commit2=`git_show_head $testroot/repo`
566 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
567 ret="$?"
568 if [ "$ret" != "0" ]; then
569 test_done "$testroot" "$ret"
570 return 1
571 fi
573 echo "edit $old_commit1" > $testroot/histedit-script
574 echo "mesg committing changes" >> $testroot/histedit-script
575 echo "pick $old_commit2" >> $testroot/histedit-script
577 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
578 > $testroot/stdout)
580 local short_old_commit1=`trim_obj_id 28 $old_commit1`
581 local short_old_commit2=`trim_obj_id 28 $old_commit2`
583 echo "G alpha" > $testroot/stdout.expected
584 echo "D beta" >> $testroot/stdout.expected
585 echo "A epsilon/new" >> $testroot/stdout.expected
586 echo "Stopping histedit for amending commit $old_commit1" \
587 >> $testroot/stdout.expected
588 cmp -s $testroot/stdout.expected $testroot/stdout
589 ret="$?"
590 if [ "$ret" != "0" ]; then
591 diff -u $testroot/stdout.expected $testroot/stdout
592 test_done "$testroot" "$ret"
593 return 1
594 fi
596 echo "edited modified alpha on master" > $testroot/wt/alpha
598 # test interaction of 'got stage' and histedit -c
599 (cd $testroot/wt && got stage alpha > /dev/null)
600 (cd $testroot/wt && got histedit -c > $testroot/stdout \
601 2> $testroot/stderr)
602 ret="$?"
603 if [ "$ret" = "0" ]; then
604 echo "histedit succeeded unexpectedly" >&2
605 test_done "$testroot" "1"
606 return 1
607 fi
608 echo -n "got: work tree contains files with staged changes; " \
609 > $testroot/stderr.expected
610 echo "these changes must be committed or unstaged first" \
611 >> $testroot/stderr.expected
612 cmp -s $testroot/stderr.expected $testroot/stderr
613 ret="$?"
614 if [ "$ret" != "0" ]; then
615 diff -u $testroot/stderr.expected $testroot/stderr
616 test_done "$testroot" "$ret"
617 return 1
618 fi
620 (cd $testroot/wt && got unstage alpha > /dev/null)
621 (cd $testroot/wt && got histedit -c > $testroot/stdout)
623 local new_commit1=`git_show_parent_commit $testroot/repo`
624 local new_commit2=`git_show_head $testroot/repo`
626 local short_new_commit1=`trim_obj_id 28 $new_commit1`
627 local short_new_commit2=`trim_obj_id 28 $new_commit2`
629 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
630 > $testroot/stdout.expected
631 echo "G epsilon/zeta" >> $testroot/stdout.expected
632 echo -n "$short_old_commit2 -> $short_new_commit2: " \
633 >> $testroot/stdout.expected
634 echo "committing to zeta on master" >> $testroot/stdout.expected
635 echo "Switching work tree to refs/heads/master" \
636 >> $testroot/stdout.expected
638 cmp -s $testroot/stdout.expected $testroot/stdout
639 ret="$?"
640 if [ "$ret" != "0" ]; then
641 diff -u $testroot/stdout.expected $testroot/stdout
642 test_done "$testroot" "$ret"
643 return 1
644 fi
646 echo "edited modified alpha on master" > $testroot/content.expected
647 cat $testroot/wt/alpha > $testroot/content
648 cmp -s $testroot/content.expected $testroot/content
649 ret="$?"
650 if [ "$ret" != "0" ]; then
651 diff -u $testroot/content.expected $testroot/content
652 test_done "$testroot" "$ret"
653 return 1
654 fi
656 if [ -e $testroot/wt/beta ]; then
657 echo "removed file beta still exists on disk" >&2
658 test_done "$testroot" "1"
659 return 1
660 fi
662 echo "new file on master" > $testroot/content.expected
663 cat $testroot/wt/epsilon/new > $testroot/content
664 cmp -s $testroot/content.expected $testroot/content
665 ret="$?"
666 if [ "$ret" != "0" ]; then
667 diff -u $testroot/content.expected $testroot/content
668 test_done "$testroot" "$ret"
669 return 1
670 fi
672 (cd $testroot/wt && got status > $testroot/stdout)
674 echo -n > $testroot/stdout.expected
675 cmp -s $testroot/stdout.expected $testroot/stdout
676 ret="$?"
677 if [ "$ret" != "0" ]; then
678 diff -u $testroot/stdout.expected $testroot/stdout
679 test_done "$testroot" "$ret"
680 return 1
681 fi
683 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
684 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
685 echo "commit $new_commit1" >> $testroot/stdout.expected
686 echo "commit $orig_commit" >> $testroot/stdout.expected
687 cmp -s $testroot/stdout.expected $testroot/stdout
688 ret="$?"
689 if [ "$ret" != "0" ]; then
690 diff -u $testroot/stdout.expected $testroot/stdout
691 fi
692 test_done "$testroot" "$ret"
695 test_histedit_fold_last_commit() {
696 local testroot=`test_init histedit_fold_last_commit`
698 local orig_commit=`git_show_head $testroot/repo`
700 echo "modified alpha on master" > $testroot/repo/alpha
701 (cd $testroot/repo && git rm -q beta)
702 echo "new file on master" > $testroot/repo/epsilon/new
703 (cd $testroot/repo && git add epsilon/new)
704 git_commit $testroot/repo -m "committing changes"
705 local old_commit1=`git_show_head $testroot/repo`
707 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
708 git_commit $testroot/repo -m "committing to zeta on master"
709 local old_commit2=`git_show_head $testroot/repo`
711 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
712 ret="$?"
713 if [ "$ret" != "0" ]; then
714 test_done "$testroot" "$ret"
715 return 1
716 fi
718 echo "pick $old_commit1" > $testroot/histedit-script
719 echo "fold $old_commit2" >> $testroot/histedit-script
720 echo "mesg committing folded changes" >> $testroot/histedit-script
722 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
723 > $testroot/stdout 2> $testroot/stderr)
725 ret="$?"
726 if [ "$ret" = "0" ]; then
727 echo "histedit succeeded unexpectedly" >&2
728 test_done "$testroot" "1"
729 return 1
730 fi
732 echo "got: last commit in histedit script cannot be folded" \
733 > $testroot/stderr.expected
735 cmp -s $testroot/stderr.expected $testroot/stderr
736 ret="$?"
737 if [ "$ret" != "0" ]; then
738 diff -u $testroot/stderr.expected $testroot/stderr
739 fi
740 test_done "$testroot" "$ret"
743 test_histedit_missing_commit() {
744 local testroot=`test_init histedit_missing_commit`
746 local orig_commit=`git_show_head $testroot/repo`
748 echo "modified alpha on master" > $testroot/repo/alpha
749 (cd $testroot/repo && git rm -q beta)
750 echo "new file on master" > $testroot/repo/epsilon/new
751 (cd $testroot/repo && git add epsilon/new)
752 git_commit $testroot/repo -m "committing changes"
753 local old_commit1=`git_show_head $testroot/repo`
755 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
756 git_commit $testroot/repo -m "committing to zeta on master"
757 local old_commit2=`git_show_head $testroot/repo`
759 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
760 ret="$?"
761 if [ "$ret" != "0" ]; then
762 test_done "$testroot" "$ret"
763 return 1
764 fi
766 echo "pick $old_commit1" > $testroot/histedit-script
767 echo "mesg committing changes" >> $testroot/histedit-script
769 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
770 > $testroot/stdout 2> $testroot/stderr)
772 ret="$?"
773 if [ "$ret" = "0" ]; then
774 echo "histedit succeeded unexpectedly" >&2
775 test_done "$testroot" "1"
776 return 1
777 fi
779 echo "got: commit $old_commit2 missing from histedit script" \
780 > $testroot/stderr.expected
782 cmp -s $testroot/stderr.expected $testroot/stderr
783 ret="$?"
784 if [ "$ret" != "0" ]; then
785 diff -u $testroot/stderr.expected $testroot/stderr
786 fi
787 test_done "$testroot" "$ret"
790 test_histedit_abort() {
791 local testroot=`test_init histedit_abort`
793 local orig_commit=`git_show_head $testroot/repo`
795 echo "modified alpha on master" > $testroot/repo/alpha
796 (cd $testroot/repo && git rm -q beta)
797 echo "new file on master" > $testroot/repo/epsilon/new
798 (cd $testroot/repo && git add epsilon/new)
799 git_commit $testroot/repo -m "committing changes"
800 local old_commit1=`git_show_head $testroot/repo`
802 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
803 git_commit $testroot/repo -m "committing to zeta on master"
804 local old_commit2=`git_show_head $testroot/repo`
806 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
807 ret="$?"
808 if [ "$ret" != "0" ]; then
809 test_done "$testroot" "$ret"
810 return 1
811 fi
813 echo "edit $old_commit1" > $testroot/histedit-script
814 echo "mesg committing changes" >> $testroot/histedit-script
815 echo "pick $old_commit2" >> $testroot/histedit-script
817 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
818 > $testroot/stdout)
820 local short_old_commit1=`trim_obj_id 28 $old_commit1`
821 local short_old_commit2=`trim_obj_id 28 $old_commit2`
823 echo "G alpha" > $testroot/stdout.expected
824 echo "D beta" >> $testroot/stdout.expected
825 echo "A epsilon/new" >> $testroot/stdout.expected
826 echo "Stopping histedit for amending commit $old_commit1" \
827 >> $testroot/stdout.expected
828 cmp -s $testroot/stdout.expected $testroot/stdout
829 ret="$?"
830 if [ "$ret" != "0" ]; then
831 diff -u $testroot/stdout.expected $testroot/stdout
832 test_done "$testroot" "$ret"
833 return 1
834 fi
836 echo "edited modified alpha on master" > $testroot/wt/alpha
838 (cd $testroot/wt && got histedit -a > $testroot/stdout)
840 local new_commit1=`git_show_parent_commit $testroot/repo`
841 local new_commit2=`git_show_head $testroot/repo`
843 echo "Switching work tree to refs/heads/master" \
844 > $testroot/stdout.expected
845 echo "R alpha" >> $testroot/stdout.expected
846 echo "R beta" >> $testroot/stdout.expected
847 echo "R epsilon/new" >> $testroot/stdout.expected
848 echo "Histedit of refs/heads/master aborted" \
849 >> $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 for f in alpha beta; do
860 echo "$f" > $testroot/content.expected
861 cat $testroot/wt/$f > $testroot/content
862 cmp -s $testroot/content.expected $testroot/content
863 ret="$?"
864 if [ "$ret" != "0" ]; then
865 diff -u $testroot/content.expected $testroot/content
866 test_done "$testroot" "$ret"
867 return 1
868 fi
869 done
871 echo "new file on master" > $testroot/content.expected
872 cat $testroot/wt/epsilon/new > $testroot/content
873 cmp -s $testroot/content.expected $testroot/content
874 ret="$?"
875 if [ "$ret" != "0" ]; then
876 diff -u $testroot/content.expected $testroot/content
877 test_done "$testroot" "$ret"
878 return 1
879 fi
881 (cd $testroot/wt && got status > $testroot/stdout)
883 echo "? epsilon/new" > $testroot/stdout.expected
884 cmp -s $testroot/stdout.expected $testroot/stdout
885 ret="$?"
886 if [ "$ret" != "0" ]; then
887 diff -u $testroot/stdout.expected $testroot/stdout
888 test_done "$testroot" "$ret"
889 return 1
890 fi
892 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
893 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
894 echo "commit $new_commit1" >> $testroot/stdout.expected
895 echo "commit $orig_commit" >> $testroot/stdout.expected
896 cmp -s $testroot/stdout.expected $testroot/stdout
897 ret="$?"
898 if [ "$ret" != "0" ]; then
899 diff -u $testroot/stdout.expected $testroot/stdout
900 fi
901 test_done "$testroot" "$ret"
904 test_histedit_path_prefix_drop() {
905 local testroot=`test_init histedit_path_prefix_drop`
906 local orig_commit=`git_show_head $testroot/repo`
908 echo "modified zeta" > $testroot/repo/epsilon/zeta
909 git_commit $testroot/repo -m "changing zeta"
910 local old_commit1=`git_show_head $testroot/repo`
912 got checkout -c $orig_commit -p gamma $testroot/repo \
913 $testroot/wt > /dev/null
914 ret="$?"
915 if [ "$ret" != "0" ]; then
916 test_done "$testroot" "$ret"
917 return 1
918 fi
920 echo "drop $old_commit1" > $testroot/histedit-script
922 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
923 > $testroot/stdout 2> $testroot/stderr)
925 ret="$?"
926 if [ "$ret" = "0" ]; then
927 echo "histedit succeeded unexpectedly" >&2
928 test_done "$testroot" "1"
929 return 1
930 fi
932 echo -n "got: cannot edit branch history which contains changes " \
933 > $testroot/stderr.expected
934 echo "outside of this work tree's path prefix" \
935 >> $testroot/stderr.expected
937 cmp -s $testroot/stderr.expected $testroot/stderr
938 ret="$?"
939 if [ "$ret" != "0" ]; then
940 diff -u $testroot/stderr.expected $testroot/stderr
941 test_done "$testroot" "$ret"
942 return 1
943 fi
945 rm -rf $testroot/wt
946 got checkout -c $orig_commit -p epsilon $testroot/repo \
947 $testroot/wt > /dev/null
948 ret="$?"
949 if [ "$ret" != "0" ]; then
950 test_done "$testroot" "$ret"
951 return 1
952 fi
953 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
954 > $testroot/stdout)
956 local short_old_commit1=`trim_obj_id 28 $old_commit1`
957 local short_old_commit2=`trim_obj_id 28 $old_commit2`
959 echo "$short_old_commit1 -> drop commit: changing zeta" \
960 > $testroot/stdout.expected
961 echo "Switching work tree to refs/heads/master" \
962 >> $testroot/stdout.expected
964 cmp -s $testroot/stdout.expected $testroot/stdout
965 ret="$?"
966 if [ "$ret" != "0" ]; then
967 diff -u $testroot/stdout.expected $testroot/stdout
968 test_done "$testroot" "$ret"
969 return 1
970 fi
972 echo "zeta" > $testroot/content.expected
973 cat $testroot/wt/zeta > $testroot/content
974 cmp -s $testroot/content.expected $testroot/content
975 ret="$?"
976 if [ "$ret" != "0" ]; then
977 diff -u $testroot/content.expected $testroot/content
978 test_done "$testroot" "$ret"
979 return 1
980 fi
983 (cd $testroot/wt && got status > $testroot/stdout)
985 echo -n > $testroot/stdout.expected
986 cmp -s $testroot/stdout.expected $testroot/stdout
987 ret="$?"
988 if [ "$ret" != "0" ]; then
989 diff -u $testroot/stdout.expected $testroot/stdout
990 test_done "$testroot" "$ret"
991 return 1
992 fi
994 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
995 echo "commit $orig_commit (master)" > $testroot/stdout.expected
996 cmp -s $testroot/stdout.expected $testroot/stdout
997 ret="$?"
998 if [ "$ret" != "0" ]; then
999 diff -u $testroot/stdout.expected $testroot/stdout
1001 test_done "$testroot" "$ret"
1004 test_histedit_path_prefix_edit() {
1005 local testroot=`test_init histedit_path_prefix_edit`
1006 local orig_commit=`git_show_head $testroot/repo`
1008 echo "modified zeta" > $testroot/repo/epsilon/zeta
1009 git_commit $testroot/repo -m "changing zeta"
1010 local old_commit1=`git_show_head $testroot/repo`
1012 got diff -r $testroot/repo $orig_commit $old_commit1 \
1013 > $testroot/diff.expected
1015 got checkout -c $orig_commit -p gamma $testroot/repo \
1016 $testroot/wt > /dev/null
1017 ret="$?"
1018 if [ "$ret" != "0" ]; then
1019 test_done "$testroot" "$ret"
1020 return 1
1023 echo "edit $old_commit1" > $testroot/histedit-script
1024 echo "mesg modified zeta" >> $testroot/histedit-script
1026 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1027 > $testroot/stdout 2> $testroot/stderr)
1029 ret="$?"
1030 if [ "$ret" = "0" ]; then
1031 echo "histedit succeeded unexpectedly" >&2
1032 test_done "$testroot" "1"
1033 return 1
1036 echo -n "got: cannot edit branch history which contains changes " \
1037 > $testroot/stderr.expected
1038 echo "outside of this work tree's path prefix" \
1039 >> $testroot/stderr.expected
1041 cmp -s $testroot/stderr.expected $testroot/stderr
1042 ret="$?"
1043 if [ "$ret" != "0" ]; then
1044 diff -u $testroot/stderr.expected $testroot/stderr
1045 test_done "$testroot" "$ret"
1046 return 1
1049 rm -rf $testroot/wt
1050 got checkout -c $orig_commit -p epsilon $testroot/repo \
1051 $testroot/wt > /dev/null
1052 ret="$?"
1053 if [ "$ret" != "0" ]; then
1054 test_done "$testroot" "$ret"
1055 return 1
1057 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1058 > $testroot/stdout)
1060 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1062 echo "G zeta" > $testroot/stdout.expected
1063 echo "Stopping histedit for amending commit $old_commit1" \
1064 >> $testroot/stdout.expected
1065 cmp -s $testroot/stdout.expected $testroot/stdout
1066 ret="$?"
1067 if [ "$ret" != "0" ]; then
1068 diff -u $testroot/stdout.expected $testroot/stdout
1069 test_done "$testroot" "$ret"
1070 return 1
1073 echo "modified zeta" > $testroot/content.expected
1074 cat $testroot/wt/zeta > $testroot/content
1075 cmp -s $testroot/content.expected $testroot/content
1076 ret="$?"
1077 if [ "$ret" != "0" ]; then
1078 diff -u $testroot/content.expected $testroot/content
1079 test_done "$testroot" "$ret"
1080 return 1
1083 (cd $testroot/wt && got status > $testroot/stdout)
1085 echo "M zeta"> $testroot/stdout.expected
1086 cmp -s $testroot/stdout.expected $testroot/stdout
1087 ret="$?"
1088 if [ "$ret" != "0" ]; then
1089 diff -u $testroot/stdout.expected $testroot/stdout
1090 test_done "$testroot" "$ret"
1091 return 1
1094 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1096 local new_commit1=`git_show_head $testroot/repo`
1097 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1099 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1100 > $testroot/stdout.expected
1101 echo "modified zeta" >> $testroot/stdout.expected
1102 echo "Switching work tree to refs/heads/master" \
1103 >> $testroot/stdout.expected
1105 cmp -s $testroot/stdout.expected $testroot/stdout
1106 ret="$?"
1107 if [ "$ret" != "0" ]; then
1108 diff -u $testroot/stdout.expected $testroot/stdout
1109 test_done "$testroot" "$ret"
1110 return 1
1113 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1114 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1115 echo "commit $orig_commit" >> $testroot/stdout.expected
1116 cmp -s $testroot/stdout.expected $testroot/stdout
1117 ret="$?"
1118 if [ "$ret" != "0" ]; then
1119 diff -u $testroot/stdout.expected $testroot/stdout
1120 test_done "$testroot" "$ret"
1121 return 1
1124 got diff -r $testroot/repo $orig_commit $new_commit1 \
1125 > $testroot/diff
1126 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1127 cmp -s $testroot/diff.expected $testroot/diff
1128 ret="$?"
1129 if [ "$ret" != "0" ]; then
1130 diff -u $testroot/diff.expected $testroot/diff
1132 test_done "$testroot" "$ret"
1135 test_histedit_outside_refs_heads() {
1136 local testroot=`test_init histedit_outside_refs_heads`
1137 local commit1=`git_show_head $testroot/repo`
1139 got checkout $testroot/repo $testroot/wt > /dev/null
1140 ret="$?"
1141 if [ "$ret" != "0" ]; then
1142 echo "got checkout failed unexpectedly"
1143 test_done "$testroot" "$ret"
1144 return 1
1147 echo "modified alpha" > $testroot/wt/alpha
1149 (cd $testroot/wt && got commit -m 'change alpha' \
1150 > $testroot/stdout 2> $testroot/stderr)
1151 ret="$?"
1152 if [ "$ret" != "0" ]; then
1153 echo "got commit failed unexpectedly" >&2
1154 test_done "$testroot" "1"
1155 return 1
1157 local commit2=`git_show_head $testroot/repo`
1159 got ref -r $testroot/repo -c master refs/remotes/origin/master
1160 ret="$?"
1161 if [ "$ret" != "0" ]; then
1162 echo "got ref failed unexpectedly" >&2
1163 test_done "$testroot" "1"
1164 return 1
1167 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1168 ret="$?"
1169 if [ "$ret" != "0" ]; then
1170 echo "got update failed unexpectedly"
1171 test_done "$testroot" "$ret"
1172 return 1
1175 echo "edit $commit2" > $testroot/histedit-script
1176 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1177 2> $testroot/stderr)
1179 echo -n "got: will not edit commit history of a branch outside the " \
1180 > $testroot/stderr.expected
1181 echo '"refs/heads/" reference namespace' \
1182 >> $testroot/stderr.expected
1183 cmp -s $testroot/stderr.expected $testroot/stderr
1184 ret="$?"
1185 if [ "$ret" != "0" ]; then
1186 diff -u $testroot/stderr.expected $testroot/stderr
1188 test_done "$testroot" "$ret"
1191 test_histedit_fold_last_commit_swap() {
1192 local testroot=`test_init histedit_fold_last_commit_swap`
1194 local orig_commit=`git_show_head $testroot/repo`
1196 echo "modified alpha on master" > $testroot/repo/alpha
1197 (cd $testroot/repo && git rm -q beta)
1198 echo "new file on master" > $testroot/repo/epsilon/new
1199 (cd $testroot/repo && git add epsilon/new)
1200 git_commit $testroot/repo -m "committing changes"
1201 local old_commit1=`git_show_head $testroot/repo`
1203 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1204 git_commit $testroot/repo -m "committing to zeta on master"
1205 local old_commit2=`git_show_head $testroot/repo`
1207 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1208 ret="$?"
1209 if [ "$ret" != "0" ]; then
1210 test_done "$testroot" "$ret"
1211 return 1
1214 # fold commit2 into commit1 (requires swapping commits)
1215 echo "fold $old_commit2" > $testroot/histedit-script
1216 echo "pick $old_commit1" >> $testroot/histedit-script
1217 echo "mesg committing folded changes" >> $testroot/histedit-script
1219 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1220 > $testroot/stdout 2> $testroot/stderr)
1222 ret="$?"
1223 if [ "$ret" != "0" ]; then
1224 echo "histedit failed unexpectedly" >&2
1225 test_done "$testroot" "$ret"
1226 return 1
1229 local new_commit=`git_show_head $testroot/repo`
1231 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1232 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1233 local short_new_commit=`trim_obj_id 28 $new_commit`
1235 echo "G epsilon/zeta" >> $testroot/stdout.expected
1236 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1237 >> $testroot/stdout.expected
1238 echo "on master" >> $testroot/stdout.expected
1239 echo "G alpha" >> $testroot/stdout.expected
1240 echo "D beta" >> $testroot/stdout.expected
1241 echo "A epsilon/new" >> $testroot/stdout.expected
1242 echo -n "$short_old_commit1 -> $short_new_commit: " \
1243 >> $testroot/stdout.expected
1244 echo "committing folded changes" >> $testroot/stdout.expected
1245 echo "Switching work tree to refs/heads/master" \
1246 >> $testroot/stdout.expected
1248 cmp -s $testroot/stdout.expected $testroot/stdout
1249 ret="$?"
1250 if [ "$ret" != "0" ]; then
1251 diff -u $testroot/stdout.expected $testroot/stdout
1253 test_done "$testroot" "$ret"
1256 test_histedit_split_commit() {
1257 local testroot=`test_init histedit_split_commit`
1259 local orig_commit=`git_show_head $testroot/repo`
1261 echo "modified alpha on master" > $testroot/repo/alpha
1262 (cd $testroot/repo && git rm -q beta)
1263 echo "new file on master" > $testroot/repo/epsilon/new
1264 (cd $testroot/repo && git add epsilon/new)
1265 git_commit $testroot/repo -m "committing changes 1"
1266 local old_commit1=`git_show_head $testroot/repo`
1267 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1269 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1270 git_commit $testroot/repo -m "committing changes 2"
1271 local old_commit2=`git_show_head $testroot/repo`
1272 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1274 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1275 ret="$?"
1276 if [ "$ret" != "0" ]; then
1277 test_done "$testroot" "$ret"
1278 return 1
1281 # split commit1 into commitA and commitB and commitC
1282 echo "e $old_commit1" > $testroot/histedit-script
1283 echo "p $old_commit2" >> $testroot/histedit-script
1285 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1286 > $testroot/stdout 2> $testroot/stderr)
1287 ret="$?"
1288 if [ "$ret" != "0" ]; then
1289 echo "histedit failed unexpectedly:" >&2
1290 cat $testroot/stderr >&2
1291 test_done "$testroot" "$ret"
1292 return 1
1295 echo "G alpha" > $testroot/stdout.expected
1296 echo "D beta" >> $testroot/stdout.expected
1297 echo "A epsilon/new" >> $testroot/stdout.expected
1298 echo "Stopping histedit for amending commit $old_commit1" \
1299 >> $testroot/stdout.expected
1301 cmp -s $testroot/stdout.expected $testroot/stdout
1302 ret="$?"
1303 if [ "$ret" != "0" ]; then
1304 diff -u $testroot/stdout.expected $testroot/stdout
1305 test_done "$testroot" "$ret"
1306 return 1
1309 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1310 ret="$?"
1311 if [ "$ret" != "0" ]; then
1312 echo "commit failed unexpectedly" >&2
1313 test_done "$testroot" "$ret"
1314 return 1
1317 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1318 ret="$?"
1319 if [ "$ret" != "0" ]; then
1320 echo "commit failed unexpectedly" >&2
1321 test_done "$testroot" "$ret"
1322 return 1
1325 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1326 ret="$?"
1327 if [ "$ret" != "0" ]; then
1328 echo "commit failed unexpectedly" >&2
1329 test_done "$testroot" "$ret"
1330 return 1
1333 (cd $testroot/wt && got histedit -c \
1334 > $testroot/stdout 2> $testroot/stderr)
1335 ret="$?"
1336 if [ "$ret" != "0" ]; then
1337 echo "histedit failed unexpectedly:" >&2
1338 cat $testroot/stderr >&2
1339 test_done "$testroot" "$ret"
1340 return 1
1342 local new_commit2=`git_show_head $testroot/repo`
1343 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1345 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1346 > $testroot/stdout.expected
1347 echo "G epsilon/zeta" >> $testroot/stdout.expected
1348 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1349 >> $testroot/stdout.expected
1350 echo "Switching work tree to refs/heads/master" \
1351 >> $testroot/stdout.expected
1353 cmp -s $testroot/stdout.expected $testroot/stdout
1354 ret="$?"
1355 if [ "$ret" != "0" ]; then
1356 diff -u $testroot/stdout.expected $testroot/stdout
1358 test_done "$testroot" "$ret"
1362 test_histedit_duplicate_commit_in_script() {
1363 local testroot=`test_init histedit_duplicate_commit_in_script`
1365 local orig_commit=`git_show_head $testroot/repo`
1367 echo "modified alpha on master" > $testroot/repo/alpha
1368 (cd $testroot/repo && git rm -q beta)
1369 echo "new file on master" > $testroot/repo/epsilon/new
1370 (cd $testroot/repo && git add epsilon/new)
1371 git_commit $testroot/repo -m "committing changes 1"
1372 local old_commit1=`git_show_head $testroot/repo`
1374 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1375 git_commit $testroot/repo -m "committing changes 2"
1376 local old_commit2=`git_show_head $testroot/repo`
1378 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1379 ret="$?"
1380 if [ "$ret" != "0" ]; then
1381 test_done "$testroot" "$ret"
1382 return 1
1385 # This histedit script lists commit1 more than once
1386 echo "p $old_commit1" > $testroot/histedit-script
1387 echo "p $old_commit1" >> $testroot/histedit-script
1388 echo "p $old_commit2" >> $testroot/histedit-script
1390 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1391 > $testroot/stdout 2> $testroot/stderr)
1392 ret="$?"
1393 if [ "$ret" = "0" ]; then
1394 echo "histedit succeeded unexpectedly:" >&2
1395 cat $testroot/stdout >&2
1396 test_done "$testroot" "$ret"
1397 return 1
1400 echo -n "got: commit $old_commit1 is listed more than once " \
1401 > $testroot/stderr.expected
1402 echo "in histedit script" >> $testroot/stderr.expected
1404 cmp -s $testroot/stderr.expected $testroot/stderr
1405 ret="$?"
1406 if [ "$ret" != "0" ]; then
1407 diff -u $testroot/stderr.expected $testroot/stderr
1409 test_done "$testroot" "$ret"
1413 # if a previous commit introduces a new file, and it is folded into a commit
1414 # that deletes the same file, the file still exists after the histedit
1415 test_histedit_fold_add_delete() {
1416 local testroot=`test_init histedit_fold`
1418 local orig_commit=`git_show_head $testroot/repo`
1420 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1421 (cd $testroot/repo && git add epsilon/psi)
1422 git_commit $testroot/repo -m "committing changes"
1423 local old_commit1=`git_show_head $testroot/repo`
1425 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1426 git_commit $testroot/repo -m "editing psi"
1427 local old_commit2=`git_show_head $testroot/repo`
1429 (cd $testroot/repo && git rm -q epsilon/psi)
1430 git_commit $testroot/repo -m "removing psi"
1431 local old_commit3=`git_show_head $testroot/repo`
1433 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1434 ret="$?"
1435 if [ "$ret" != "0" ]; then
1436 test_done "$testroot" "$ret"
1437 return 1
1440 echo "fold $old_commit1" > $testroot/histedit-script
1441 echo "fold $old_commit2" >> $testroot/histedit-script
1442 echo "pick $old_commit3" >> $testroot/histedit-script
1443 echo "mesg folded changes" >> $testroot/histedit-script
1445 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1446 > $testroot/stdout)
1448 local new_commit1=`git_show_head $testroot/repo`
1450 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1451 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1452 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1453 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1455 echo "A epsilon/psi" >> $testroot/stdout.expected
1456 echo "$short_old_commit1 -> fold commit: committing changes" \
1457 >> $testroot/stdout.expected
1458 echo "G epsilon/psi" >> $testroot/stdout.expected
1459 echo "$short_old_commit2 -> fold commit: editing psi" \
1460 >> $testroot/stdout.expected
1461 echo "D epsilon/psi" >> $testroot/stdout.expected
1462 echo "$short_old_commit3 -> no-op change: folded changes" \
1463 >> $testroot/stdout.expected
1464 echo "Switching work tree to refs/heads/master" \
1465 >> $testroot/stdout.expected
1467 cmp -s $testroot/stdout.expected $testroot/stdout
1468 ret="$?"
1469 if [ "$ret" != "0" ]; then
1470 diff -u $testroot/stdout.expected $testroot/stdout
1471 test_done "$testroot" "$ret"
1472 return 1
1475 if [ -e $testroot/wt/epsilon/psi ]; then
1476 echo "removed file psi still exists on disk" >&2
1477 test_done "$testroot" "1"
1478 return 1
1481 (cd $testroot/wt && got status > $testroot/stdout)
1483 echo -n > $testroot/stdout.expected
1484 cmp -s $testroot/stdout.expected $testroot/stdout
1485 ret="$?"
1486 if [ "$ret" != "0" ]; then
1487 diff -u $testroot/stdout.expected $testroot/stdout
1488 test_done "$testroot" "$ret"
1489 return 1
1492 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1493 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1494 cmp -s $testroot/stdout.expected $testroot/stdout
1495 ret="$?"
1496 if [ "$ret" != "0" ]; then
1497 diff -u $testroot/stdout.expected $testroot/stdout
1498 test_done "$testroot" "$ret"
1499 return 1
1502 got tree -r $testroot/repo epsilon > $testroot/stdout
1503 echo "zeta" > $testroot/stdout.expected
1504 cmp -s $testroot/stdout.expected $testroot/stdout
1505 ret="$?"
1506 if [ "$ret" != "0" ]; then
1507 diff -u $testroot/stdout.expected $testroot/stdout
1509 test_done "$testroot" "$ret"
1512 test_histedit_fold_only() {
1513 local testroot=`test_init histedit_fold_only`
1515 local orig_commit=`git_show_head $testroot/repo`
1517 echo "modified alpha on master" > $testroot/repo/alpha
1518 (cd $testroot/repo && git rm -q beta)
1519 echo "new file on master" > $testroot/repo/epsilon/new
1520 (cd $testroot/repo && git add epsilon/new)
1521 git_commit $testroot/repo -m "committing changes"
1522 local old_commit1=`git_show_head $testroot/repo`
1524 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1525 git_commit $testroot/repo -m "committing to zeta on master"
1526 local old_commit2=`git_show_head $testroot/repo`
1528 echo "modified delta on master" > $testroot/repo/gamma/delta
1529 git_commit $testroot/repo -m "committing to delta on master"
1530 local old_commit3=`git_show_head $testroot/repo`
1532 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1533 ret="$?"
1534 if [ "$ret" != "0" ]; then
1535 test_done "$testroot" "$ret"
1536 return 1
1539 cat > $testroot/editor.sh <<EOF
1540 #!/bin/sh
1541 sed -i 's/.*/committing folded changes/' "\$1"
1542 EOF
1543 chmod +x $testroot/editor.sh
1545 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1546 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1548 local new_commit1=`git_show_head $testroot/repo`
1550 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1551 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1552 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1553 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1554 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1556 echo "G alpha" > $testroot/stdout.expected
1557 echo "D beta" >> $testroot/stdout.expected
1558 echo "A epsilon/new" >> $testroot/stdout.expected
1559 echo "$short_old_commit1 -> fold commit: committing changes" \
1560 >> $testroot/stdout.expected
1561 echo "G epsilon/zeta" >> $testroot/stdout.expected
1562 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1563 echo "fold commit: committing to zeta on master" \
1564 >> $testroot/stdout.expected
1565 echo "G gamma/delta" >> $testroot/stdout.expected
1566 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1567 >> $testroot/stdout.expected
1568 echo "committing folded changes" >> $testroot/stdout.expected
1569 echo "Switching work tree to refs/heads/master" \
1570 >> $testroot/stdout.expected
1572 cmp -s $testroot/stdout.expected $testroot/stdout
1573 ret="$?"
1574 if [ "$ret" != "0" ]; then
1575 diff -u $testroot/stdout.expected $testroot/stdout
1576 test_done "$testroot" "$ret"
1577 return 1
1580 echo "modified alpha on master" > $testroot/content.expected
1581 cat $testroot/wt/alpha > $testroot/content
1582 cmp -s $testroot/content.expected $testroot/content
1583 ret="$?"
1584 if [ "$ret" != "0" ]; then
1585 diff -u $testroot/content.expected $testroot/content
1586 test_done "$testroot" "$ret"
1587 return 1
1590 if [ -e $testroot/wt/beta ]; then
1591 echo "removed file beta still exists on disk" >&2
1592 test_done "$testroot" "1"
1593 return 1
1596 echo "new file on master" > $testroot/content.expected
1597 cat $testroot/wt/epsilon/new > $testroot/content
1598 cmp -s $testroot/content.expected $testroot/content
1599 ret="$?"
1600 if [ "$ret" != "0" ]; then
1601 diff -u $testroot/content.expected $testroot/content
1602 test_done "$testroot" "$ret"
1603 return 1
1606 (cd $testroot/wt && got status > $testroot/stdout)
1608 echo -n > $testroot/stdout.expected
1609 cmp -s $testroot/stdout.expected $testroot/stdout
1610 ret="$?"
1611 if [ "$ret" != "0" ]; then
1612 diff -u $testroot/stdout.expected $testroot/stdout
1613 test_done "$testroot" "$ret"
1614 return 1
1617 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1618 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1619 echo "commit $orig_commit" >> $testroot/stdout.expected
1620 cmp -s $testroot/stdout.expected $testroot/stdout
1621 ret="$?"
1622 if [ "$ret" != "0" ]; then
1623 diff -u $testroot/stdout.expected $testroot/stdout
1625 test_done "$testroot" "$ret"
1628 test_histedit_fold_only_empty_logmsg() {
1629 local testroot=`test_init histedit_fold_only_empty_logmsg`
1631 local orig_commit=`git_show_head $testroot/repo`
1633 echo "modified alpha on master" > $testroot/repo/alpha
1634 (cd $testroot/repo && git rm -q beta)
1635 echo "new file on master" > $testroot/repo/epsilon/new
1636 (cd $testroot/repo && git add epsilon/new)
1637 git_commit $testroot/repo -m "committing changes"
1638 local old_commit1=`git_show_head $testroot/repo`
1640 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1641 git_commit $testroot/repo -m "committing to zeta on master"
1642 local old_commit2=`git_show_head $testroot/repo`
1644 echo "modified delta on master" > $testroot/repo/gamma/delta
1645 git_commit $testroot/repo -m "committing to delta on master"
1646 local old_commit3=`git_show_head $testroot/repo`
1648 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1649 ret="$?"
1650 if [ "$ret" != "0" ]; then
1651 test_done "$testroot" "$ret"
1652 return 1
1655 cat > $testroot/editor.sh <<EOF
1656 #!/bin/sh
1657 sed -i 'd' "\$1"
1658 EOF
1659 chmod +x $testroot/editor.sh
1661 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1662 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1664 local new_commit1=`git_show_head $testroot/repo`
1666 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1667 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1668 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1669 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1670 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1671 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1673 echo "G alpha" > $testroot/stdout.expected
1674 echo "D beta" >> $testroot/stdout.expected
1675 echo "A epsilon/new" >> $testroot/stdout.expected
1676 echo "$short_old_commit1 -> fold commit: committing changes" \
1677 >> $testroot/stdout.expected
1678 echo "G epsilon/zeta" >> $testroot/stdout.expected
1679 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1680 echo "fold commit: committing to zeta on master" \
1681 >> $testroot/stdout.expected
1682 echo "G gamma/delta" >> $testroot/stdout.expected
1683 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1684 >> $testroot/stdout.expected
1685 echo "# log message of folded commit $very_short_old_commit1" \
1686 >> $testroot/stdout.expected
1687 echo "Switching work tree to refs/heads/master" \
1688 >> $testroot/stdout.expected
1690 cmp -s $testroot/stdout.expected $testroot/stdout
1691 ret="$?"
1692 if [ "$ret" != "0" ]; then
1693 diff -u $testroot/stdout.expected $testroot/stdout
1694 test_done "$testroot" "$ret"
1695 return 1
1698 echo "modified alpha on master" > $testroot/content.expected
1699 cat $testroot/wt/alpha > $testroot/content
1700 cmp -s $testroot/content.expected $testroot/content
1701 ret="$?"
1702 if [ "$ret" != "0" ]; then
1703 diff -u $testroot/content.expected $testroot/content
1704 test_done "$testroot" "$ret"
1705 return 1
1708 if [ -e $testroot/wt/beta ]; then
1709 echo "removed file beta still exists on disk" >&2
1710 test_done "$testroot" "1"
1711 return 1
1714 echo "new file on master" > $testroot/content.expected
1715 cat $testroot/wt/epsilon/new > $testroot/content
1716 cmp -s $testroot/content.expected $testroot/content
1717 ret="$?"
1718 if [ "$ret" != "0" ]; then
1719 diff -u $testroot/content.expected $testroot/content
1720 test_done "$testroot" "$ret"
1721 return 1
1724 (cd $testroot/wt && got status > $testroot/stdout)
1726 echo -n > $testroot/stdout.expected
1727 cmp -s $testroot/stdout.expected $testroot/stdout
1728 ret="$?"
1729 if [ "$ret" != "0" ]; then
1730 diff -u $testroot/stdout.expected $testroot/stdout
1731 test_done "$testroot" "$ret"
1732 return 1
1735 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1736 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1737 echo "commit $orig_commit" >> $testroot/stdout.expected
1738 cmp -s $testroot/stdout.expected $testroot/stdout
1739 ret="$?"
1740 if [ "$ret" != "0" ]; then
1741 diff -u $testroot/stdout.expected $testroot/stdout
1743 test_done "$testroot" "$ret"
1746 test_parseargs "$@"
1747 run_test test_histedit_no_op
1748 run_test test_histedit_swap
1749 run_test test_histedit_drop
1750 run_test test_histedit_fold
1751 run_test test_histedit_edit
1752 run_test test_histedit_fold_last_commit
1753 run_test test_histedit_missing_commit
1754 run_test test_histedit_abort
1755 run_test test_histedit_path_prefix_drop
1756 run_test test_histedit_path_prefix_edit
1757 run_test test_histedit_outside_refs_heads
1758 run_test test_histedit_fold_last_commit_swap
1759 run_test test_histedit_split_commit
1760 run_test test_histedit_duplicate_commit_in_script
1761 run_test test_histedit_fold_add_delete
1762 run_test test_histedit_fold_only
1763 run_test test_histedit_fold_only_empty_logmsg