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 fi
175 test_done "$testroot" "$ret"
178 test_histedit_swap() {
179 local testroot=`test_init histedit_swap`
181 local orig_commit=`git_show_head $testroot/repo`
183 echo "modified alpha on master" > $testroot/repo/alpha
184 (cd $testroot/repo && git rm -q beta)
185 echo "new file on master" > $testroot/repo/epsilon/new
186 (cd $testroot/repo && git add epsilon/new)
187 git_commit $testroot/repo -m "committing changes"
188 local old_commit1=`git_show_head $testroot/repo`
190 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
191 git_commit $testroot/repo -m "committing to zeta on master"
192 local old_commit2=`git_show_head $testroot/repo`
194 got diff -r $testroot/repo $orig_commit $old_commit2 \
195 > $testroot/diff.expected
197 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
198 ret="$?"
199 if [ "$ret" != "0" ]; then
200 test_done "$testroot" "$ret"
201 return 1
202 fi
204 echo "pick $old_commit2" > $testroot/histedit-script
205 echo "pick $old_commit1" >> $testroot/histedit-script
207 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
208 > $testroot/stdout)
210 local new_commit2=`git_show_parent_commit $testroot/repo`
211 local new_commit1=`git_show_head $testroot/repo`
213 local short_old_commit1=`trim_obj_id 28 $old_commit1`
214 local short_old_commit2=`trim_obj_id 28 $old_commit2`
215 local short_new_commit1=`trim_obj_id 28 $new_commit1`
216 local short_new_commit2=`trim_obj_id 28 $new_commit2`
218 echo "G epsilon/zeta" > $testroot/stdout.expected
219 echo -n "$short_old_commit2 -> $short_new_commit2: " \
220 >> $testroot/stdout.expected
221 echo "committing to zeta on master" >> $testroot/stdout.expected
222 echo "G alpha" >> $testroot/stdout.expected
223 echo "D beta" >> $testroot/stdout.expected
224 echo "A epsilon/new" >> $testroot/stdout.expected
225 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
226 >> $testroot/stdout.expected
227 echo "Switching work tree to refs/heads/master" \
228 >> $testroot/stdout.expected
230 cmp -s $testroot/stdout.expected $testroot/stdout
231 ret="$?"
232 if [ "$ret" != "0" ]; then
233 diff -u $testroot/stdout.expected $testroot/stdout
234 test_done "$testroot" "$ret"
235 return 1
236 fi
238 echo "modified alpha on master" > $testroot/content.expected
239 cat $testroot/wt/alpha > $testroot/content
240 cmp -s $testroot/content.expected $testroot/content
241 ret="$?"
242 if [ "$ret" != "0" ]; then
243 diff -u $testroot/content.expected $testroot/content
244 test_done "$testroot" "$ret"
245 return 1
246 fi
248 if [ -e $testroot/wt/beta ]; then
249 echo "removed file beta still exists on disk" >&2
250 test_done "$testroot" "1"
251 return 1
252 fi
254 echo "new file on master" > $testroot/content.expected
255 cat $testroot/wt/epsilon/new > $testroot/content
256 cmp -s $testroot/content.expected $testroot/content
257 ret="$?"
258 if [ "$ret" != "0" ]; then
259 diff -u $testroot/content.expected $testroot/content
260 test_done "$testroot" "$ret"
261 return 1
262 fi
264 (cd $testroot/wt && got status > $testroot/stdout)
266 echo -n > $testroot/stdout.expected
267 cmp -s $testroot/stdout.expected $testroot/stdout
268 ret="$?"
269 if [ "$ret" != "0" ]; then
270 diff -u $testroot/stdout.expected $testroot/stdout
271 test_done "$testroot" "$ret"
272 return 1
273 fi
275 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
276 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
277 echo "commit $new_commit2" >> $testroot/stdout.expected
278 echo "commit $orig_commit" >> $testroot/stdout.expected
279 cmp -s $testroot/stdout.expected $testroot/stdout
280 ret="$?"
281 if [ "$ret" != "0" ]; then
282 diff -u $testroot/stdout.expected $testroot/stdout
283 test_done "$testroot" "$ret"
284 return 1
285 fi
287 got diff -r $testroot/repo $orig_commit $new_commit1 \
288 > $testroot/diff
289 sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
290 cmp -s $testroot/diff.expected $testroot/diff
291 ret="$?"
292 if [ "$ret" != "0" ]; then
293 diff -u $testroot/diff.expected $testroot/diff
294 fi
295 test_done "$testroot" "$ret"
298 test_histedit_drop() {
299 local testroot=`test_init histedit_drop`
300 local orig_commit=`git_show_head $testroot/repo`
302 echo "modified alpha on master" > $testroot/repo/alpha
303 (cd $testroot/repo && git rm -q beta)
304 echo "new file on master" > $testroot/repo/epsilon/new
305 (cd $testroot/repo && git add epsilon/new)
306 git_commit $testroot/repo -m "committing changes"
307 local old_commit1=`git_show_head $testroot/repo`
309 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
310 git_commit $testroot/repo -m "committing to zeta on master"
311 local old_commit2=`git_show_head $testroot/repo`
313 got diff -r $testroot/repo $old_commit1 $old_commit2 \
314 > $testroot/diff.expected
316 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
317 ret="$?"
318 if [ "$ret" != "0" ]; then
319 test_done "$testroot" "$ret"
320 return 1
321 fi
323 echo "drop $old_commit1" > $testroot/histedit-script
324 echo "pick $old_commit2" >> $testroot/histedit-script
326 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
327 > $testroot/stdout)
329 local new_commit2=`git_show_head $testroot/repo`
331 local short_old_commit1=`trim_obj_id 28 $old_commit1`
332 local short_old_commit2=`trim_obj_id 28 $old_commit2`
333 local short_new_commit2=`trim_obj_id 28 $new_commit2`
335 echo "$short_old_commit1 -> drop commit: committing changes" \
336 > $testroot/stdout.expected
337 echo "G epsilon/zeta" >> $testroot/stdout.expected
338 echo -n "$short_old_commit2 -> $short_new_commit2: " \
339 >> $testroot/stdout.expected
340 echo "committing to zeta on master" >> $testroot/stdout.expected
341 echo "Switching work tree to refs/heads/master" \
342 >> $testroot/stdout.expected
344 cmp -s $testroot/stdout.expected $testroot/stdout
345 ret="$?"
346 if [ "$ret" != "0" ]; then
347 diff -u $testroot/stdout.expected $testroot/stdout
348 test_done "$testroot" "$ret"
349 return 1
350 fi
352 for f in alpha beta; do
353 echo "$f" > $testroot/content.expected
354 cat $testroot/wt/$f > $testroot/content
355 cmp -s $testroot/content.expected $testroot/content
356 ret="$?"
357 if [ "$ret" != "0" ]; then
358 diff -u $testroot/content.expected $testroot/content
359 test_done "$testroot" "$ret"
360 return 1
361 fi
362 done
364 if [ -e $testroot/wt/new ]; then
365 echo "file new exists on disk but should not" >&2
366 test_done "$testroot" "1"
367 return 1
368 fi
370 (cd $testroot/wt && got status > $testroot/stdout)
372 echo -n > $testroot/stdout.expected
373 cmp -s $testroot/stdout.expected $testroot/stdout
374 ret="$?"
375 if [ "$ret" != "0" ]; then
376 diff -u $testroot/stdout.expected $testroot/stdout
377 test_done "$testroot" "$ret"
378 return 1
379 fi
381 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
382 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
383 echo "commit $orig_commit" >> $testroot/stdout.expected
384 cmp -s $testroot/stdout.expected $testroot/stdout
385 ret="$?"
386 if [ "$ret" != "0" ]; then
387 diff -u $testroot/stdout.expected $testroot/stdout
388 test_done "$testroot" "$ret"
389 return 1
390 fi
392 got diff -r $testroot/repo $orig_commit $new_commit2 \
393 > $testroot/diff
394 sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
395 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
396 cmp -s $testroot/diff.expected $testroot/diff
397 ret="$?"
398 if [ "$ret" != "0" ]; then
399 diff -u $testroot/diff.expected $testroot/diff
400 fi
401 test_done "$testroot" "$ret"
404 test_histedit_fold() {
405 local testroot=`test_init histedit_fold`
407 local orig_commit=`git_show_head $testroot/repo`
409 echo "modified alpha on master" > $testroot/repo/alpha
410 (cd $testroot/repo && git rm -q beta)
411 echo "new file on master" > $testroot/repo/epsilon/new
412 (cd $testroot/repo && git add epsilon/new)
413 git_commit $testroot/repo -m "committing changes"
414 local old_commit1=`git_show_head $testroot/repo`
416 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
417 git_commit $testroot/repo -m "committing to zeta on master"
418 local old_commit2=`git_show_head $testroot/repo`
420 echo "modified delta on master" > $testroot/repo/gamma/delta
421 git_commit $testroot/repo -m "committing to delta on master"
422 local old_commit3=`git_show_head $testroot/repo`
424 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
425 ret="$?"
426 if [ "$ret" != "0" ]; then
427 test_done "$testroot" "$ret"
428 return 1
429 fi
431 echo "fold $old_commit1" > $testroot/histedit-script
432 echo "drop $old_commit2" >> $testroot/histedit-script
433 echo "pick $old_commit3" >> $testroot/histedit-script
434 echo "mesg committing folded changes" >> $testroot/histedit-script
436 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
437 > $testroot/stdout)
439 local new_commit1=`git_show_parent_commit $testroot/repo`
440 local new_commit2=`git_show_head $testroot/repo`
442 local short_old_commit1=`trim_obj_id 28 $old_commit1`
443 local short_old_commit2=`trim_obj_id 28 $old_commit2`
444 local short_old_commit3=`trim_obj_id 28 $old_commit3`
445 local short_new_commit1=`trim_obj_id 28 $new_commit1`
446 local short_new_commit2=`trim_obj_id 28 $new_commit2`
448 echo "G alpha" > $testroot/stdout.expected
449 echo "D beta" >> $testroot/stdout.expected
450 echo "A epsilon/new" >> $testroot/stdout.expected
451 echo "$short_old_commit1 -> fold commit: committing changes" \
452 >> $testroot/stdout.expected
453 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
454 echo "drop commit: committing to zeta on master" \
455 >> $testroot/stdout.expected
456 echo "G gamma/delta" >> $testroot/stdout.expected
457 echo -n "$short_old_commit3 -> $short_new_commit2: " \
458 >> $testroot/stdout.expected
459 echo "committing folded changes" >> $testroot/stdout.expected
460 echo "Switching work tree to refs/heads/master" \
461 >> $testroot/stdout.expected
463 cmp -s $testroot/stdout.expected $testroot/stdout
464 ret="$?"
465 if [ "$ret" != "0" ]; then
466 diff -u $testroot/stdout.expected $testroot/stdout
467 test_done "$testroot" "$ret"
468 return 1
469 fi
471 echo "modified alpha on master" > $testroot/content.expected
472 cat $testroot/wt/alpha > $testroot/content
473 cmp -s $testroot/content.expected $testroot/content
474 ret="$?"
475 if [ "$ret" != "0" ]; then
476 diff -u $testroot/content.expected $testroot/content
477 test_done "$testroot" "$ret"
478 return 1
479 fi
481 if [ -e $testroot/wt/beta ]; then
482 echo "removed file beta still exists on disk" >&2
483 test_done "$testroot" "1"
484 return 1
485 fi
487 echo "new file on master" > $testroot/content.expected
488 cat $testroot/wt/epsilon/new > $testroot/content
489 cmp -s $testroot/content.expected $testroot/content
490 ret="$?"
491 if [ "$ret" != "0" ]; then
492 diff -u $testroot/content.expected $testroot/content
493 test_done "$testroot" "$ret"
494 return 1
495 fi
497 (cd $testroot/wt && got status > $testroot/stdout)
499 echo -n > $testroot/stdout.expected
500 cmp -s $testroot/stdout.expected $testroot/stdout
501 ret="$?"
502 if [ "$ret" != "0" ]; then
503 diff -u $testroot/stdout.expected $testroot/stdout
504 test_done "$testroot" "$ret"
505 return 1
506 fi
508 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
509 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
510 echo "commit $orig_commit" >> $testroot/stdout.expected
511 cmp -s $testroot/stdout.expected $testroot/stdout
512 ret="$?"
513 if [ "$ret" != "0" ]; then
514 diff -u $testroot/stdout.expected $testroot/stdout
515 fi
516 test_done "$testroot" "$ret"
519 test_histedit_edit() {
520 local testroot=`test_init histedit_edit`
522 local orig_commit=`git_show_head $testroot/repo`
524 echo "modified alpha on master" > $testroot/repo/alpha
525 (cd $testroot/repo && git rm -q beta)
526 echo "new file on master" > $testroot/repo/epsilon/new
527 (cd $testroot/repo && git add epsilon/new)
528 git_commit $testroot/repo -m "committing changes"
529 local old_commit1=`git_show_head $testroot/repo`
531 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
532 git_commit $testroot/repo -m "committing to zeta on master"
533 local old_commit2=`git_show_head $testroot/repo`
535 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
536 ret="$?"
537 if [ "$ret" != "0" ]; then
538 test_done "$testroot" "$ret"
539 return 1
540 fi
542 echo "edit $old_commit1" > $testroot/histedit-script
543 echo "mesg committing changes" >> $testroot/histedit-script
544 echo "pick $old_commit2" >> $testroot/histedit-script
546 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
547 > $testroot/stdout)
549 local short_old_commit1=`trim_obj_id 28 $old_commit1`
550 local short_old_commit2=`trim_obj_id 28 $old_commit2`
552 echo "G alpha" > $testroot/stdout.expected
553 echo "D beta" >> $testroot/stdout.expected
554 echo "A epsilon/new" >> $testroot/stdout.expected
555 echo "Stopping histedit for amending commit $old_commit1" \
556 >> $testroot/stdout.expected
557 cmp -s $testroot/stdout.expected $testroot/stdout
558 ret="$?"
559 if [ "$ret" != "0" ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
562 return 1
563 fi
565 echo "edited modified alpha on master" > $testroot/wt/alpha
567 # test interaction of 'got stage' and histedit -c
568 (cd $testroot/wt && got stage alpha > /dev/null)
569 (cd $testroot/wt && got histedit -c > $testroot/stdout \
570 2> $testroot/stderr)
571 ret="$?"
572 if [ "$ret" = "0" ]; then
573 echo "histedit succeeded unexpectedly" >&2
574 test_done "$testroot" "1"
575 return 1
576 fi
577 echo -n "got: work tree contains files with staged changes; " \
578 > $testroot/stderr.expected
579 echo "these changes must be committed or unstaged first" \
580 >> $testroot/stderr.expected
581 cmp -s $testroot/stderr.expected $testroot/stderr
582 ret="$?"
583 if [ "$ret" != "0" ]; then
584 diff -u $testroot/stderr.expected $testroot/stderr
585 test_done "$testroot" "$ret"
586 return 1
587 fi
589 (cd $testroot/wt && got unstage alpha > /dev/null)
590 (cd $testroot/wt && got histedit -c > $testroot/stdout)
592 local new_commit1=`git_show_parent_commit $testroot/repo`
593 local new_commit2=`git_show_head $testroot/repo`
595 local short_new_commit1=`trim_obj_id 28 $new_commit1`
596 local short_new_commit2=`trim_obj_id 28 $new_commit2`
598 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
599 > $testroot/stdout.expected
600 echo "G epsilon/zeta" >> $testroot/stdout.expected
601 echo -n "$short_old_commit2 -> $short_new_commit2: " \
602 >> $testroot/stdout.expected
603 echo "committing to zeta on master" >> $testroot/stdout.expected
604 echo "Switching work tree to refs/heads/master" \
605 >> $testroot/stdout.expected
607 cmp -s $testroot/stdout.expected $testroot/stdout
608 ret="$?"
609 if [ "$ret" != "0" ]; then
610 diff -u $testroot/stdout.expected $testroot/stdout
611 test_done "$testroot" "$ret"
612 return 1
613 fi
615 echo "edited modified alpha on master" > $testroot/content.expected
616 cat $testroot/wt/alpha > $testroot/content
617 cmp -s $testroot/content.expected $testroot/content
618 ret="$?"
619 if [ "$ret" != "0" ]; then
620 diff -u $testroot/content.expected $testroot/content
621 test_done "$testroot" "$ret"
622 return 1
623 fi
625 if [ -e $testroot/wt/beta ]; then
626 echo "removed file beta still exists on disk" >&2
627 test_done "$testroot" "1"
628 return 1
629 fi
631 echo "new file on master" > $testroot/content.expected
632 cat $testroot/wt/epsilon/new > $testroot/content
633 cmp -s $testroot/content.expected $testroot/content
634 ret="$?"
635 if [ "$ret" != "0" ]; then
636 diff -u $testroot/content.expected $testroot/content
637 test_done "$testroot" "$ret"
638 return 1
639 fi
641 (cd $testroot/wt && got status > $testroot/stdout)
643 echo -n > $testroot/stdout.expected
644 cmp -s $testroot/stdout.expected $testroot/stdout
645 ret="$?"
646 if [ "$ret" != "0" ]; then
647 diff -u $testroot/stdout.expected $testroot/stdout
648 test_done "$testroot" "$ret"
649 return 1
650 fi
652 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
653 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
654 echo "commit $new_commit1" >> $testroot/stdout.expected
655 echo "commit $orig_commit" >> $testroot/stdout.expected
656 cmp -s $testroot/stdout.expected $testroot/stdout
657 ret="$?"
658 if [ "$ret" != "0" ]; then
659 diff -u $testroot/stdout.expected $testroot/stdout
660 fi
661 test_done "$testroot" "$ret"
664 test_histedit_fold_last_commit() {
665 local testroot=`test_init histedit_fold_last_commit`
667 local orig_commit=`git_show_head $testroot/repo`
669 echo "modified alpha on master" > $testroot/repo/alpha
670 (cd $testroot/repo && git rm -q beta)
671 echo "new file on master" > $testroot/repo/epsilon/new
672 (cd $testroot/repo && git add epsilon/new)
673 git_commit $testroot/repo -m "committing changes"
674 local old_commit1=`git_show_head $testroot/repo`
676 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
677 git_commit $testroot/repo -m "committing to zeta on master"
678 local old_commit2=`git_show_head $testroot/repo`
680 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
681 ret="$?"
682 if [ "$ret" != "0" ]; then
683 test_done "$testroot" "$ret"
684 return 1
685 fi
687 echo "pick $old_commit1" > $testroot/histedit-script
688 echo "fold $old_commit2" >> $testroot/histedit-script
689 echo "mesg committing folded changes" >> $testroot/histedit-script
691 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
692 > $testroot/stdout 2> $testroot/stderr)
694 ret="$?"
695 if [ "$ret" = "0" ]; then
696 echo "histedit succeeded unexpectedly" >&2
697 test_done "$testroot" "1"
698 return 1
699 fi
701 echo "got: last commit in histedit script cannot be folded" \
702 > $testroot/stderr.expected
704 cmp -s $testroot/stderr.expected $testroot/stderr
705 ret="$?"
706 if [ "$ret" != "0" ]; then
707 diff -u $testroot/stderr.expected $testroot/stderr
708 fi
709 test_done "$testroot" "$ret"
712 test_histedit_missing_commit() {
713 local testroot=`test_init histedit_missing_commit`
715 local orig_commit=`git_show_head $testroot/repo`
717 echo "modified alpha on master" > $testroot/repo/alpha
718 (cd $testroot/repo && git rm -q beta)
719 echo "new file on master" > $testroot/repo/epsilon/new
720 (cd $testroot/repo && git add epsilon/new)
721 git_commit $testroot/repo -m "committing changes"
722 local old_commit1=`git_show_head $testroot/repo`
724 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
725 git_commit $testroot/repo -m "committing to zeta on master"
726 local old_commit2=`git_show_head $testroot/repo`
728 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
729 ret="$?"
730 if [ "$ret" != "0" ]; then
731 test_done "$testroot" "$ret"
732 return 1
733 fi
735 echo "pick $old_commit1" > $testroot/histedit-script
736 echo "mesg committing changes" >> $testroot/histedit-script
738 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
739 > $testroot/stdout 2> $testroot/stderr)
741 ret="$?"
742 if [ "$ret" = "0" ]; then
743 echo "histedit succeeded unexpectedly" >&2
744 test_done "$testroot" "1"
745 return 1
746 fi
748 echo "got: commit $old_commit2 missing from histedit script" \
749 > $testroot/stderr.expected
751 cmp -s $testroot/stderr.expected $testroot/stderr
752 ret="$?"
753 if [ "$ret" != "0" ]; then
754 diff -u $testroot/stderr.expected $testroot/stderr
755 fi
756 test_done "$testroot" "$ret"
759 test_histedit_abort() {
760 local testroot=`test_init histedit_abort`
762 local orig_commit=`git_show_head $testroot/repo`
764 echo "modified alpha on master" > $testroot/repo/alpha
765 (cd $testroot/repo && git rm -q beta)
766 echo "new file on master" > $testroot/repo/epsilon/new
767 (cd $testroot/repo && git add epsilon/new)
768 git_commit $testroot/repo -m "committing changes"
769 local old_commit1=`git_show_head $testroot/repo`
771 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
772 git_commit $testroot/repo -m "committing to zeta on master"
773 local old_commit2=`git_show_head $testroot/repo`
775 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
776 ret="$?"
777 if [ "$ret" != "0" ]; then
778 test_done "$testroot" "$ret"
779 return 1
780 fi
782 echo "edit $old_commit1" > $testroot/histedit-script
783 echo "mesg committing changes" >> $testroot/histedit-script
784 echo "pick $old_commit2" >> $testroot/histedit-script
786 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
787 > $testroot/stdout)
789 local short_old_commit1=`trim_obj_id 28 $old_commit1`
790 local short_old_commit2=`trim_obj_id 28 $old_commit2`
792 echo "G alpha" > $testroot/stdout.expected
793 echo "D beta" >> $testroot/stdout.expected
794 echo "A epsilon/new" >> $testroot/stdout.expected
795 echo "Stopping histedit for amending commit $old_commit1" \
796 >> $testroot/stdout.expected
797 cmp -s $testroot/stdout.expected $testroot/stdout
798 ret="$?"
799 if [ "$ret" != "0" ]; then
800 diff -u $testroot/stdout.expected $testroot/stdout
801 test_done "$testroot" "$ret"
802 return 1
803 fi
805 echo "edited modified alpha on master" > $testroot/wt/alpha
807 (cd $testroot/wt && got histedit -a > $testroot/stdout)
809 local new_commit1=`git_show_parent_commit $testroot/repo`
810 local new_commit2=`git_show_head $testroot/repo`
812 echo "Switching work tree to refs/heads/master" \
813 > $testroot/stdout.expected
814 echo "R alpha" >> $testroot/stdout.expected
815 echo "R beta" >> $testroot/stdout.expected
816 echo "R epsilon/new" >> $testroot/stdout.expected
817 echo "Histedit of refs/heads/master aborted" \
818 >> $testroot/stdout.expected
820 cmp -s $testroot/stdout.expected $testroot/stdout
821 ret="$?"
822 if [ "$ret" != "0" ]; then
823 diff -u $testroot/stdout.expected $testroot/stdout
824 test_done "$testroot" "$ret"
825 return 1
826 fi
828 for f in alpha beta; do
829 echo "$f" > $testroot/content.expected
830 cat $testroot/wt/$f > $testroot/content
831 cmp -s $testroot/content.expected $testroot/content
832 ret="$?"
833 if [ "$ret" != "0" ]; then
834 diff -u $testroot/content.expected $testroot/content
835 test_done "$testroot" "$ret"
836 return 1
837 fi
838 done
840 echo "new file on master" > $testroot/content.expected
841 cat $testroot/wt/epsilon/new > $testroot/content
842 cmp -s $testroot/content.expected $testroot/content
843 ret="$?"
844 if [ "$ret" != "0" ]; then
845 diff -u $testroot/content.expected $testroot/content
846 test_done "$testroot" "$ret"
847 return 1
848 fi
850 (cd $testroot/wt && got status > $testroot/stdout)
852 echo "? epsilon/new" > $testroot/stdout.expected
853 cmp -s $testroot/stdout.expected $testroot/stdout
854 ret="$?"
855 if [ "$ret" != "0" ]; then
856 diff -u $testroot/stdout.expected $testroot/stdout
857 test_done "$testroot" "$ret"
858 return 1
859 fi
861 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
862 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
863 echo "commit $new_commit1" >> $testroot/stdout.expected
864 echo "commit $orig_commit" >> $testroot/stdout.expected
865 cmp -s $testroot/stdout.expected $testroot/stdout
866 ret="$?"
867 if [ "$ret" != "0" ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
869 fi
870 test_done "$testroot" "$ret"
873 test_histedit_path_prefix_drop() {
874 local testroot=`test_init histedit_path_prefix_drop`
875 local orig_commit=`git_show_head $testroot/repo`
877 echo "modified zeta" > $testroot/repo/epsilon/zeta
878 git_commit $testroot/repo -m "changing zeta"
879 local old_commit1=`git_show_head $testroot/repo`
881 got checkout -c $orig_commit -p gamma $testroot/repo \
882 $testroot/wt > /dev/null
883 ret="$?"
884 if [ "$ret" != "0" ]; then
885 test_done "$testroot" "$ret"
886 return 1
887 fi
889 echo "drop $old_commit1" > $testroot/histedit-script
891 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
892 > $testroot/stdout 2> $testroot/stderr)
894 ret="$?"
895 if [ "$ret" = "0" ]; then
896 echo "histedit succeeded unexpectedly" >&2
897 test_done "$testroot" "1"
898 return 1
899 fi
901 echo -n "got: cannot edit branch history which contains changes " \
902 > $testroot/stderr.expected
903 echo "outside of this work tree's path prefix" \
904 >> $testroot/stderr.expected
906 cmp -s $testroot/stderr.expected $testroot/stderr
907 ret="$?"
908 if [ "$ret" != "0" ]; then
909 diff -u $testroot/stderr.expected $testroot/stderr
910 test_done "$testroot" "$ret"
911 return 1
912 fi
914 rm -rf $testroot/wt
915 got checkout -c $orig_commit -p epsilon $testroot/repo \
916 $testroot/wt > /dev/null
917 ret="$?"
918 if [ "$ret" != "0" ]; then
919 test_done "$testroot" "$ret"
920 return 1
921 fi
922 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
923 > $testroot/stdout)
925 local short_old_commit1=`trim_obj_id 28 $old_commit1`
926 local short_old_commit2=`trim_obj_id 28 $old_commit2`
928 echo "$short_old_commit1 -> drop commit: changing zeta" \
929 > $testroot/stdout.expected
930 echo "Switching work tree to refs/heads/master" \
931 >> $testroot/stdout.expected
933 cmp -s $testroot/stdout.expected $testroot/stdout
934 ret="$?"
935 if [ "$ret" != "0" ]; then
936 diff -u $testroot/stdout.expected $testroot/stdout
937 test_done "$testroot" "$ret"
938 return 1
939 fi
941 echo "zeta" > $testroot/content.expected
942 cat $testroot/wt/zeta > $testroot/content
943 cmp -s $testroot/content.expected $testroot/content
944 ret="$?"
945 if [ "$ret" != "0" ]; then
946 diff -u $testroot/content.expected $testroot/content
947 test_done "$testroot" "$ret"
948 return 1
949 fi
952 (cd $testroot/wt && got status > $testroot/stdout)
954 echo -n > $testroot/stdout.expected
955 cmp -s $testroot/stdout.expected $testroot/stdout
956 ret="$?"
957 if [ "$ret" != "0" ]; then
958 diff -u $testroot/stdout.expected $testroot/stdout
959 test_done "$testroot" "$ret"
960 return 1
961 fi
963 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
964 echo "commit $orig_commit (master)" > $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 fi
970 test_done "$testroot" "$ret"
973 test_histedit_path_prefix_edit() {
974 local testroot=`test_init histedit_path_prefix_edit`
975 local orig_commit=`git_show_head $testroot/repo`
977 echo "modified zeta" > $testroot/repo/epsilon/zeta
978 git_commit $testroot/repo -m "changing zeta"
979 local old_commit1=`git_show_head $testroot/repo`
981 got diff -r $testroot/repo $orig_commit $old_commit1 \
982 > $testroot/diff.expected
984 got checkout -c $orig_commit -p gamma $testroot/repo \
985 $testroot/wt > /dev/null
986 ret="$?"
987 if [ "$ret" != "0" ]; then
988 test_done "$testroot" "$ret"
989 return 1
990 fi
992 echo "edit $old_commit1" > $testroot/histedit-script
993 echo "mesg modified zeta" >> $testroot/histedit-script
995 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
996 > $testroot/stdout 2> $testroot/stderr)
998 ret="$?"
999 if [ "$ret" = "0" ]; then
1000 echo "histedit succeeded unexpectedly" >&2
1001 test_done "$testroot" "1"
1002 return 1
1005 echo -n "got: cannot edit branch history which contains changes " \
1006 > $testroot/stderr.expected
1007 echo "outside of this work tree's path prefix" \
1008 >> $testroot/stderr.expected
1010 cmp -s $testroot/stderr.expected $testroot/stderr
1011 ret="$?"
1012 if [ "$ret" != "0" ]; then
1013 diff -u $testroot/stderr.expected $testroot/stderr
1014 test_done "$testroot" "$ret"
1015 return 1
1018 rm -rf $testroot/wt
1019 got checkout -c $orig_commit -p epsilon $testroot/repo \
1020 $testroot/wt > /dev/null
1021 ret="$?"
1022 if [ "$ret" != "0" ]; then
1023 test_done "$testroot" "$ret"
1024 return 1
1026 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1027 > $testroot/stdout)
1029 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1031 echo "G zeta" > $testroot/stdout.expected
1032 echo "Stopping histedit for amending commit $old_commit1" \
1033 >> $testroot/stdout.expected
1034 cmp -s $testroot/stdout.expected $testroot/stdout
1035 ret="$?"
1036 if [ "$ret" != "0" ]; then
1037 diff -u $testroot/stdout.expected $testroot/stdout
1038 test_done "$testroot" "$ret"
1039 return 1
1042 echo "modified zeta" > $testroot/content.expected
1043 cat $testroot/wt/zeta > $testroot/content
1044 cmp -s $testroot/content.expected $testroot/content
1045 ret="$?"
1046 if [ "$ret" != "0" ]; then
1047 diff -u $testroot/content.expected $testroot/content
1048 test_done "$testroot" "$ret"
1049 return 1
1052 (cd $testroot/wt && got status > $testroot/stdout)
1054 echo "M zeta"> $testroot/stdout.expected
1055 cmp -s $testroot/stdout.expected $testroot/stdout
1056 ret="$?"
1057 if [ "$ret" != "0" ]; then
1058 diff -u $testroot/stdout.expected $testroot/stdout
1059 test_done "$testroot" "$ret"
1060 return 1
1063 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1065 local new_commit1=`git_show_head $testroot/repo`
1066 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1068 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1069 > $testroot/stdout.expected
1070 echo "modified zeta" >> $testroot/stdout.expected
1071 echo "Switching work tree to refs/heads/master" \
1072 >> $testroot/stdout.expected
1074 cmp -s $testroot/stdout.expected $testroot/stdout
1075 ret="$?"
1076 if [ "$ret" != "0" ]; then
1077 diff -u $testroot/stdout.expected $testroot/stdout
1078 test_done "$testroot" "$ret"
1079 return 1
1082 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1083 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1084 echo "commit $orig_commit" >> $testroot/stdout.expected
1085 cmp -s $testroot/stdout.expected $testroot/stdout
1086 ret="$?"
1087 if [ "$ret" != "0" ]; then
1088 diff -u $testroot/stdout.expected $testroot/stdout
1089 test_done "$testroot" "$ret"
1090 return 1
1093 got diff -r $testroot/repo $orig_commit $new_commit1 \
1094 > $testroot/diff
1095 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1096 cmp -s $testroot/diff.expected $testroot/diff
1097 ret="$?"
1098 if [ "$ret" != "0" ]; then
1099 diff -u $testroot/diff.expected $testroot/diff
1101 test_done "$testroot" "$ret"
1104 test_histedit_outside_refs_heads() {
1105 local testroot=`test_init histedit_outside_refs_heads`
1106 local commit1=`git_show_head $testroot/repo`
1108 got checkout $testroot/repo $testroot/wt > /dev/null
1109 ret="$?"
1110 if [ "$ret" != "0" ]; then
1111 echo "got checkout failed unexpectedly"
1112 test_done "$testroot" "$ret"
1113 return 1
1116 echo "modified alpha" > $testroot/wt/alpha
1118 (cd $testroot/wt && got commit -m 'change alpha' \
1119 > $testroot/stdout 2> $testroot/stderr)
1120 ret="$?"
1121 if [ "$ret" != "0" ]; then
1122 echo "got commit failed unexpectedly" >&2
1123 test_done "$testroot" "1"
1124 return 1
1126 local commit2=`git_show_head $testroot/repo`
1128 got ref -r $testroot/repo -c master refs/remotes/origin/master
1129 ret="$?"
1130 if [ "$ret" != "0" ]; then
1131 echo "got ref failed unexpectedly" >&2
1132 test_done "$testroot" "1"
1133 return 1
1136 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1137 ret="$?"
1138 if [ "$ret" != "0" ]; then
1139 echo "got update failed unexpectedly"
1140 test_done "$testroot" "$ret"
1141 return 1
1144 echo "edit $commit2" > $testroot/histedit-script
1145 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1146 2> $testroot/stderr)
1148 echo -n "got: will not edit commit history of a branch outside the " \
1149 > $testroot/stderr.expected
1150 echo '"refs/heads/" reference namespace' \
1151 >> $testroot/stderr.expected
1152 cmp -s $testroot/stderr.expected $testroot/stderr
1153 ret="$?"
1154 if [ "$ret" != "0" ]; then
1155 diff -u $testroot/stderr.expected $testroot/stderr
1157 test_done "$testroot" "$ret"
1160 test_histedit_fold_last_commit_swap() {
1161 local testroot=`test_init histedit_fold_last_commit_swap`
1163 local orig_commit=`git_show_head $testroot/repo`
1165 echo "modified alpha on master" > $testroot/repo/alpha
1166 (cd $testroot/repo && git rm -q beta)
1167 echo "new file on master" > $testroot/repo/epsilon/new
1168 (cd $testroot/repo && git add epsilon/new)
1169 git_commit $testroot/repo -m "committing changes"
1170 local old_commit1=`git_show_head $testroot/repo`
1172 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1173 git_commit $testroot/repo -m "committing to zeta on master"
1174 local old_commit2=`git_show_head $testroot/repo`
1176 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1177 ret="$?"
1178 if [ "$ret" != "0" ]; then
1179 test_done "$testroot" "$ret"
1180 return 1
1183 # fold commit2 into commit1 (requires swapping commits)
1184 echo "fold $old_commit2" > $testroot/histedit-script
1185 echo "pick $old_commit1" >> $testroot/histedit-script
1186 echo "mesg committing folded changes" >> $testroot/histedit-script
1188 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1189 > $testroot/stdout 2> $testroot/stderr)
1191 ret="$?"
1192 if [ "$ret" != "0" ]; then
1193 echo "histedit failed unexpectedly" >&2
1194 test_done "$testroot" "$ret"
1195 return 1
1198 local new_commit=`git_show_head $testroot/repo`
1200 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1201 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1202 local short_new_commit=`trim_obj_id 28 $new_commit`
1204 echo "G epsilon/zeta" >> $testroot/stdout.expected
1205 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1206 >> $testroot/stdout.expected
1207 echo "on master" >> $testroot/stdout.expected
1208 echo "G alpha" >> $testroot/stdout.expected
1209 echo "D beta" >> $testroot/stdout.expected
1210 echo "A epsilon/new" >> $testroot/stdout.expected
1211 echo -n "$short_old_commit1 -> $short_new_commit: " \
1212 >> $testroot/stdout.expected
1213 echo "committing folded changes" >> $testroot/stdout.expected
1214 echo "Switching work tree to refs/heads/master" \
1215 >> $testroot/stdout.expected
1217 cmp -s $testroot/stdout.expected $testroot/stdout
1218 ret="$?"
1219 if [ "$ret" != "0" ]; then
1220 diff -u $testroot/stdout.expected $testroot/stdout
1222 test_done "$testroot" "$ret"
1225 test_histedit_split_commit() {
1226 local testroot=`test_init histedit_split_commit`
1228 local orig_commit=`git_show_head $testroot/repo`
1230 echo "modified alpha on master" > $testroot/repo/alpha
1231 (cd $testroot/repo && git rm -q beta)
1232 echo "new file on master" > $testroot/repo/epsilon/new
1233 (cd $testroot/repo && git add epsilon/new)
1234 git_commit $testroot/repo -m "committing changes 1"
1235 local old_commit1=`git_show_head $testroot/repo`
1236 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1238 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1239 git_commit $testroot/repo -m "committing changes 2"
1240 local old_commit2=`git_show_head $testroot/repo`
1241 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1243 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1244 ret="$?"
1245 if [ "$ret" != "0" ]; then
1246 test_done "$testroot" "$ret"
1247 return 1
1250 # split commit1 into commitA and commitB and commitC
1251 echo "e $old_commit1" > $testroot/histedit-script
1252 echo "p $old_commit2" >> $testroot/histedit-script
1254 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1255 > $testroot/stdout 2> $testroot/stderr)
1256 ret="$?"
1257 if [ "$ret" != "0" ]; then
1258 echo "histedit failed unexpectedly:" >&2
1259 cat $testroot/stderr >&2
1260 test_done "$testroot" "$ret"
1261 return 1
1264 echo "G alpha" > $testroot/stdout.expected
1265 echo "D beta" >> $testroot/stdout.expected
1266 echo "A epsilon/new" >> $testroot/stdout.expected
1267 echo "Stopping histedit for amending commit $old_commit1" \
1268 >> $testroot/stdout.expected
1270 cmp -s $testroot/stdout.expected $testroot/stdout
1271 ret="$?"
1272 if [ "$ret" != "0" ]; then
1273 diff -u $testroot/stdout.expected $testroot/stdout
1274 test_done "$testroot" "$ret"
1275 return 1
1278 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1279 ret="$?"
1280 if [ "$ret" != "0" ]; then
1281 echo "commit failed unexpectedly" >&2
1282 test_done "$testroot" "$ret"
1283 return 1
1286 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1287 ret="$?"
1288 if [ "$ret" != "0" ]; then
1289 echo "commit failed unexpectedly" >&2
1290 test_done "$testroot" "$ret"
1291 return 1
1294 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1295 ret="$?"
1296 if [ "$ret" != "0" ]; then
1297 echo "commit failed unexpectedly" >&2
1298 test_done "$testroot" "$ret"
1299 return 1
1302 (cd $testroot/wt && got histedit -c \
1303 > $testroot/stdout 2> $testroot/stderr)
1304 ret="$?"
1305 if [ "$ret" != "0" ]; then
1306 echo "histedit failed unexpectedly:" >&2
1307 cat $testroot/stderr >&2
1308 test_done "$testroot" "$ret"
1309 return 1
1311 local new_commit2=`git_show_head $testroot/repo`
1312 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1314 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1315 > $testroot/stdout.expected
1316 echo "G epsilon/zeta" >> $testroot/stdout.expected
1317 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1318 >> $testroot/stdout.expected
1319 echo "Switching work tree to refs/heads/master" \
1320 >> $testroot/stdout.expected
1322 cmp -s $testroot/stdout.expected $testroot/stdout
1323 ret="$?"
1324 if [ "$ret" != "0" ]; then
1325 diff -u $testroot/stdout.expected $testroot/stdout
1327 test_done "$testroot" "$ret"
1331 test_histedit_duplicate_commit_in_script() {
1332 local testroot=`test_init histedit_duplicate_commit_in_script`
1334 local orig_commit=`git_show_head $testroot/repo`
1336 echo "modified alpha on master" > $testroot/repo/alpha
1337 (cd $testroot/repo && git rm -q beta)
1338 echo "new file on master" > $testroot/repo/epsilon/new
1339 (cd $testroot/repo && git add epsilon/new)
1340 git_commit $testroot/repo -m "committing changes 1"
1341 local old_commit1=`git_show_head $testroot/repo`
1343 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1344 git_commit $testroot/repo -m "committing changes 2"
1345 local old_commit2=`git_show_head $testroot/repo`
1347 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1348 ret="$?"
1349 if [ "$ret" != "0" ]; then
1350 test_done "$testroot" "$ret"
1351 return 1
1354 # This histedit script lists commit1 more than once
1355 echo "p $old_commit1" > $testroot/histedit-script
1356 echo "p $old_commit1" >> $testroot/histedit-script
1357 echo "p $old_commit2" >> $testroot/histedit-script
1359 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1360 > $testroot/stdout 2> $testroot/stderr)
1361 ret="$?"
1362 if [ "$ret" = "0" ]; then
1363 echo "histedit succeeded unexpectedly:" >&2
1364 cat $testroot/stdout >&2
1365 test_done "$testroot" "$ret"
1366 return 1
1369 echo -n "got: commit $old_commit1 is listed more than once " \
1370 > $testroot/stderr.expected
1371 echo "in histedit script" >> $testroot/stderr.expected
1373 cmp -s $testroot/stderr.expected $testroot/stderr
1374 ret="$?"
1375 if [ "$ret" != "0" ]; then
1376 diff -u $testroot/stderr.expected $testroot/stderr
1378 test_done "$testroot" "$ret"
1382 # if a previous commit introduces a new file, and it is folded into a commit
1383 # that deletes the same file, the file still exists after the histedit
1384 test_histedit_fold_add_delete() {
1385 local testroot=`test_init histedit_fold`
1387 local orig_commit=`git_show_head $testroot/repo`
1389 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1390 (cd $testroot/repo && git add epsilon/psi)
1391 git_commit $testroot/repo -m "committing changes"
1392 local old_commit1=`git_show_head $testroot/repo`
1394 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1395 git_commit $testroot/repo -m "editing psi"
1396 local old_commit2=`git_show_head $testroot/repo`
1398 (cd $testroot/repo && git rm -q epsilon/psi)
1399 git_commit $testroot/repo -m "removing psi"
1400 local old_commit3=`git_show_head $testroot/repo`
1402 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1403 ret="$?"
1404 if [ "$ret" != "0" ]; then
1405 test_done "$testroot" "$ret"
1406 return 1
1409 echo "fold $old_commit1" > $testroot/histedit-script
1410 echo "fold $old_commit2" >> $testroot/histedit-script
1411 echo "pick $old_commit3" >> $testroot/histedit-script
1412 echo "mesg folded changes" >> $testroot/histedit-script
1414 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1415 > $testroot/stdout)
1417 local new_commit1=`git_show_head $testroot/repo`
1419 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1420 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1421 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1422 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1424 echo "A epsilon/psi" >> $testroot/stdout.expected
1425 echo "$short_old_commit1 -> fold commit: committing changes" \
1426 >> $testroot/stdout.expected
1427 echo "G epsilon/psi" >> $testroot/stdout.expected
1428 echo "$short_old_commit2 -> fold commit: editing psi" \
1429 >> $testroot/stdout.expected
1430 echo "D epsilon/psi" >> $testroot/stdout.expected
1431 echo "$short_old_commit3 -> no-op change: folded changes" \
1432 >> $testroot/stdout.expected
1433 echo "Switching work tree to refs/heads/master" \
1434 >> $testroot/stdout.expected
1436 cmp -s $testroot/stdout.expected $testroot/stdout
1437 ret="$?"
1438 if [ "$ret" != "0" ]; then
1439 diff -u $testroot/stdout.expected $testroot/stdout
1440 test_done "$testroot" "$ret"
1441 return 1
1444 if [ -e $testroot/wt/epsilon/psi ]; then
1445 echo "removed file psi still exists on disk" >&2
1446 test_done "$testroot" "1"
1447 return 1
1450 (cd $testroot/wt && got status > $testroot/stdout)
1452 echo -n > $testroot/stdout.expected
1453 cmp -s $testroot/stdout.expected $testroot/stdout
1454 ret="$?"
1455 if [ "$ret" != "0" ]; then
1456 diff -u $testroot/stdout.expected $testroot/stdout
1457 test_done "$testroot" "$ret"
1458 return 1
1461 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1462 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1463 cmp -s $testroot/stdout.expected $testroot/stdout
1464 ret="$?"
1465 if [ "$ret" != "0" ]; then
1466 diff -u $testroot/stdout.expected $testroot/stdout
1467 test_done "$testroot" "$ret"
1468 return 1
1471 got tree -r $testroot/repo epsilon > $testroot/stdout
1472 echo "zeta" > $testroot/stdout.expected
1473 cmp -s $testroot/stdout.expected $testroot/stdout
1474 ret="$?"
1475 if [ "$ret" != "0" ]; then
1476 diff -u $testroot/stdout.expected $testroot/stdout
1478 test_done "$testroot" "$ret"
1481 test_histedit_fold_only() {
1482 local testroot=`test_init histedit_fold_only`
1484 local orig_commit=`git_show_head $testroot/repo`
1486 echo "modified alpha on master" > $testroot/repo/alpha
1487 (cd $testroot/repo && git rm -q beta)
1488 echo "new file on master" > $testroot/repo/epsilon/new
1489 (cd $testroot/repo && git add epsilon/new)
1490 git_commit $testroot/repo -m "committing changes"
1491 local old_commit1=`git_show_head $testroot/repo`
1493 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1494 git_commit $testroot/repo -m "committing to zeta on master"
1495 local old_commit2=`git_show_head $testroot/repo`
1497 echo "modified delta on master" > $testroot/repo/gamma/delta
1498 git_commit $testroot/repo -m "committing to delta on master"
1499 local old_commit3=`git_show_head $testroot/repo`
1501 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1502 ret="$?"
1503 if [ "$ret" != "0" ]; then
1504 test_done "$testroot" "$ret"
1505 return 1
1508 cat > $testroot/editor.sh <<EOF
1509 #!/bin/sh
1510 sed -i 's/.*/committing folded changes/' "\$1"
1511 EOF
1512 chmod +x $testroot/editor.sh
1514 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1515 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1517 local new_commit1=`git_show_head $testroot/repo`
1519 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1520 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1521 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1522 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1523 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1525 echo "G alpha" > $testroot/stdout.expected
1526 echo "D beta" >> $testroot/stdout.expected
1527 echo "A epsilon/new" >> $testroot/stdout.expected
1528 echo "$short_old_commit1 -> fold commit: committing changes" \
1529 >> $testroot/stdout.expected
1530 echo "G epsilon/zeta" >> $testroot/stdout.expected
1531 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1532 echo "fold commit: committing to zeta on master" \
1533 >> $testroot/stdout.expected
1534 echo "G gamma/delta" >> $testroot/stdout.expected
1535 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1536 >> $testroot/stdout.expected
1537 echo "committing folded changes" >> $testroot/stdout.expected
1538 echo "Switching work tree to refs/heads/master" \
1539 >> $testroot/stdout.expected
1541 cmp -s $testroot/stdout.expected $testroot/stdout
1542 ret="$?"
1543 if [ "$ret" != "0" ]; then
1544 diff -u $testroot/stdout.expected $testroot/stdout
1545 test_done "$testroot" "$ret"
1546 return 1
1549 echo "modified alpha on master" > $testroot/content.expected
1550 cat $testroot/wt/alpha > $testroot/content
1551 cmp -s $testroot/content.expected $testroot/content
1552 ret="$?"
1553 if [ "$ret" != "0" ]; then
1554 diff -u $testroot/content.expected $testroot/content
1555 test_done "$testroot" "$ret"
1556 return 1
1559 if [ -e $testroot/wt/beta ]; then
1560 echo "removed file beta still exists on disk" >&2
1561 test_done "$testroot" "1"
1562 return 1
1565 echo "new file on master" > $testroot/content.expected
1566 cat $testroot/wt/epsilon/new > $testroot/content
1567 cmp -s $testroot/content.expected $testroot/content
1568 ret="$?"
1569 if [ "$ret" != "0" ]; then
1570 diff -u $testroot/content.expected $testroot/content
1571 test_done "$testroot" "$ret"
1572 return 1
1575 (cd $testroot/wt && got status > $testroot/stdout)
1577 echo -n > $testroot/stdout.expected
1578 cmp -s $testroot/stdout.expected $testroot/stdout
1579 ret="$?"
1580 if [ "$ret" != "0" ]; then
1581 diff -u $testroot/stdout.expected $testroot/stdout
1582 test_done "$testroot" "$ret"
1583 return 1
1586 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1587 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1588 echo "commit $orig_commit" >> $testroot/stdout.expected
1589 cmp -s $testroot/stdout.expected $testroot/stdout
1590 ret="$?"
1591 if [ "$ret" != "0" ]; then
1592 diff -u $testroot/stdout.expected $testroot/stdout
1594 test_done "$testroot" "$ret"
1597 test_histedit_fold_only_empty_logmsg() {
1598 local testroot=`test_init histedit_fold_only_empty_logmsg`
1600 local orig_commit=`git_show_head $testroot/repo`
1602 echo "modified alpha on master" > $testroot/repo/alpha
1603 (cd $testroot/repo && git rm -q beta)
1604 echo "new file on master" > $testroot/repo/epsilon/new
1605 (cd $testroot/repo && git add epsilon/new)
1606 git_commit $testroot/repo -m "committing changes"
1607 local old_commit1=`git_show_head $testroot/repo`
1609 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1610 git_commit $testroot/repo -m "committing to zeta on master"
1611 local old_commit2=`git_show_head $testroot/repo`
1613 echo "modified delta on master" > $testroot/repo/gamma/delta
1614 git_commit $testroot/repo -m "committing to delta on master"
1615 local old_commit3=`git_show_head $testroot/repo`
1617 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1618 ret="$?"
1619 if [ "$ret" != "0" ]; then
1620 test_done "$testroot" "$ret"
1621 return 1
1624 cat > $testroot/editor.sh <<EOF
1625 #!/bin/sh
1626 sed -i 'd' "\$1"
1627 EOF
1628 chmod +x $testroot/editor.sh
1630 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1631 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1633 local new_commit1=`git_show_head $testroot/repo`
1635 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1636 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1637 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1638 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1639 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1640 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1642 echo "G alpha" > $testroot/stdout.expected
1643 echo "D beta" >> $testroot/stdout.expected
1644 echo "A epsilon/new" >> $testroot/stdout.expected
1645 echo "$short_old_commit1 -> fold commit: committing changes" \
1646 >> $testroot/stdout.expected
1647 echo "G epsilon/zeta" >> $testroot/stdout.expected
1648 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1649 echo "fold commit: committing to zeta on master" \
1650 >> $testroot/stdout.expected
1651 echo "G gamma/delta" >> $testroot/stdout.expected
1652 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1653 >> $testroot/stdout.expected
1654 echo "# log message of folded commit $very_short_old_commit1" \
1655 >> $testroot/stdout.expected
1656 echo "Switching work tree to refs/heads/master" \
1657 >> $testroot/stdout.expected
1659 cmp -s $testroot/stdout.expected $testroot/stdout
1660 ret="$?"
1661 if [ "$ret" != "0" ]; then
1662 diff -u $testroot/stdout.expected $testroot/stdout
1663 test_done "$testroot" "$ret"
1664 return 1
1667 echo "modified alpha on master" > $testroot/content.expected
1668 cat $testroot/wt/alpha > $testroot/content
1669 cmp -s $testroot/content.expected $testroot/content
1670 ret="$?"
1671 if [ "$ret" != "0" ]; then
1672 diff -u $testroot/content.expected $testroot/content
1673 test_done "$testroot" "$ret"
1674 return 1
1677 if [ -e $testroot/wt/beta ]; then
1678 echo "removed file beta still exists on disk" >&2
1679 test_done "$testroot" "1"
1680 return 1
1683 echo "new file on master" > $testroot/content.expected
1684 cat $testroot/wt/epsilon/new > $testroot/content
1685 cmp -s $testroot/content.expected $testroot/content
1686 ret="$?"
1687 if [ "$ret" != "0" ]; then
1688 diff -u $testroot/content.expected $testroot/content
1689 test_done "$testroot" "$ret"
1690 return 1
1693 (cd $testroot/wt && got status > $testroot/stdout)
1695 echo -n > $testroot/stdout.expected
1696 cmp -s $testroot/stdout.expected $testroot/stdout
1697 ret="$?"
1698 if [ "$ret" != "0" ]; then
1699 diff -u $testroot/stdout.expected $testroot/stdout
1700 test_done "$testroot" "$ret"
1701 return 1
1704 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1705 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1706 echo "commit $orig_commit" >> $testroot/stdout.expected
1707 cmp -s $testroot/stdout.expected $testroot/stdout
1708 ret="$?"
1709 if [ "$ret" != "0" ]; then
1710 diff -u $testroot/stdout.expected $testroot/stdout
1712 test_done "$testroot" "$ret"
1715 test_parseargs "$@"
1716 run_test test_histedit_no_op
1717 run_test test_histedit_swap
1718 run_test test_histedit_drop
1719 run_test test_histedit_fold
1720 run_test test_histedit_edit
1721 run_test test_histedit_fold_last_commit
1722 run_test test_histedit_missing_commit
1723 run_test test_histedit_abort
1724 run_test test_histedit_path_prefix_drop
1725 run_test test_histedit_path_prefix_edit
1726 run_test test_histedit_outside_refs_heads
1727 run_test test_histedit_fold_last_commit_swap
1728 run_test test_histedit_split_commit
1729 run_test test_histedit_duplicate_commit_in_script
1730 run_test test_histedit_fold_add_delete
1731 run_test test_histedit_fold_only
1732 run_test test_histedit_fold_only_empty_logmsg