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`
24 echo "modified alpha on master" > $testroot/repo/alpha
25 (cd $testroot/repo && git rm -q beta)
26 echo "new file on master" > $testroot/repo/epsilon/new
27 (cd $testroot/repo && git add epsilon/new)
28 git_commit $testroot/repo -m "committing changes"
29 local old_commit1=`git_show_head $testroot/repo`
31 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
32 git_commit $testroot/repo -m "committing to zeta on master"
33 local old_commit2=`git_show_head $testroot/repo`
35 got diff -r $testroot/repo $orig_commit $old_commit2 \
36 > $testroot/diff.expected
38 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
39 ret="$?"
40 if [ "$ret" != "0" ]; then
41 test_done "$testroot" "$ret"
42 return 1
43 fi
45 echo "pick $old_commit1" > $testroot/histedit-script
46 echo "pick $old_commit2" >> $testroot/histedit-script
48 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
49 > $testroot/stdout)
51 local new_commit1=`git_show_parent_commit $testroot/repo`
52 local new_commit2=`git_show_head $testroot/repo`
54 local short_old_commit1=`trim_obj_id 28 $old_commit1`
55 local short_old_commit2=`trim_obj_id 28 $old_commit2`
56 local short_new_commit1=`trim_obj_id 28 $new_commit1`
57 local short_new_commit2=`trim_obj_id 28 $new_commit2`
59 echo "G alpha" > $testroot/stdout.expected
60 echo "D beta" >> $testroot/stdout.expected
61 echo "A epsilon/new" >> $testroot/stdout.expected
62 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
63 >> $testroot/stdout.expected
64 echo "G epsilon/zeta" >> $testroot/stdout.expected
65 echo -n "$short_old_commit2 -> $short_new_commit2: " \
66 >> $testroot/stdout.expected
67 echo "committing to zeta on master" >> $testroot/stdout.expected
68 echo "Switching work tree to refs/heads/master" \
69 >> $testroot/stdout.expected
71 cmp -s $testroot/stdout.expected $testroot/stdout
72 ret="$?"
73 if [ "$ret" != "0" ]; then
74 diff -u $testroot/stdout.expected $testroot/stdout
75 test_done "$testroot" "$ret"
76 return 1
77 fi
79 echo "modified alpha on master" > $testroot/content.expected
80 cat $testroot/wt/alpha > $testroot/content
81 cmp -s $testroot/content.expected $testroot/content
82 ret="$?"
83 if [ "$ret" != "0" ]; then
84 diff -u $testroot/content.expected $testroot/content
85 test_done "$testroot" "$ret"
86 return 1
87 fi
89 if [ -e $testroot/wt/beta ]; then
90 echo "removed file beta still exists on disk" >&2
91 test_done "$testroot" "1"
92 return 1
93 fi
95 echo "new file on master" > $testroot/content.expected
96 cat $testroot/wt/epsilon/new > $testroot/content
97 cmp -s $testroot/content.expected $testroot/content
98 ret="$?"
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/content.expected $testroot/content
101 test_done "$testroot" "$ret"
102 return 1
103 fi
105 (cd $testroot/wt && got status > $testroot/stdout)
107 echo -n > $testroot/stdout.expected
108 cmp -s $testroot/stdout.expected $testroot/stdout
109 ret="$?"
110 if [ "$ret" != "0" ]; then
111 diff -u $testroot/stdout.expected $testroot/stdout
112 test_done "$testroot" "$ret"
113 return 1
114 fi
116 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
117 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
118 echo "commit $new_commit1" >> $testroot/stdout.expected
119 echo "commit $orig_commit" >> $testroot/stdout.expected
120 cmp -s $testroot/stdout.expected $testroot/stdout
121 ret="$?"
122 if [ "$ret" != "0" ]; then
123 diff -u $testroot/stdout.expected $testroot/stdout
124 test_done "$testroot" "$ret"
125 return 1
126 fi
128 got diff -r $testroot/repo $orig_commit $new_commit2 \
129 > $testroot/diff
130 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
131 cmp -s $testroot/diff.expected $testroot/diff
132 ret="$?"
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/diff.expected $testroot/diff
135 test_done "$testroot" "$ret"
136 return 1
137 fi
139 (cd $testroot/wt && got update > $testroot/stdout)
141 echo 'Already up-to-date' > $testroot/stdout.expected
142 cmp -s $testroot/stdout.expected $testroot/stdout
143 ret="$?"
144 if [ "$ret" != "0" ]; then
145 diff -u $testroot/stdout.expected $testroot/stdout
146 fi
147 test_done "$testroot" "$ret"
150 test_histedit_swap() {
151 local testroot=`test_init histedit_swap`
153 local orig_commit=`git_show_head $testroot/repo`
155 echo "modified alpha on master" > $testroot/repo/alpha
156 (cd $testroot/repo && git rm -q beta)
157 echo "new file on master" > $testroot/repo/epsilon/new
158 (cd $testroot/repo && git add epsilon/new)
159 git_commit $testroot/repo -m "committing changes"
160 local old_commit1=`git_show_head $testroot/repo`
162 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
163 git_commit $testroot/repo -m "committing to zeta on master"
164 local old_commit2=`git_show_head $testroot/repo`
166 got diff -r $testroot/repo $orig_commit $old_commit2 \
167 > $testroot/diff.expected
169 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
170 ret="$?"
171 if [ "$ret" != "0" ]; then
172 test_done "$testroot" "$ret"
173 return 1
174 fi
176 echo "pick $old_commit2" > $testroot/histedit-script
177 echo "pick $old_commit1" >> $testroot/histedit-script
179 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
180 > $testroot/stdout)
182 local new_commit2=`git_show_parent_commit $testroot/repo`
183 local new_commit1=`git_show_head $testroot/repo`
185 local short_old_commit1=`trim_obj_id 28 $old_commit1`
186 local short_old_commit2=`trim_obj_id 28 $old_commit2`
187 local short_new_commit1=`trim_obj_id 28 $new_commit1`
188 local short_new_commit2=`trim_obj_id 28 $new_commit2`
190 echo "G epsilon/zeta" > $testroot/stdout.expected
191 echo -n "$short_old_commit2 -> $short_new_commit2: " \
192 >> $testroot/stdout.expected
193 echo "committing to zeta on master" >> $testroot/stdout.expected
194 echo "G alpha" >> $testroot/stdout.expected
195 echo "D beta" >> $testroot/stdout.expected
196 echo "A epsilon/new" >> $testroot/stdout.expected
197 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
198 >> $testroot/stdout.expected
199 echo "Switching work tree to refs/heads/master" \
200 >> $testroot/stdout.expected
202 cmp -s $testroot/stdout.expected $testroot/stdout
203 ret="$?"
204 if [ "$ret" != "0" ]; then
205 diff -u $testroot/stdout.expected $testroot/stdout
206 test_done "$testroot" "$ret"
207 return 1
208 fi
210 echo "modified alpha on master" > $testroot/content.expected
211 cat $testroot/wt/alpha > $testroot/content
212 cmp -s $testroot/content.expected $testroot/content
213 ret="$?"
214 if [ "$ret" != "0" ]; then
215 diff -u $testroot/content.expected $testroot/content
216 test_done "$testroot" "$ret"
217 return 1
218 fi
220 if [ -e $testroot/wt/beta ]; then
221 echo "removed file beta still exists on disk" >&2
222 test_done "$testroot" "1"
223 return 1
224 fi
226 echo "new file on master" > $testroot/content.expected
227 cat $testroot/wt/epsilon/new > $testroot/content
228 cmp -s $testroot/content.expected $testroot/content
229 ret="$?"
230 if [ "$ret" != "0" ]; then
231 diff -u $testroot/content.expected $testroot/content
232 test_done "$testroot" "$ret"
233 return 1
234 fi
236 (cd $testroot/wt && got status > $testroot/stdout)
238 echo -n > $testroot/stdout.expected
239 cmp -s $testroot/stdout.expected $testroot/stdout
240 ret="$?"
241 if [ "$ret" != "0" ]; then
242 diff -u $testroot/stdout.expected $testroot/stdout
243 test_done "$testroot" "$ret"
244 return 1
245 fi
247 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
248 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
249 echo "commit $new_commit2" >> $testroot/stdout.expected
250 echo "commit $orig_commit" >> $testroot/stdout.expected
251 cmp -s $testroot/stdout.expected $testroot/stdout
252 ret="$?"
253 if [ "$ret" != "0" ]; then
254 diff -u $testroot/stdout.expected $testroot/stdout
255 test_done "$testroot" "$ret"
256 return 1
257 fi
259 got diff -r $testroot/repo $orig_commit $new_commit1 \
260 > $testroot/diff
261 sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
262 cmp -s $testroot/diff.expected $testroot/diff
263 ret="$?"
264 if [ "$ret" != "0" ]; then
265 diff -u $testroot/diff.expected $testroot/diff
266 fi
267 test_done "$testroot" "$ret"
270 test_histedit_drop() {
271 local testroot=`test_init histedit_drop`
272 local orig_commit=`git_show_head $testroot/repo`
274 echo "modified alpha on master" > $testroot/repo/alpha
275 (cd $testroot/repo && git rm -q beta)
276 echo "new file on master" > $testroot/repo/epsilon/new
277 (cd $testroot/repo && git add epsilon/new)
278 git_commit $testroot/repo -m "committing changes"
279 local old_commit1=`git_show_head $testroot/repo`
281 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
282 git_commit $testroot/repo -m "committing to zeta on master"
283 local old_commit2=`git_show_head $testroot/repo`
285 got diff -r $testroot/repo $old_commit1 $old_commit2 \
286 > $testroot/diff.expected
288 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
289 ret="$?"
290 if [ "$ret" != "0" ]; then
291 test_done "$testroot" "$ret"
292 return 1
293 fi
295 echo "drop $old_commit1" > $testroot/histedit-script
296 echo "pick $old_commit2" >> $testroot/histedit-script
298 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
299 > $testroot/stdout)
301 local new_commit2=`git_show_head $testroot/repo`
303 local short_old_commit1=`trim_obj_id 28 $old_commit1`
304 local short_old_commit2=`trim_obj_id 28 $old_commit2`
305 local short_new_commit2=`trim_obj_id 28 $new_commit2`
307 echo "$short_old_commit1 -> drop commit: committing changes" \
308 > $testroot/stdout.expected
309 echo "G epsilon/zeta" >> $testroot/stdout.expected
310 echo -n "$short_old_commit2 -> $short_new_commit2: " \
311 >> $testroot/stdout.expected
312 echo "committing to zeta on master" >> $testroot/stdout.expected
313 echo "Switching work tree to refs/heads/master" \
314 >> $testroot/stdout.expected
316 cmp -s $testroot/stdout.expected $testroot/stdout
317 ret="$?"
318 if [ "$ret" != "0" ]; then
319 diff -u $testroot/stdout.expected $testroot/stdout
320 test_done "$testroot" "$ret"
321 return 1
322 fi
324 for f in alpha beta; do
325 echo "$f" > $testroot/content.expected
326 cat $testroot/wt/$f > $testroot/content
327 cmp -s $testroot/content.expected $testroot/content
328 ret="$?"
329 if [ "$ret" != "0" ]; then
330 diff -u $testroot/content.expected $testroot/content
331 test_done "$testroot" "$ret"
332 return 1
333 fi
334 done
336 if [ -e $testroot/wt/new ]; then
337 echo "file new exists on disk but should not" >&2
338 test_done "$testroot" "1"
339 return 1
340 fi
342 (cd $testroot/wt && got status > $testroot/stdout)
344 echo -n > $testroot/stdout.expected
345 cmp -s $testroot/stdout.expected $testroot/stdout
346 ret="$?"
347 if [ "$ret" != "0" ]; then
348 diff -u $testroot/stdout.expected $testroot/stdout
349 test_done "$testroot" "$ret"
350 return 1
351 fi
353 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
354 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
355 echo "commit $orig_commit" >> $testroot/stdout.expected
356 cmp -s $testroot/stdout.expected $testroot/stdout
357 ret="$?"
358 if [ "$ret" != "0" ]; then
359 diff -u $testroot/stdout.expected $testroot/stdout
360 test_done "$testroot" "$ret"
361 return 1
362 fi
364 got diff -r $testroot/repo $orig_commit $new_commit2 \
365 > $testroot/diff
366 sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
367 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
368 cmp -s $testroot/diff.expected $testroot/diff
369 ret="$?"
370 if [ "$ret" != "0" ]; then
371 diff -u $testroot/diff.expected $testroot/diff
372 fi
373 test_done "$testroot" "$ret"
376 test_histedit_fold() {
377 local testroot=`test_init histedit_fold`
379 local orig_commit=`git_show_head $testroot/repo`
381 echo "modified alpha on master" > $testroot/repo/alpha
382 (cd $testroot/repo && git rm -q beta)
383 echo "new file on master" > $testroot/repo/epsilon/new
384 (cd $testroot/repo && git add epsilon/new)
385 git_commit $testroot/repo -m "committing changes"
386 local old_commit1=`git_show_head $testroot/repo`
388 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
389 git_commit $testroot/repo -m "committing to zeta on master"
390 local old_commit2=`git_show_head $testroot/repo`
392 echo "modified delta on master" > $testroot/repo/gamma/delta
393 git_commit $testroot/repo -m "committing to delta on master"
394 local old_commit3=`git_show_head $testroot/repo`
396 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
397 ret="$?"
398 if [ "$ret" != "0" ]; then
399 test_done "$testroot" "$ret"
400 return 1
401 fi
403 echo "fold $old_commit1" > $testroot/histedit-script
404 echo "drop $old_commit2" >> $testroot/histedit-script
405 echo "pick $old_commit3" >> $testroot/histedit-script
406 echo "mesg committing folded changes" >> $testroot/histedit-script
408 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
409 > $testroot/stdout)
411 local new_commit1=`git_show_parent_commit $testroot/repo`
412 local new_commit2=`git_show_head $testroot/repo`
414 local short_old_commit1=`trim_obj_id 28 $old_commit1`
415 local short_old_commit2=`trim_obj_id 28 $old_commit2`
416 local short_old_commit3=`trim_obj_id 28 $old_commit3`
417 local short_new_commit1=`trim_obj_id 28 $new_commit1`
418 local short_new_commit2=`trim_obj_id 28 $new_commit2`
420 echo "G alpha" > $testroot/stdout.expected
421 echo "D beta" >> $testroot/stdout.expected
422 echo "A epsilon/new" >> $testroot/stdout.expected
423 echo "$short_old_commit1 -> fold commit: committing changes" \
424 >> $testroot/stdout.expected
425 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
426 echo "drop commit: committing to zeta on master" \
427 >> $testroot/stdout.expected
428 echo "G gamma/delta" >> $testroot/stdout.expected
429 echo -n "$short_old_commit3 -> $short_new_commit2: " \
430 >> $testroot/stdout.expected
431 echo "committing folded changes" >> $testroot/stdout.expected
432 echo "Switching work tree to refs/heads/master" \
433 >> $testroot/stdout.expected
435 cmp -s $testroot/stdout.expected $testroot/stdout
436 ret="$?"
437 if [ "$ret" != "0" ]; then
438 diff -u $testroot/stdout.expected $testroot/stdout
439 test_done "$testroot" "$ret"
440 return 1
441 fi
443 echo "modified alpha on master" > $testroot/content.expected
444 cat $testroot/wt/alpha > $testroot/content
445 cmp -s $testroot/content.expected $testroot/content
446 ret="$?"
447 if [ "$ret" != "0" ]; then
448 diff -u $testroot/content.expected $testroot/content
449 test_done "$testroot" "$ret"
450 return 1
451 fi
453 if [ -e $testroot/wt/beta ]; then
454 echo "removed file beta still exists on disk" >&2
455 test_done "$testroot" "1"
456 return 1
457 fi
459 echo "new file on master" > $testroot/content.expected
460 cat $testroot/wt/epsilon/new > $testroot/content
461 cmp -s $testroot/content.expected $testroot/content
462 ret="$?"
463 if [ "$ret" != "0" ]; then
464 diff -u $testroot/content.expected $testroot/content
465 test_done "$testroot" "$ret"
466 return 1
467 fi
469 (cd $testroot/wt && got status > $testroot/stdout)
471 echo -n > $testroot/stdout.expected
472 cmp -s $testroot/stdout.expected $testroot/stdout
473 ret="$?"
474 if [ "$ret" != "0" ]; then
475 diff -u $testroot/stdout.expected $testroot/stdout
476 test_done "$testroot" "$ret"
477 return 1
478 fi
480 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
481 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
482 echo "commit $orig_commit" >> $testroot/stdout.expected
483 cmp -s $testroot/stdout.expected $testroot/stdout
484 ret="$?"
485 if [ "$ret" != "0" ]; then
486 diff -u $testroot/stdout.expected $testroot/stdout
487 fi
488 test_done "$testroot" "$ret"
491 test_histedit_edit() {
492 local testroot=`test_init histedit_edit`
494 local orig_commit=`git_show_head $testroot/repo`
496 echo "modified alpha on master" > $testroot/repo/alpha
497 (cd $testroot/repo && git rm -q beta)
498 echo "new file on master" > $testroot/repo/epsilon/new
499 (cd $testroot/repo && git add epsilon/new)
500 git_commit $testroot/repo -m "committing changes"
501 local old_commit1=`git_show_head $testroot/repo`
503 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
504 git_commit $testroot/repo -m "committing to zeta on master"
505 local old_commit2=`git_show_head $testroot/repo`
507 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
508 ret="$?"
509 if [ "$ret" != "0" ]; then
510 test_done "$testroot" "$ret"
511 return 1
512 fi
514 echo "edit $old_commit1" > $testroot/histedit-script
515 echo "mesg committing changes" >> $testroot/histedit-script
516 echo "pick $old_commit2" >> $testroot/histedit-script
518 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
519 > $testroot/stdout)
521 local short_old_commit1=`trim_obj_id 28 $old_commit1`
522 local short_old_commit2=`trim_obj_id 28 $old_commit2`
524 echo "G alpha" > $testroot/stdout.expected
525 echo "D beta" >> $testroot/stdout.expected
526 echo "A epsilon/new" >> $testroot/stdout.expected
527 echo "Stopping histedit for amending commit $old_commit1" \
528 >> $testroot/stdout.expected
529 cmp -s $testroot/stdout.expected $testroot/stdout
530 ret="$?"
531 if [ "$ret" != "0" ]; then
532 diff -u $testroot/stdout.expected $testroot/stdout
533 test_done "$testroot" "$ret"
534 return 1
535 fi
537 echo "edited modified alpha on master" > $testroot/wt/alpha
539 # test interaction of 'got stage' and histedit -c
540 (cd $testroot/wt && got stage alpha > /dev/null)
541 (cd $testroot/wt && got histedit -c > $testroot/stdout \
542 2> $testroot/stderr)
543 ret="$?"
544 if [ "$ret" = "0" ]; then
545 echo "histedit succeeded unexpectedly" >&2
546 test_done "$testroot" "1"
547 return 1
548 fi
549 echo -n "got: work tree contains files with staged changes; " \
550 > $testroot/stderr.expected
551 echo "these changes must be committed or unstaged first" \
552 >> $testroot/stderr.expected
553 cmp -s $testroot/stderr.expected $testroot/stderr
554 ret="$?"
555 if [ "$ret" != "0" ]; then
556 diff -u $testroot/stderr.expected $testroot/stderr
557 test_done "$testroot" "$ret"
558 return 1
559 fi
561 (cd $testroot/wt && got unstage alpha > /dev/null)
562 (cd $testroot/wt && got histedit -c > $testroot/stdout)
564 local new_commit1=`git_show_parent_commit $testroot/repo`
565 local new_commit2=`git_show_head $testroot/repo`
567 local short_new_commit1=`trim_obj_id 28 $new_commit1`
568 local short_new_commit2=`trim_obj_id 28 $new_commit2`
570 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
571 > $testroot/stdout.expected
572 echo "G epsilon/zeta" >> $testroot/stdout.expected
573 echo -n "$short_old_commit2 -> $short_new_commit2: " \
574 >> $testroot/stdout.expected
575 echo "committing to zeta on master" >> $testroot/stdout.expected
576 echo "Switching work tree to refs/heads/master" \
577 >> $testroot/stdout.expected
579 cmp -s $testroot/stdout.expected $testroot/stdout
580 ret="$?"
581 if [ "$ret" != "0" ]; then
582 diff -u $testroot/stdout.expected $testroot/stdout
583 test_done "$testroot" "$ret"
584 return 1
585 fi
587 echo "edited modified alpha on master" > $testroot/content.expected
588 cat $testroot/wt/alpha > $testroot/content
589 cmp -s $testroot/content.expected $testroot/content
590 ret="$?"
591 if [ "$ret" != "0" ]; then
592 diff -u $testroot/content.expected $testroot/content
593 test_done "$testroot" "$ret"
594 return 1
595 fi
597 if [ -e $testroot/wt/beta ]; then
598 echo "removed file beta still exists on disk" >&2
599 test_done "$testroot" "1"
600 return 1
601 fi
603 echo "new file on master" > $testroot/content.expected
604 cat $testroot/wt/epsilon/new > $testroot/content
605 cmp -s $testroot/content.expected $testroot/content
606 ret="$?"
607 if [ "$ret" != "0" ]; then
608 diff -u $testroot/content.expected $testroot/content
609 test_done "$testroot" "$ret"
610 return 1
611 fi
613 (cd $testroot/wt && got status > $testroot/stdout)
615 echo -n > $testroot/stdout.expected
616 cmp -s $testroot/stdout.expected $testroot/stdout
617 ret="$?"
618 if [ "$ret" != "0" ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
625 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
626 echo "commit $new_commit1" >> $testroot/stdout.expected
627 echo "commit $orig_commit" >> $testroot/stdout.expected
628 cmp -s $testroot/stdout.expected $testroot/stdout
629 ret="$?"
630 if [ "$ret" != "0" ]; then
631 diff -u $testroot/stdout.expected $testroot/stdout
632 fi
633 test_done "$testroot" "$ret"
636 test_histedit_fold_last_commit() {
637 local testroot=`test_init histedit_fold_last_commit`
639 local orig_commit=`git_show_head $testroot/repo`
641 echo "modified alpha on master" > $testroot/repo/alpha
642 (cd $testroot/repo && git rm -q beta)
643 echo "new file on master" > $testroot/repo/epsilon/new
644 (cd $testroot/repo && git add epsilon/new)
645 git_commit $testroot/repo -m "committing changes"
646 local old_commit1=`git_show_head $testroot/repo`
648 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
649 git_commit $testroot/repo -m "committing to zeta on master"
650 local old_commit2=`git_show_head $testroot/repo`
652 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
653 ret="$?"
654 if [ "$ret" != "0" ]; then
655 test_done "$testroot" "$ret"
656 return 1
657 fi
659 echo "pick $old_commit1" > $testroot/histedit-script
660 echo "fold $old_commit2" >> $testroot/histedit-script
661 echo "mesg committing folded changes" >> $testroot/histedit-script
663 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
664 > $testroot/stdout 2> $testroot/stderr)
666 ret="$?"
667 if [ "$ret" = "0" ]; then
668 echo "histedit succeeded unexpectedly" >&2
669 test_done "$testroot" "1"
670 return 1
671 fi
673 echo "got: last commit in histedit script cannot be folded" \
674 > $testroot/stderr.expected
676 cmp -s $testroot/stderr.expected $testroot/stderr
677 ret="$?"
678 if [ "$ret" != "0" ]; then
679 diff -u $testroot/stderr.expected $testroot/stderr
680 fi
681 test_done "$testroot" "$ret"
684 test_histedit_missing_commit() {
685 local testroot=`test_init histedit_missing_commit`
687 local orig_commit=`git_show_head $testroot/repo`
689 echo "modified alpha on master" > $testroot/repo/alpha
690 (cd $testroot/repo && git rm -q beta)
691 echo "new file on master" > $testroot/repo/epsilon/new
692 (cd $testroot/repo && git add epsilon/new)
693 git_commit $testroot/repo -m "committing changes"
694 local old_commit1=`git_show_head $testroot/repo`
696 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
697 git_commit $testroot/repo -m "committing to zeta on master"
698 local old_commit2=`git_show_head $testroot/repo`
700 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
701 ret="$?"
702 if [ "$ret" != "0" ]; then
703 test_done "$testroot" "$ret"
704 return 1
705 fi
707 echo "pick $old_commit1" > $testroot/histedit-script
708 echo "mesg committing changes" >> $testroot/histedit-script
710 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
711 > $testroot/stdout 2> $testroot/stderr)
713 ret="$?"
714 if [ "$ret" = "0" ]; then
715 echo "histedit succeeded unexpectedly" >&2
716 test_done "$testroot" "1"
717 return 1
718 fi
720 echo "got: commit $old_commit2 missing from histedit script" \
721 > $testroot/stderr.expected
723 cmp -s $testroot/stderr.expected $testroot/stderr
724 ret="$?"
725 if [ "$ret" != "0" ]; then
726 diff -u $testroot/stderr.expected $testroot/stderr
727 fi
728 test_done "$testroot" "$ret"
731 test_histedit_abort() {
732 local testroot=`test_init histedit_abort`
734 local orig_commit=`git_show_head $testroot/repo`
736 echo "modified alpha on master" > $testroot/repo/alpha
737 (cd $testroot/repo && git rm -q beta)
738 echo "new file on master" > $testroot/repo/epsilon/new
739 (cd $testroot/repo && git add epsilon/new)
740 git_commit $testroot/repo -m "committing changes"
741 local old_commit1=`git_show_head $testroot/repo`
743 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
744 git_commit $testroot/repo -m "committing to zeta on master"
745 local old_commit2=`git_show_head $testroot/repo`
747 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
748 ret="$?"
749 if [ "$ret" != "0" ]; then
750 test_done "$testroot" "$ret"
751 return 1
752 fi
754 echo "edit $old_commit1" > $testroot/histedit-script
755 echo "mesg committing changes" >> $testroot/histedit-script
756 echo "pick $old_commit2" >> $testroot/histedit-script
758 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
759 > $testroot/stdout)
761 local short_old_commit1=`trim_obj_id 28 $old_commit1`
762 local short_old_commit2=`trim_obj_id 28 $old_commit2`
764 echo "G alpha" > $testroot/stdout.expected
765 echo "D beta" >> $testroot/stdout.expected
766 echo "A epsilon/new" >> $testroot/stdout.expected
767 echo "Stopping histedit for amending commit $old_commit1" \
768 >> $testroot/stdout.expected
769 cmp -s $testroot/stdout.expected $testroot/stdout
770 ret="$?"
771 if [ "$ret" != "0" ]; then
772 diff -u $testroot/stdout.expected $testroot/stdout
773 test_done "$testroot" "$ret"
774 return 1
775 fi
777 echo "edited modified alpha on master" > $testroot/wt/alpha
779 (cd $testroot/wt && got histedit -a > $testroot/stdout)
781 local new_commit1=`git_show_parent_commit $testroot/repo`
782 local new_commit2=`git_show_head $testroot/repo`
784 echo "Switching work tree to refs/heads/master" \
785 > $testroot/stdout.expected
786 echo "R alpha" >> $testroot/stdout.expected
787 echo "R beta" >> $testroot/stdout.expected
788 echo "R epsilon/new" >> $testroot/stdout.expected
789 echo "Histedit of refs/heads/master aborted" \
790 >> $testroot/stdout.expected
792 cmp -s $testroot/stdout.expected $testroot/stdout
793 ret="$?"
794 if [ "$ret" != "0" ]; then
795 diff -u $testroot/stdout.expected $testroot/stdout
796 test_done "$testroot" "$ret"
797 return 1
798 fi
800 for f in alpha beta; do
801 echo "$f" > $testroot/content.expected
802 cat $testroot/wt/$f > $testroot/content
803 cmp -s $testroot/content.expected $testroot/content
804 ret="$?"
805 if [ "$ret" != "0" ]; then
806 diff -u $testroot/content.expected $testroot/content
807 test_done "$testroot" "$ret"
808 return 1
809 fi
810 done
812 echo "new file on master" > $testroot/content.expected
813 cat $testroot/wt/epsilon/new > $testroot/content
814 cmp -s $testroot/content.expected $testroot/content
815 ret="$?"
816 if [ "$ret" != "0" ]; then
817 diff -u $testroot/content.expected $testroot/content
818 test_done "$testroot" "$ret"
819 return 1
820 fi
822 (cd $testroot/wt && got status > $testroot/stdout)
824 echo "? epsilon/new" > $testroot/stdout.expected
825 cmp -s $testroot/stdout.expected $testroot/stdout
826 ret="$?"
827 if [ "$ret" != "0" ]; then
828 diff -u $testroot/stdout.expected $testroot/stdout
829 test_done "$testroot" "$ret"
830 return 1
831 fi
833 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
834 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
835 echo "commit $new_commit1" >> $testroot/stdout.expected
836 echo "commit $orig_commit" >> $testroot/stdout.expected
837 cmp -s $testroot/stdout.expected $testroot/stdout
838 ret="$?"
839 if [ "$ret" != "0" ]; then
840 diff -u $testroot/stdout.expected $testroot/stdout
841 fi
842 test_done "$testroot" "$ret"
845 test_histedit_path_prefix_drop() {
846 local testroot=`test_init histedit_path_prefix_drop`
847 local orig_commit=`git_show_head $testroot/repo`
849 echo "modified zeta" > $testroot/repo/epsilon/zeta
850 git_commit $testroot/repo -m "changing zeta"
851 local old_commit1=`git_show_head $testroot/repo`
853 got checkout -c $orig_commit -p gamma $testroot/repo \
854 $testroot/wt > /dev/null
855 ret="$?"
856 if [ "$ret" != "0" ]; then
857 test_done "$testroot" "$ret"
858 return 1
859 fi
861 echo "drop $old_commit1" > $testroot/histedit-script
863 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
864 > $testroot/stdout 2> $testroot/stderr)
866 ret="$?"
867 if [ "$ret" = "0" ]; then
868 echo "histedit succeeded unexpectedly" >&2
869 test_done "$testroot" "1"
870 return 1
871 fi
873 echo -n "got: cannot edit branch history which contains changes " \
874 > $testroot/stderr.expected
875 echo "outside of this work tree's path prefix" \
876 >> $testroot/stderr.expected
878 cmp -s $testroot/stderr.expected $testroot/stderr
879 ret="$?"
880 if [ "$ret" != "0" ]; then
881 diff -u $testroot/stderr.expected $testroot/stderr
882 test_done "$testroot" "$ret"
883 return 1
884 fi
886 rm -rf $testroot/wt
887 got checkout -c $orig_commit -p epsilon $testroot/repo \
888 $testroot/wt > /dev/null
889 ret="$?"
890 if [ "$ret" != "0" ]; then
891 test_done "$testroot" "$ret"
892 return 1
893 fi
894 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
895 > $testroot/stdout)
897 local short_old_commit1=`trim_obj_id 28 $old_commit1`
898 local short_old_commit2=`trim_obj_id 28 $old_commit2`
900 echo "$short_old_commit1 -> drop commit: changing zeta" \
901 > $testroot/stdout.expected
902 echo "Switching work tree to refs/heads/master" \
903 >> $testroot/stdout.expected
905 cmp -s $testroot/stdout.expected $testroot/stdout
906 ret="$?"
907 if [ "$ret" != "0" ]; then
908 diff -u $testroot/stdout.expected $testroot/stdout
909 test_done "$testroot" "$ret"
910 return 1
911 fi
913 echo "zeta" > $testroot/content.expected
914 cat $testroot/wt/zeta > $testroot/content
915 cmp -s $testroot/content.expected $testroot/content
916 ret="$?"
917 if [ "$ret" != "0" ]; then
918 diff -u $testroot/content.expected $testroot/content
919 test_done "$testroot" "$ret"
920 return 1
921 fi
924 (cd $testroot/wt && got status > $testroot/stdout)
926 echo -n > $testroot/stdout.expected
927 cmp -s $testroot/stdout.expected $testroot/stdout
928 ret="$?"
929 if [ "$ret" != "0" ]; then
930 diff -u $testroot/stdout.expected $testroot/stdout
931 test_done "$testroot" "$ret"
932 return 1
933 fi
935 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
936 echo "commit $orig_commit (master)" > $testroot/stdout.expected
937 cmp -s $testroot/stdout.expected $testroot/stdout
938 ret="$?"
939 if [ "$ret" != "0" ]; then
940 diff -u $testroot/stdout.expected $testroot/stdout
941 fi
942 test_done "$testroot" "$ret"
945 test_histedit_path_prefix_edit() {
946 local testroot=`test_init histedit_path_prefix_edit`
947 local orig_commit=`git_show_head $testroot/repo`
949 echo "modified zeta" > $testroot/repo/epsilon/zeta
950 git_commit $testroot/repo -m "changing zeta"
951 local old_commit1=`git_show_head $testroot/repo`
953 got diff -r $testroot/repo $orig_commit $old_commit1 \
954 > $testroot/diff.expected
956 got checkout -c $orig_commit -p gamma $testroot/repo \
957 $testroot/wt > /dev/null
958 ret="$?"
959 if [ "$ret" != "0" ]; then
960 test_done "$testroot" "$ret"
961 return 1
962 fi
964 echo "edit $old_commit1" > $testroot/histedit-script
965 echo "mesg modified zeta" >> $testroot/histedit-script
967 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
968 > $testroot/stdout 2> $testroot/stderr)
970 ret="$?"
971 if [ "$ret" = "0" ]; then
972 echo "histedit succeeded unexpectedly" >&2
973 test_done "$testroot" "1"
974 return 1
975 fi
977 echo -n "got: cannot edit branch history which contains changes " \
978 > $testroot/stderr.expected
979 echo "outside of this work tree's path prefix" \
980 >> $testroot/stderr.expected
982 cmp -s $testroot/stderr.expected $testroot/stderr
983 ret="$?"
984 if [ "$ret" != "0" ]; then
985 diff -u $testroot/stderr.expected $testroot/stderr
986 test_done "$testroot" "$ret"
987 return 1
988 fi
990 rm -rf $testroot/wt
991 got checkout -c $orig_commit -p epsilon $testroot/repo \
992 $testroot/wt > /dev/null
993 ret="$?"
994 if [ "$ret" != "0" ]; then
995 test_done "$testroot" "$ret"
996 return 1
997 fi
998 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
999 > $testroot/stdout)
1001 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1003 echo "G zeta" > $testroot/stdout.expected
1004 echo "Stopping histedit for amending commit $old_commit1" \
1005 >> $testroot/stdout.expected
1006 cmp -s $testroot/stdout.expected $testroot/stdout
1007 ret="$?"
1008 if [ "$ret" != "0" ]; then
1009 diff -u $testroot/stdout.expected $testroot/stdout
1010 test_done "$testroot" "$ret"
1011 return 1
1014 echo "modified zeta" > $testroot/content.expected
1015 cat $testroot/wt/zeta > $testroot/content
1016 cmp -s $testroot/content.expected $testroot/content
1017 ret="$?"
1018 if [ "$ret" != "0" ]; then
1019 diff -u $testroot/content.expected $testroot/content
1020 test_done "$testroot" "$ret"
1021 return 1
1024 (cd $testroot/wt && got status > $testroot/stdout)
1026 echo "M zeta"> $testroot/stdout.expected
1027 cmp -s $testroot/stdout.expected $testroot/stdout
1028 ret="$?"
1029 if [ "$ret" != "0" ]; then
1030 diff -u $testroot/stdout.expected $testroot/stdout
1031 test_done "$testroot" "$ret"
1032 return 1
1035 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1037 local new_commit1=`git_show_head $testroot/repo`
1038 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1040 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1041 > $testroot/stdout.expected
1042 echo "modified zeta" >> $testroot/stdout.expected
1043 echo "Switching work tree to refs/heads/master" \
1044 >> $testroot/stdout.expected
1046 cmp -s $testroot/stdout.expected $testroot/stdout
1047 ret="$?"
1048 if [ "$ret" != "0" ]; then
1049 diff -u $testroot/stdout.expected $testroot/stdout
1050 test_done "$testroot" "$ret"
1051 return 1
1054 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1055 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1056 echo "commit $orig_commit" >> $testroot/stdout.expected
1057 cmp -s $testroot/stdout.expected $testroot/stdout
1058 ret="$?"
1059 if [ "$ret" != "0" ]; then
1060 diff -u $testroot/stdout.expected $testroot/stdout
1061 test_done "$testroot" "$ret"
1062 return 1
1065 got diff -r $testroot/repo $orig_commit $new_commit1 \
1066 > $testroot/diff
1067 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1068 cmp -s $testroot/diff.expected $testroot/diff
1069 ret="$?"
1070 if [ "$ret" != "0" ]; then
1071 diff -u $testroot/diff.expected $testroot/diff
1073 test_done "$testroot" "$ret"
1076 test_histedit_outside_refs_heads() {
1077 local testroot=`test_init histedit_outside_refs_heads`
1078 local commit1=`git_show_head $testroot/repo`
1080 got checkout $testroot/repo $testroot/wt > /dev/null
1081 ret="$?"
1082 if [ "$ret" != "0" ]; then
1083 echo "got checkout failed unexpectedly"
1084 test_done "$testroot" "$ret"
1085 return 1
1088 echo "modified alpha" > $testroot/wt/alpha
1090 (cd $testroot/wt && got commit -m 'change alpha' \
1091 > $testroot/stdout 2> $testroot/stderr)
1092 ret="$?"
1093 if [ "$ret" != "0" ]; then
1094 echo "got commit failed unexpectedly" >&2
1095 test_done "$testroot" "1"
1096 return 1
1098 local commit2=`git_show_head $testroot/repo`
1100 got ref -r $testroot/repo -c master refs/remotes/origin/master
1101 ret="$?"
1102 if [ "$ret" != "0" ]; then
1103 echo "got ref failed unexpectedly" >&2
1104 test_done "$testroot" "1"
1105 return 1
1108 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1109 ret="$?"
1110 if [ "$ret" != "0" ]; then
1111 echo "got update failed unexpectedly"
1112 test_done "$testroot" "$ret"
1113 return 1
1116 echo "edit $commit2" > $testroot/histedit-script
1117 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1118 2> $testroot/stderr)
1120 echo -n "got: will not edit commit history of a branch outside the " \
1121 > $testroot/stderr.expected
1122 echo '"refs/heads/" reference namespace' \
1123 >> $testroot/stderr.expected
1124 cmp -s $testroot/stderr.expected $testroot/stderr
1125 ret="$?"
1126 if [ "$ret" != "0" ]; then
1127 diff -u $testroot/stderr.expected $testroot/stderr
1129 test_done "$testroot" "$ret"
1132 test_histedit_fold_last_commit_swap() {
1133 local testroot=`test_init histedit_fold_last_commit_swap`
1135 local orig_commit=`git_show_head $testroot/repo`
1137 echo "modified alpha on master" > $testroot/repo/alpha
1138 (cd $testroot/repo && git rm -q beta)
1139 echo "new file on master" > $testroot/repo/epsilon/new
1140 (cd $testroot/repo && git add epsilon/new)
1141 git_commit $testroot/repo -m "committing changes"
1142 local old_commit1=`git_show_head $testroot/repo`
1144 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1145 git_commit $testroot/repo -m "committing to zeta on master"
1146 local old_commit2=`git_show_head $testroot/repo`
1148 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1149 ret="$?"
1150 if [ "$ret" != "0" ]; then
1151 test_done "$testroot" "$ret"
1152 return 1
1155 # fold commit2 into commit1 (requires swapping commits)
1156 echo "fold $old_commit2" > $testroot/histedit-script
1157 echo "pick $old_commit1" >> $testroot/histedit-script
1158 echo "mesg committing folded changes" >> $testroot/histedit-script
1160 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1161 > $testroot/stdout 2> $testroot/stderr)
1163 ret="$?"
1164 if [ "$ret" != "0" ]; then
1165 echo "histedit failed unexpectedly" >&2
1166 test_done "$testroot" "$ret"
1167 return 1
1170 local new_commit=`git_show_head $testroot/repo`
1172 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1173 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1174 local short_new_commit=`trim_obj_id 28 $new_commit`
1176 echo "G epsilon/zeta" >> $testroot/stdout.expected
1177 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1178 >> $testroot/stdout.expected
1179 echo "on master" >> $testroot/stdout.expected
1180 echo "G alpha" >> $testroot/stdout.expected
1181 echo "D beta" >> $testroot/stdout.expected
1182 echo "A epsilon/new" >> $testroot/stdout.expected
1183 echo -n "$short_old_commit1 -> $short_new_commit: " \
1184 >> $testroot/stdout.expected
1185 echo "committing folded changes" >> $testroot/stdout.expected
1186 echo "Switching work tree to refs/heads/master" \
1187 >> $testroot/stdout.expected
1189 cmp -s $testroot/stdout.expected $testroot/stdout
1190 ret="$?"
1191 if [ "$ret" != "0" ]; then
1192 diff -u $testroot/stdout.expected $testroot/stdout
1194 test_done "$testroot" "$ret"
1197 test_histedit_split_commit() {
1198 local testroot=`test_init histedit_split_commit`
1200 local orig_commit=`git_show_head $testroot/repo`
1202 echo "modified alpha on master" > $testroot/repo/alpha
1203 (cd $testroot/repo && git rm -q beta)
1204 echo "new file on master" > $testroot/repo/epsilon/new
1205 (cd $testroot/repo && git add epsilon/new)
1206 git_commit $testroot/repo -m "committing changes 1"
1207 local old_commit1=`git_show_head $testroot/repo`
1208 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1210 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1211 git_commit $testroot/repo -m "committing changes 2"
1212 local old_commit2=`git_show_head $testroot/repo`
1213 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1215 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1216 ret="$?"
1217 if [ "$ret" != "0" ]; then
1218 test_done "$testroot" "$ret"
1219 return 1
1222 # split commit1 into commitA and commitB and commitC
1223 echo "e $old_commit1" > $testroot/histedit-script
1224 echo "p $old_commit2" >> $testroot/histedit-script
1226 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1227 > $testroot/stdout 2> $testroot/stderr)
1228 ret="$?"
1229 if [ "$ret" != "0" ]; then
1230 echo "histedit failed unexpectedly:" >&2
1231 cat $testroot/stderr >&2
1232 test_done "$testroot" "$ret"
1233 return 1
1236 echo "G alpha" > $testroot/stdout.expected
1237 echo "D beta" >> $testroot/stdout.expected
1238 echo "A epsilon/new" >> $testroot/stdout.expected
1239 echo "Stopping histedit for amending commit $old_commit1" \
1240 >> $testroot/stdout.expected
1242 cmp -s $testroot/stdout.expected $testroot/stdout
1243 ret="$?"
1244 if [ "$ret" != "0" ]; then
1245 diff -u $testroot/stdout.expected $testroot/stdout
1246 test_done "$testroot" "$ret"
1247 return 1
1250 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1251 ret="$?"
1252 if [ "$ret" != "0" ]; then
1253 echo "commit failed unexpectedly" >&2
1254 test_done "$testroot" "$ret"
1255 return 1
1258 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1259 ret="$?"
1260 if [ "$ret" != "0" ]; then
1261 echo "commit failed unexpectedly" >&2
1262 test_done "$testroot" "$ret"
1263 return 1
1266 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1267 ret="$?"
1268 if [ "$ret" != "0" ]; then
1269 echo "commit failed unexpectedly" >&2
1270 test_done "$testroot" "$ret"
1271 return 1
1274 (cd $testroot/wt && got histedit -c \
1275 > $testroot/stdout 2> $testroot/stderr)
1276 ret="$?"
1277 if [ "$ret" != "0" ]; then
1278 echo "histedit failed unexpectedly:" >&2
1279 cat $testroot/stderr >&2
1280 test_done "$testroot" "$ret"
1281 return 1
1283 local new_commit2=`git_show_head $testroot/repo`
1284 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1286 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1287 > $testroot/stdout.expected
1288 echo "G epsilon/zeta" >> $testroot/stdout.expected
1289 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1290 >> $testroot/stdout.expected
1291 echo "Switching work tree to refs/heads/master" \
1292 >> $testroot/stdout.expected
1294 cmp -s $testroot/stdout.expected $testroot/stdout
1295 ret="$?"
1296 if [ "$ret" != "0" ]; then
1297 diff -u $testroot/stdout.expected $testroot/stdout
1299 test_done "$testroot" "$ret"
1303 test_histedit_duplicate_commit_in_script() {
1304 local testroot=`test_init histedit_duplicate_commit_in_script`
1306 local orig_commit=`git_show_head $testroot/repo`
1308 echo "modified alpha on master" > $testroot/repo/alpha
1309 (cd $testroot/repo && git rm -q beta)
1310 echo "new file on master" > $testroot/repo/epsilon/new
1311 (cd $testroot/repo && git add epsilon/new)
1312 git_commit $testroot/repo -m "committing changes 1"
1313 local old_commit1=`git_show_head $testroot/repo`
1315 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1316 git_commit $testroot/repo -m "committing changes 2"
1317 local old_commit2=`git_show_head $testroot/repo`
1319 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1320 ret="$?"
1321 if [ "$ret" != "0" ]; then
1322 test_done "$testroot" "$ret"
1323 return 1
1326 # This histedit script lists commit1 more than once
1327 echo "p $old_commit1" > $testroot/histedit-script
1328 echo "p $old_commit1" >> $testroot/histedit-script
1329 echo "p $old_commit2" >> $testroot/histedit-script
1331 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1332 > $testroot/stdout 2> $testroot/stderr)
1333 ret="$?"
1334 if [ "$ret" = "0" ]; then
1335 echo "histedit succeeded unexpectedly:" >&2
1336 cat $testroot/stdout >&2
1337 test_done "$testroot" "$ret"
1338 return 1
1341 echo -n "got: commit $old_commit1 is listed more than once " \
1342 > $testroot/stderr.expected
1343 echo "in histedit script" >> $testroot/stderr.expected
1345 cmp -s $testroot/stderr.expected $testroot/stderr
1346 ret="$?"
1347 if [ "$ret" != "0" ]; then
1348 diff -u $testroot/stderr.expected $testroot/stderr
1350 test_done "$testroot" "$ret"
1354 # if a previous commit introduces a new file, and it is folded into a commit
1355 # that deletes the same file, the file still exists after the histedit
1356 test_histedit_fold_add_delete() {
1357 local testroot=`test_init histedit_fold`
1359 local orig_commit=`git_show_head $testroot/repo`
1361 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1362 (cd $testroot/repo && git add epsilon/psi)
1363 git_commit $testroot/repo -m "committing changes"
1364 local old_commit1=`git_show_head $testroot/repo`
1366 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1367 git_commit $testroot/repo -m "editing psi"
1368 local old_commit2=`git_show_head $testroot/repo`
1370 (cd $testroot/repo && git rm -q epsilon/psi)
1371 git_commit $testroot/repo -m "removing psi"
1372 local old_commit3=`git_show_head $testroot/repo`
1374 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1375 ret="$?"
1376 if [ "$ret" != "0" ]; then
1377 test_done "$testroot" "$ret"
1378 return 1
1381 echo "fold $old_commit1" > $testroot/histedit-script
1382 echo "fold $old_commit2" >> $testroot/histedit-script
1383 echo "pick $old_commit3" >> $testroot/histedit-script
1384 echo "mesg folded changes" >> $testroot/histedit-script
1386 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1387 > $testroot/stdout)
1389 local new_commit1=`git_show_head $testroot/repo`
1391 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1392 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1393 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1394 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1396 echo "A epsilon/psi" >> $testroot/stdout.expected
1397 echo "$short_old_commit1 -> fold commit: committing changes" \
1398 >> $testroot/stdout.expected
1399 echo "G epsilon/psi" >> $testroot/stdout.expected
1400 echo "$short_old_commit2 -> fold commit: editing psi" \
1401 >> $testroot/stdout.expected
1402 echo "D epsilon/psi" >> $testroot/stdout.expected
1403 echo "$short_old_commit3 -> no-op change: folded changes" \
1404 >> $testroot/stdout.expected
1405 echo "Switching work tree to refs/heads/master" \
1406 >> $testroot/stdout.expected
1408 cmp -s $testroot/stdout.expected $testroot/stdout
1409 ret="$?"
1410 if [ "$ret" != "0" ]; then
1411 diff -u $testroot/stdout.expected $testroot/stdout
1412 test_done "$testroot" "$ret"
1413 return 1
1416 if [ -e $testroot/wt/epsilon/psi ]; then
1417 echo "removed file psi still exists on disk" >&2
1418 test_done "$testroot" "1"
1419 return 1
1422 (cd $testroot/wt && got status > $testroot/stdout)
1424 echo -n > $testroot/stdout.expected
1425 cmp -s $testroot/stdout.expected $testroot/stdout
1426 ret="$?"
1427 if [ "$ret" != "0" ]; then
1428 diff -u $testroot/stdout.expected $testroot/stdout
1429 test_done "$testroot" "$ret"
1430 return 1
1433 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1434 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1435 cmp -s $testroot/stdout.expected $testroot/stdout
1436 ret="$?"
1437 if [ "$ret" != "0" ]; then
1438 diff -u $testroot/stdout.expected $testroot/stdout
1439 test_done "$testroot" "$ret"
1440 return 1
1443 got tree -r $testroot/repo epsilon > $testroot/stdout
1444 echo "zeta" > $testroot/stdout.expected
1445 cmp -s $testroot/stdout.expected $testroot/stdout
1446 ret="$?"
1447 if [ "$ret" != "0" ]; then
1448 diff -u $testroot/stdout.expected $testroot/stdout
1450 test_done "$testroot" "$ret"
1453 test_histedit_fold_only() {
1454 local testroot=`test_init histedit_fold_only`
1456 local orig_commit=`git_show_head $testroot/repo`
1458 echo "modified alpha on master" > $testroot/repo/alpha
1459 (cd $testroot/repo && git rm -q beta)
1460 echo "new file on master" > $testroot/repo/epsilon/new
1461 (cd $testroot/repo && git add epsilon/new)
1462 git_commit $testroot/repo -m "committing changes"
1463 local old_commit1=`git_show_head $testroot/repo`
1465 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1466 git_commit $testroot/repo -m "committing to zeta on master"
1467 local old_commit2=`git_show_head $testroot/repo`
1469 echo "modified delta on master" > $testroot/repo/gamma/delta
1470 git_commit $testroot/repo -m "committing to delta on master"
1471 local old_commit3=`git_show_head $testroot/repo`
1473 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1474 ret="$?"
1475 if [ "$ret" != "0" ]; then
1476 test_done "$testroot" "$ret"
1477 return 1
1480 cat > $testroot/editor.sh <<EOF
1481 #!/bin/sh
1482 sed -i 's/.*/committing folded changes/' "\$1"
1483 EOF
1484 chmod +x $testroot/editor.sh
1486 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1487 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1489 local new_commit1=`git_show_head $testroot/repo`
1491 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1492 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1493 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1494 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1495 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1497 echo "G alpha" > $testroot/stdout.expected
1498 echo "D beta" >> $testroot/stdout.expected
1499 echo "A epsilon/new" >> $testroot/stdout.expected
1500 echo "$short_old_commit1 -> fold commit: committing changes" \
1501 >> $testroot/stdout.expected
1502 echo "G epsilon/zeta" >> $testroot/stdout.expected
1503 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1504 echo "fold commit: committing to zeta on master" \
1505 >> $testroot/stdout.expected
1506 echo "G gamma/delta" >> $testroot/stdout.expected
1507 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1508 >> $testroot/stdout.expected
1509 echo "committing folded changes" >> $testroot/stdout.expected
1510 echo "Switching work tree to refs/heads/master" \
1511 >> $testroot/stdout.expected
1513 cmp -s $testroot/stdout.expected $testroot/stdout
1514 ret="$?"
1515 if [ "$ret" != "0" ]; then
1516 diff -u $testroot/stdout.expected $testroot/stdout
1517 test_done "$testroot" "$ret"
1518 return 1
1521 echo "modified alpha on master" > $testroot/content.expected
1522 cat $testroot/wt/alpha > $testroot/content
1523 cmp -s $testroot/content.expected $testroot/content
1524 ret="$?"
1525 if [ "$ret" != "0" ]; then
1526 diff -u $testroot/content.expected $testroot/content
1527 test_done "$testroot" "$ret"
1528 return 1
1531 if [ -e $testroot/wt/beta ]; then
1532 echo "removed file beta still exists on disk" >&2
1533 test_done "$testroot" "1"
1534 return 1
1537 echo "new file on master" > $testroot/content.expected
1538 cat $testroot/wt/epsilon/new > $testroot/content
1539 cmp -s $testroot/content.expected $testroot/content
1540 ret="$?"
1541 if [ "$ret" != "0" ]; then
1542 diff -u $testroot/content.expected $testroot/content
1543 test_done "$testroot" "$ret"
1544 return 1
1547 (cd $testroot/wt && got status > $testroot/stdout)
1549 echo -n > $testroot/stdout.expected
1550 cmp -s $testroot/stdout.expected $testroot/stdout
1551 ret="$?"
1552 if [ "$ret" != "0" ]; then
1553 diff -u $testroot/stdout.expected $testroot/stdout
1554 test_done "$testroot" "$ret"
1555 return 1
1558 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1559 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1560 echo "commit $orig_commit" >> $testroot/stdout.expected
1561 cmp -s $testroot/stdout.expected $testroot/stdout
1562 ret="$?"
1563 if [ "$ret" != "0" ]; then
1564 diff -u $testroot/stdout.expected $testroot/stdout
1566 test_done "$testroot" "$ret"
1569 test_histedit_fold_only_empty_logmsg() {
1570 local testroot=`test_init histedit_fold_only_empty_logmsg`
1572 local orig_commit=`git_show_head $testroot/repo`
1574 echo "modified alpha on master" > $testroot/repo/alpha
1575 (cd $testroot/repo && git rm -q beta)
1576 echo "new file on master" > $testroot/repo/epsilon/new
1577 (cd $testroot/repo && git add epsilon/new)
1578 git_commit $testroot/repo -m "committing changes"
1579 local old_commit1=`git_show_head $testroot/repo`
1581 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1582 git_commit $testroot/repo -m "committing to zeta on master"
1583 local old_commit2=`git_show_head $testroot/repo`
1585 echo "modified delta on master" > $testroot/repo/gamma/delta
1586 git_commit $testroot/repo -m "committing to delta on master"
1587 local old_commit3=`git_show_head $testroot/repo`
1589 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1590 ret="$?"
1591 if [ "$ret" != "0" ]; then
1592 test_done "$testroot" "$ret"
1593 return 1
1596 cat > $testroot/editor.sh <<EOF
1597 #!/bin/sh
1598 sed -i 'd' "\$1"
1599 EOF
1600 chmod +x $testroot/editor.sh
1602 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1603 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1605 local new_commit1=`git_show_head $testroot/repo`
1607 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1608 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1609 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1610 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1611 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1612 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1614 echo "G alpha" > $testroot/stdout.expected
1615 echo "D beta" >> $testroot/stdout.expected
1616 echo "A epsilon/new" >> $testroot/stdout.expected
1617 echo "$short_old_commit1 -> fold commit: committing changes" \
1618 >> $testroot/stdout.expected
1619 echo "G epsilon/zeta" >> $testroot/stdout.expected
1620 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1621 echo "fold commit: committing to zeta on master" \
1622 >> $testroot/stdout.expected
1623 echo "G gamma/delta" >> $testroot/stdout.expected
1624 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1625 >> $testroot/stdout.expected
1626 echo "# log message of folded commit $very_short_old_commit1" \
1627 >> $testroot/stdout.expected
1628 echo "Switching work tree to refs/heads/master" \
1629 >> $testroot/stdout.expected
1631 cmp -s $testroot/stdout.expected $testroot/stdout
1632 ret="$?"
1633 if [ "$ret" != "0" ]; then
1634 diff -u $testroot/stdout.expected $testroot/stdout
1635 test_done "$testroot" "$ret"
1636 return 1
1639 echo "modified alpha on master" > $testroot/content.expected
1640 cat $testroot/wt/alpha > $testroot/content
1641 cmp -s $testroot/content.expected $testroot/content
1642 ret="$?"
1643 if [ "$ret" != "0" ]; then
1644 diff -u $testroot/content.expected $testroot/content
1645 test_done "$testroot" "$ret"
1646 return 1
1649 if [ -e $testroot/wt/beta ]; then
1650 echo "removed file beta still exists on disk" >&2
1651 test_done "$testroot" "1"
1652 return 1
1655 echo "new file on master" > $testroot/content.expected
1656 cat $testroot/wt/epsilon/new > $testroot/content
1657 cmp -s $testroot/content.expected $testroot/content
1658 ret="$?"
1659 if [ "$ret" != "0" ]; then
1660 diff -u $testroot/content.expected $testroot/content
1661 test_done "$testroot" "$ret"
1662 return 1
1665 (cd $testroot/wt && got status > $testroot/stdout)
1667 echo -n > $testroot/stdout.expected
1668 cmp -s $testroot/stdout.expected $testroot/stdout
1669 ret="$?"
1670 if [ "$ret" != "0" ]; then
1671 diff -u $testroot/stdout.expected $testroot/stdout
1672 test_done "$testroot" "$ret"
1673 return 1
1676 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1677 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1678 echo "commit $orig_commit" >> $testroot/stdout.expected
1679 cmp -s $testroot/stdout.expected $testroot/stdout
1680 ret="$?"
1681 if [ "$ret" != "0" ]; then
1682 diff -u $testroot/stdout.expected $testroot/stdout
1684 test_done "$testroot" "$ret"
1687 test_parseargs "$@"
1688 run_test test_histedit_no_op
1689 run_test test_histedit_swap
1690 run_test test_histedit_drop
1691 run_test test_histedit_fold
1692 run_test test_histedit_edit
1693 run_test test_histedit_fold_last_commit
1694 run_test test_histedit_missing_commit
1695 run_test test_histedit_abort
1696 run_test test_histedit_path_prefix_drop
1697 run_test test_histedit_path_prefix_edit
1698 run_test test_histedit_outside_refs_heads
1699 run_test test_histedit_fold_last_commit_swap
1700 run_test test_histedit_split_commit
1701 run_test test_histedit_duplicate_commit_in_script
1702 run_test test_histedit_fold_add_delete
1703 run_test test_histedit_fold_only
1704 run_test test_histedit_fold_only_empty_logmsg