Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_histedit_no_op() {
20 local testroot=`test_init histedit_no_op`
22 local orig_commit=`git_show_head $testroot/repo`
23 local orig_author_time=`git_show_author_time $testroot/repo`
25 echo "modified alpha on master" > $testroot/repo/alpha
26 (cd $testroot/repo && git rm -q beta)
27 echo "new file on master" > $testroot/repo/epsilon/new
28 (cd $testroot/repo && git add epsilon/new)
29 git_commit $testroot/repo -m "committing changes"
30 local old_commit1=`git_show_head $testroot/repo`
31 local old_author_time1=`git_show_author_time $testroot/repo`
33 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
34 git_commit $testroot/repo -m "committing to zeta on master"
35 local old_commit2=`git_show_head $testroot/repo`
36 local old_author_time2=`git_show_author_time $testroot/repo`
38 got diff -r $testroot/repo $orig_commit $old_commit2 \
39 > $testroot/diff.expected
41 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
42 ret=$?
43 if [ $ret -ne 0 ]; then
44 test_done "$testroot" "$ret"
45 return 1
46 fi
48 echo "pick $old_commit1" > $testroot/histedit-script
49 echo "pick $old_commit2" >> $testroot/histedit-script
51 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
52 > $testroot/stdout)
54 local new_commit1=`git_show_parent_commit $testroot/repo`
55 local new_commit2=`git_show_head $testroot/repo`
56 local new_author_time2=`git_show_author_time $testroot/repo`
58 local short_old_commit1=`trim_obj_id 28 $old_commit1`
59 local short_old_commit2=`trim_obj_id 28 $old_commit2`
60 local short_new_commit1=`trim_obj_id 28 $new_commit1`
61 local short_new_commit2=`trim_obj_id 28 $new_commit2`
63 echo "G alpha" > $testroot/stdout.expected
64 echo "D beta" >> $testroot/stdout.expected
65 echo "A epsilon/new" >> $testroot/stdout.expected
66 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
67 >> $testroot/stdout.expected
68 echo "G epsilon/zeta" >> $testroot/stdout.expected
69 echo -n "$short_old_commit2 -> $short_new_commit2: " \
70 >> $testroot/stdout.expected
71 echo "committing to zeta on master" >> $testroot/stdout.expected
72 echo "Switching work tree to refs/heads/master" \
73 >> $testroot/stdout.expected
75 cmp -s $testroot/stdout.expected $testroot/stdout
76 ret=$?
77 if [ $ret -ne 0 ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
80 return 1
81 fi
83 echo "modified alpha on master" > $testroot/content.expected
84 cat $testroot/wt/alpha > $testroot/content
85 cmp -s $testroot/content.expected $testroot/content
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 diff -u $testroot/content.expected $testroot/content
89 test_done "$testroot" "$ret"
90 return 1
91 fi
93 if [ -e $testroot/wt/beta ]; then
94 echo "removed file beta still exists on disk" >&2
95 test_done "$testroot" "1"
96 return 1
97 fi
99 echo "new file on master" > $testroot/content.expected
100 cat $testroot/wt/epsilon/new > $testroot/content
101 cmp -s $testroot/content.expected $testroot/content
102 ret=$?
103 if [ $ret -ne 0 ]; then
104 diff -u $testroot/content.expected $testroot/content
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 (cd $testroot/wt && got status > $testroot/stdout)
111 echo -n > $testroot/stdout.expected
112 cmp -s $testroot/stdout.expected $testroot/stdout
113 ret=$?
114 if [ $ret -ne 0 ]; then
115 diff -u $testroot/stdout.expected $testroot/stdout
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
121 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
122 echo "commit $new_commit1" >> $testroot/stdout.expected
123 echo "commit $orig_commit" >> $testroot/stdout.expected
124 cmp -s $testroot/stdout.expected $testroot/stdout
125 ret=$?
126 if [ $ret -ne 0 ]; then
127 diff -u $testroot/stdout.expected $testroot/stdout
128 test_done "$testroot" "$ret"
129 return 1
130 fi
132 got diff -r $testroot/repo $orig_commit $new_commit2 \
133 > $testroot/diff
134 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
135 cmp -s $testroot/diff.expected $testroot/diff
136 ret=$?
137 if [ $ret -ne 0 ]; then
138 diff -u $testroot/diff.expected $testroot/diff
139 test_done "$testroot" "$ret"
140 return 1
141 fi
143 (cd $testroot/wt && got update > $testroot/stdout)
145 echo 'Already up-to-date' > $testroot/stdout.expected
146 cmp -s $testroot/stdout.expected $testroot/stdout
147 ret=$?
148 if [ $ret -ne 0 ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
150 test_done "$testroot" "$ret"
151 return 1
152 fi
154 # We should have a backup of old commits
155 (cd $testroot/repo && got histedit -l > $testroot/stdout)
156 d_orig1=`date -u -r $old_author_time1 +"%G-%m-%d"`
157 d_orig2=`date -u -r $old_author_time2 +"%a %b %e %X %Y UTC"`
158 d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
159 d_orig=`date -u -r $orig_author_time +"%G-%m-%d"`
160 cat > $testroot/stdout.expected <<EOF
161 -----------------------------------------------
162 commit $old_commit2 (formerly master)
163 from: $GOT_AUTHOR
164 date: $d_orig2
166 committing to zeta on master
168 has become commit $new_commit2 (master)
169 $d_new2 $GOT_AUTHOR_11 committing to zeta on master
170 EOF
172 local is_forked=true d_fork fork_commit fork_commit_msg
174 if [ "$old_commit1" = "$new_commit1" ]; then
175 if [ "$old_commit2" = "$new_commit2" ]; then
176 is_forked=false
177 else
178 d_fork=$d_orig1
179 fork_commit=$new_commit1
180 fork_commit_msg="committing changes"
181 fi
182 else
183 d_fork=$d_orig
184 fork_commit=$orig_commit
185 fork_commit_msg="adding the test tree"
186 fi
188 $is_forked && cat >> $testroot/stdout.expected <<EOF
189 history forked at $fork_commit
190 $d_fork $GOT_AUTHOR_11 $fork_commit_msg
191 EOF
193 cmp -s $testroot/stdout.expected $testroot/stdout
194 ret=$?
195 if [ $ret -ne 0 ]; then
196 diff -u $testroot/stdout.expected $testroot/stdout
197 test_done "$testroot" "$ret"
198 return 1
199 fi
201 (cd $testroot/repo && got histedit -X master \
202 > $testroot/stdout 2> $testroot/stderr)
203 echo -n "Deleted refs/got/backup/histedit/master/$new_commit2: " \
204 > $testroot/stdout.expected
205 echo "$old_commit2" >> $testroot/stdout.expected
206 echo -n > $testroot/stderr.expected
207 cmp -s $testroot/stdout.expected $testroot/stdout
208 ret=$?
209 if [ $ret -ne 0 ]; then
210 diff -u $testroot/stdout.expected $testroot/stdout
211 test_done "$testroot" "$ret"
212 return 1
213 fi
214 cmp -s $testroot/stderr.expected $testroot/stderr
215 ret=$?
216 if [ $ret -ne 0 ]; then
217 diff -u $testroot/stderr.expected $testroot/stderr
218 test_done "$testroot" "$ret"
219 return 1
220 fi
222 (cd $testroot/repo && got histedit -l > $testroot/stdout)
223 echo -n > $testroot/stdout.expected
224 cmp -s $testroot/stdout.expected $testroot/stdout
225 ret=$?
226 if [ $ret -ne 0 ]; then
227 diff -u $testroot/stdout.expected $testroot/stdout
228 fi
229 test_done "$testroot" "$ret"
232 test_histedit_swap() {
233 local testroot=`test_init histedit_swap`
235 local orig_commit=`git_show_head $testroot/repo`
237 echo "modified alpha on master" > $testroot/repo/alpha
238 (cd $testroot/repo && git rm -q beta)
239 echo "new file on master" > $testroot/repo/epsilon/new
240 (cd $testroot/repo && git add epsilon/new)
241 git_commit $testroot/repo -m "committing changes"
242 local old_commit1=`git_show_head $testroot/repo`
244 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
245 git_commit $testroot/repo -m "committing to zeta on master"
246 local old_commit2=`git_show_head $testroot/repo`
248 got diff -r $testroot/repo $orig_commit $old_commit2 \
249 > $testroot/diff.expected
251 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
252 ret=$?
253 if [ $ret -ne 0 ]; then
254 test_done "$testroot" "$ret"
255 return 1
256 fi
258 echo "pick $old_commit2" > $testroot/histedit-script
259 echo "pick $old_commit1" >> $testroot/histedit-script
261 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
262 > $testroot/stdout)
264 local new_commit2=`git_show_parent_commit $testroot/repo`
265 local new_commit1=`git_show_head $testroot/repo`
267 local short_old_commit1=`trim_obj_id 28 $old_commit1`
268 local short_old_commit2=`trim_obj_id 28 $old_commit2`
269 local short_new_commit1=`trim_obj_id 28 $new_commit1`
270 local short_new_commit2=`trim_obj_id 28 $new_commit2`
272 echo "G epsilon/zeta" > $testroot/stdout.expected
273 echo -n "$short_old_commit2 -> $short_new_commit2: " \
274 >> $testroot/stdout.expected
275 echo "committing to zeta on master" >> $testroot/stdout.expected
276 echo "G alpha" >> $testroot/stdout.expected
277 echo "D beta" >> $testroot/stdout.expected
278 echo "A epsilon/new" >> $testroot/stdout.expected
279 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
280 >> $testroot/stdout.expected
281 echo "Switching work tree to refs/heads/master" \
282 >> $testroot/stdout.expected
284 cmp -s $testroot/stdout.expected $testroot/stdout
285 ret=$?
286 if [ $ret -ne 0 ]; then
287 diff -u $testroot/stdout.expected $testroot/stdout
288 test_done "$testroot" "$ret"
289 return 1
290 fi
292 echo "modified alpha on master" > $testroot/content.expected
293 cat $testroot/wt/alpha > $testroot/content
294 cmp -s $testroot/content.expected $testroot/content
295 ret=$?
296 if [ $ret -ne 0 ]; then
297 diff -u $testroot/content.expected $testroot/content
298 test_done "$testroot" "$ret"
299 return 1
300 fi
302 if [ -e $testroot/wt/beta ]; then
303 echo "removed file beta still exists on disk" >&2
304 test_done "$testroot" "1"
305 return 1
306 fi
308 echo "new file on master" > $testroot/content.expected
309 cat $testroot/wt/epsilon/new > $testroot/content
310 cmp -s $testroot/content.expected $testroot/content
311 ret=$?
312 if [ $ret -ne 0 ]; then
313 diff -u $testroot/content.expected $testroot/content
314 test_done "$testroot" "$ret"
315 return 1
316 fi
318 (cd $testroot/wt && got status > $testroot/stdout)
320 echo -n > $testroot/stdout.expected
321 cmp -s $testroot/stdout.expected $testroot/stdout
322 ret=$?
323 if [ $ret -ne 0 ]; then
324 diff -u $testroot/stdout.expected $testroot/stdout
325 test_done "$testroot" "$ret"
326 return 1
327 fi
329 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
330 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
331 echo "commit $new_commit2" >> $testroot/stdout.expected
332 echo "commit $orig_commit" >> $testroot/stdout.expected
333 cmp -s $testroot/stdout.expected $testroot/stdout
334 ret=$?
335 if [ $ret -ne 0 ]; then
336 diff -u $testroot/stdout.expected $testroot/stdout
337 test_done "$testroot" "$ret"
338 return 1
339 fi
341 got diff -r $testroot/repo $orig_commit $new_commit1 \
342 > $testroot/diff
343 sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
344 cmp -s $testroot/diff.expected $testroot/diff
345 ret=$?
346 if [ $ret -ne 0 ]; then
347 diff -u $testroot/diff.expected $testroot/diff
348 fi
349 test_done "$testroot" "$ret"
352 test_histedit_drop() {
353 local testroot=`test_init histedit_drop`
354 local orig_commit=`git_show_head $testroot/repo`
356 echo "modified alpha on master" > $testroot/repo/alpha
357 (cd $testroot/repo && git rm -q beta)
358 echo "new file on master" > $testroot/repo/epsilon/new
359 (cd $testroot/repo && git add epsilon/new)
360 git_commit $testroot/repo -m "committing changes"
361 local old_commit1=`git_show_head $testroot/repo`
363 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
364 git_commit $testroot/repo -m "committing to zeta on master"
365 local old_commit2=`git_show_head $testroot/repo`
367 got diff -r $testroot/repo $old_commit1 $old_commit2 \
368 > $testroot/diff.expected
370 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
371 ret=$?
372 if [ $ret -ne 0 ]; then
373 test_done "$testroot" "$ret"
374 return 1
375 fi
377 echo "drop $old_commit1" > $testroot/histedit-script
378 echo "pick $old_commit2" >> $testroot/histedit-script
380 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
381 > $testroot/stdout)
383 local new_commit2=`git_show_head $testroot/repo`
385 local short_old_commit1=`trim_obj_id 28 $old_commit1`
386 local short_old_commit2=`trim_obj_id 28 $old_commit2`
387 local short_new_commit2=`trim_obj_id 28 $new_commit2`
389 echo "$short_old_commit1 -> drop commit: committing changes" \
390 > $testroot/stdout.expected
391 echo "G epsilon/zeta" >> $testroot/stdout.expected
392 echo -n "$short_old_commit2 -> $short_new_commit2: " \
393 >> $testroot/stdout.expected
394 echo "committing to zeta on master" >> $testroot/stdout.expected
395 echo "Switching work tree to refs/heads/master" \
396 >> $testroot/stdout.expected
398 cmp -s $testroot/stdout.expected $testroot/stdout
399 ret=$?
400 if [ $ret -ne 0 ]; then
401 diff -u $testroot/stdout.expected $testroot/stdout
402 test_done "$testroot" "$ret"
403 return 1
404 fi
406 for f in alpha beta; do
407 echo "$f" > $testroot/content.expected
408 cat $testroot/wt/$f > $testroot/content
409 cmp -s $testroot/content.expected $testroot/content
410 ret=$?
411 if [ $ret -ne 0 ]; then
412 diff -u $testroot/content.expected $testroot/content
413 test_done "$testroot" "$ret"
414 return 1
415 fi
416 done
418 if [ -e $testroot/wt/new ]; then
419 echo "file new exists on disk but should not" >&2
420 test_done "$testroot" "1"
421 return 1
422 fi
424 (cd $testroot/wt && got status > $testroot/stdout)
426 echo -n > $testroot/stdout.expected
427 cmp -s $testroot/stdout.expected $testroot/stdout
428 ret=$?
429 if [ $ret -ne 0 ]; then
430 diff -u $testroot/stdout.expected $testroot/stdout
431 test_done "$testroot" "$ret"
432 return 1
433 fi
435 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
436 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
437 echo "commit $orig_commit" >> $testroot/stdout.expected
438 cmp -s $testroot/stdout.expected $testroot/stdout
439 ret=$?
440 if [ $ret -ne 0 ]; then
441 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
443 return 1
444 fi
446 got diff -r $testroot/repo $orig_commit $new_commit2 \
447 > $testroot/diff
448 sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
449 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
450 cmp -s $testroot/diff.expected $testroot/diff
451 ret=$?
452 if [ $ret -ne 0 ]; then
453 diff -u $testroot/diff.expected $testroot/diff
454 fi
455 test_done "$testroot" "$ret"
458 test_histedit_fold() {
459 local testroot=`test_init histedit_fold`
461 local orig_commit=`git_show_head $testroot/repo`
463 echo "modified alpha on master" > $testroot/repo/alpha
464 (cd $testroot/repo && git rm -q beta)
465 echo "new file on master" > $testroot/repo/epsilon/new
466 (cd $testroot/repo && git add epsilon/new)
467 git_commit $testroot/repo -m "committing changes"
468 local old_commit1=`git_show_head $testroot/repo`
470 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
471 git_commit $testroot/repo -m "committing to zeta on master"
472 local old_commit2=`git_show_head $testroot/repo`
474 echo "modified delta on master" > $testroot/repo/gamma/delta
475 git_commit $testroot/repo -m "committing to delta on master"
476 local old_commit3=`git_show_head $testroot/repo`
478 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
479 ret=$?
480 if [ $ret -ne 0 ]; then
481 test_done "$testroot" "$ret"
482 return 1
483 fi
485 echo "fold $old_commit1" > $testroot/histedit-script
486 echo "drop $old_commit2" >> $testroot/histedit-script
487 echo "pick $old_commit3" >> $testroot/histedit-script
488 echo "mesg committing folded changes" >> $testroot/histedit-script
490 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
491 > $testroot/stdout)
493 local new_commit1=`git_show_parent_commit $testroot/repo`
494 local new_commit2=`git_show_head $testroot/repo`
496 local short_old_commit1=`trim_obj_id 28 $old_commit1`
497 local short_old_commit2=`trim_obj_id 28 $old_commit2`
498 local short_old_commit3=`trim_obj_id 28 $old_commit3`
499 local short_new_commit1=`trim_obj_id 28 $new_commit1`
500 local short_new_commit2=`trim_obj_id 28 $new_commit2`
502 echo "G alpha" > $testroot/stdout.expected
503 echo "D beta" >> $testroot/stdout.expected
504 echo "A epsilon/new" >> $testroot/stdout.expected
505 echo "$short_old_commit1 -> fold commit: committing changes" \
506 >> $testroot/stdout.expected
507 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
508 echo "drop commit: committing to zeta on master" \
509 >> $testroot/stdout.expected
510 echo "G gamma/delta" >> $testroot/stdout.expected
511 echo -n "$short_old_commit3 -> $short_new_commit2: " \
512 >> $testroot/stdout.expected
513 echo "committing folded changes" >> $testroot/stdout.expected
514 echo "Switching work tree to refs/heads/master" \
515 >> $testroot/stdout.expected
517 cmp -s $testroot/stdout.expected $testroot/stdout
518 ret=$?
519 if [ $ret -ne 0 ]; then
520 diff -u $testroot/stdout.expected $testroot/stdout
521 test_done "$testroot" "$ret"
522 return 1
523 fi
525 echo "modified alpha on master" > $testroot/content.expected
526 cat $testroot/wt/alpha > $testroot/content
527 cmp -s $testroot/content.expected $testroot/content
528 ret=$?
529 if [ $ret -ne 0 ]; then
530 diff -u $testroot/content.expected $testroot/content
531 test_done "$testroot" "$ret"
532 return 1
533 fi
535 if [ -e $testroot/wt/beta ]; then
536 echo "removed file beta still exists on disk" >&2
537 test_done "$testroot" "1"
538 return 1
539 fi
541 echo "new file on master" > $testroot/content.expected
542 cat $testroot/wt/epsilon/new > $testroot/content
543 cmp -s $testroot/content.expected $testroot/content
544 ret=$?
545 if [ $ret -ne 0 ]; then
546 diff -u $testroot/content.expected $testroot/content
547 test_done "$testroot" "$ret"
548 return 1
549 fi
551 (cd $testroot/wt && got status > $testroot/stdout)
553 echo -n > $testroot/stdout.expected
554 cmp -s $testroot/stdout.expected $testroot/stdout
555 ret=$?
556 if [ $ret -ne 0 ]; then
557 diff -u $testroot/stdout.expected $testroot/stdout
558 test_done "$testroot" "$ret"
559 return 1
560 fi
562 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
563 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
564 echo "commit $orig_commit" >> $testroot/stdout.expected
565 cmp -s $testroot/stdout.expected $testroot/stdout
566 ret=$?
567 if [ $ret -ne 0 ]; then
568 diff -u $testroot/stdout.expected $testroot/stdout
569 fi
570 test_done "$testroot" "$ret"
573 test_histedit_edit() {
574 local testroot=`test_init histedit_edit`
576 local orig_commit=`git_show_head $testroot/repo`
578 echo "modified alpha on master" > $testroot/repo/alpha
579 (cd $testroot/repo && git rm -q beta)
580 echo "new file on master" > $testroot/repo/epsilon/new
581 (cd $testroot/repo && git add epsilon/new)
582 git_commit $testroot/repo -m "committing changes"
583 local old_commit1=`git_show_head $testroot/repo`
585 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
586 git_commit $testroot/repo -m "committing to zeta on master"
587 local old_commit2=`git_show_head $testroot/repo`
589 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
590 ret=$?
591 if [ $ret -ne 0 ]; then
592 test_done "$testroot" "$ret"
593 return 1
594 fi
596 echo "edit $old_commit1" > $testroot/histedit-script
597 echo "mesg committing changes" >> $testroot/histedit-script
598 echo "pick $old_commit2" >> $testroot/histedit-script
600 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
601 > $testroot/stdout)
603 local short_old_commit1=`trim_obj_id 28 $old_commit1`
604 local short_old_commit2=`trim_obj_id 28 $old_commit2`
606 echo "G alpha" > $testroot/stdout.expected
607 echo "D beta" >> $testroot/stdout.expected
608 echo "A epsilon/new" >> $testroot/stdout.expected
609 echo "Stopping histedit for amending commit $old_commit1" \
610 >> $testroot/stdout.expected
611 cmp -s $testroot/stdout.expected $testroot/stdout
612 ret=$?
613 if [ $ret -ne 0 ]; then
614 diff -u $testroot/stdout.expected $testroot/stdout
615 test_done "$testroot" "$ret"
616 return 1
617 fi
619 echo "edited modified alpha on master" > $testroot/wt/alpha
621 # test interaction of 'got stage' and histedit -c
622 (cd $testroot/wt && got stage alpha > /dev/null)
623 (cd $testroot/wt && got histedit -c > $testroot/stdout \
624 2> $testroot/stderr)
625 ret=$?
626 if [ $ret -eq 0 ]; then
627 echo "histedit succeeded unexpectedly" >&2
628 test_done "$testroot" "1"
629 return 1
630 fi
631 echo -n "got: work tree contains files with staged changes; " \
632 > $testroot/stderr.expected
633 echo "these changes must be committed or unstaged first" \
634 >> $testroot/stderr.expected
635 cmp -s $testroot/stderr.expected $testroot/stderr
636 ret=$?
637 if [ $ret -ne 0 ]; then
638 diff -u $testroot/stderr.expected $testroot/stderr
639 test_done "$testroot" "$ret"
640 return 1
641 fi
643 (cd $testroot/wt && got unstage alpha > /dev/null)
644 (cd $testroot/wt && got histedit -c > $testroot/stdout)
646 local new_commit1=`git_show_parent_commit $testroot/repo`
647 local new_commit2=`git_show_head $testroot/repo`
649 local short_new_commit1=`trim_obj_id 28 $new_commit1`
650 local short_new_commit2=`trim_obj_id 28 $new_commit2`
652 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
653 > $testroot/stdout.expected
654 echo "G epsilon/zeta" >> $testroot/stdout.expected
655 echo -n "$short_old_commit2 -> $short_new_commit2: " \
656 >> $testroot/stdout.expected
657 echo "committing to zeta on master" >> $testroot/stdout.expected
658 echo "Switching work tree to refs/heads/master" \
659 >> $testroot/stdout.expected
661 cmp -s $testroot/stdout.expected $testroot/stdout
662 ret=$?
663 if [ $ret -ne 0 ]; then
664 diff -u $testroot/stdout.expected $testroot/stdout
665 test_done "$testroot" "$ret"
666 return 1
667 fi
669 echo "edited modified alpha on master" > $testroot/content.expected
670 cat $testroot/wt/alpha > $testroot/content
671 cmp -s $testroot/content.expected $testroot/content
672 ret=$?
673 if [ $ret -ne 0 ]; then
674 diff -u $testroot/content.expected $testroot/content
675 test_done "$testroot" "$ret"
676 return 1
677 fi
679 if [ -e $testroot/wt/beta ]; then
680 echo "removed file beta still exists on disk" >&2
681 test_done "$testroot" "1"
682 return 1
683 fi
685 echo "new file on master" > $testroot/content.expected
686 cat $testroot/wt/epsilon/new > $testroot/content
687 cmp -s $testroot/content.expected $testroot/content
688 ret=$?
689 if [ $ret -ne 0 ]; then
690 diff -u $testroot/content.expected $testroot/content
691 test_done "$testroot" "$ret"
692 return 1
693 fi
695 (cd $testroot/wt && got status > $testroot/stdout)
697 echo -n > $testroot/stdout.expected
698 cmp -s $testroot/stdout.expected $testroot/stdout
699 ret=$?
700 if [ $ret -ne 0 ]; then
701 diff -u $testroot/stdout.expected $testroot/stdout
702 test_done "$testroot" "$ret"
703 return 1
704 fi
706 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
707 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
708 echo "commit $new_commit1" >> $testroot/stdout.expected
709 echo "commit $orig_commit" >> $testroot/stdout.expected
710 cmp -s $testroot/stdout.expected $testroot/stdout
711 ret=$?
712 if [ $ret -ne 0 ]; then
713 diff -u $testroot/stdout.expected $testroot/stdout
714 fi
715 test_done "$testroot" "$ret"
718 test_histedit_fold_last_commit() {
719 local testroot=`test_init histedit_fold_last_commit`
721 local orig_commit=`git_show_head $testroot/repo`
723 echo "modified alpha on master" > $testroot/repo/alpha
724 (cd $testroot/repo && git rm -q beta)
725 echo "new file on master" > $testroot/repo/epsilon/new
726 (cd $testroot/repo && git add epsilon/new)
727 git_commit $testroot/repo -m "committing changes"
728 local old_commit1=`git_show_head $testroot/repo`
730 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
731 git_commit $testroot/repo -m "committing to zeta on master"
732 local old_commit2=`git_show_head $testroot/repo`
734 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
735 ret=$?
736 if [ $ret -ne 0 ]; then
737 test_done "$testroot" "$ret"
738 return 1
739 fi
741 echo "pick $old_commit1" > $testroot/histedit-script
742 echo "fold $old_commit2" >> $testroot/histedit-script
743 echo "mesg committing folded changes" >> $testroot/histedit-script
745 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
746 > $testroot/stdout 2> $testroot/stderr)
748 ret=$?
749 if [ $ret -eq 0 ]; then
750 echo "histedit succeeded unexpectedly" >&2
751 test_done "$testroot" "1"
752 return 1
753 fi
755 echo "got: last commit in histedit script cannot be folded" \
756 > $testroot/stderr.expected
758 cmp -s $testroot/stderr.expected $testroot/stderr
759 ret=$?
760 if [ $ret -ne 0 ]; then
761 diff -u $testroot/stderr.expected $testroot/stderr
762 fi
763 test_done "$testroot" "$ret"
766 test_histedit_missing_commit() {
767 local testroot=`test_init histedit_missing_commit`
769 local orig_commit=`git_show_head $testroot/repo`
771 echo "modified alpha on master" > $testroot/repo/alpha
772 (cd $testroot/repo && git rm -q beta)
773 echo "new file on master" > $testroot/repo/epsilon/new
774 (cd $testroot/repo && git add epsilon/new)
775 git_commit $testroot/repo -m "committing changes"
776 local old_commit1=`git_show_head $testroot/repo`
778 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
779 git_commit $testroot/repo -m "committing to zeta on master"
780 local old_commit2=`git_show_head $testroot/repo`
782 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
783 ret=$?
784 if [ $ret -ne 0 ]; then
785 test_done "$testroot" "$ret"
786 return 1
787 fi
789 echo "pick $old_commit1" > $testroot/histedit-script
790 echo "mesg committing changes" >> $testroot/histedit-script
792 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
793 > $testroot/stdout 2> $testroot/stderr)
795 ret=$?
796 if [ $ret -eq 0 ]; then
797 echo "histedit succeeded unexpectedly" >&2
798 test_done "$testroot" "1"
799 return 1
800 fi
802 echo "got: commit $old_commit2 missing from histedit script" \
803 > $testroot/stderr.expected
805 cmp -s $testroot/stderr.expected $testroot/stderr
806 ret=$?
807 if [ $ret -ne 0 ]; then
808 diff -u $testroot/stderr.expected $testroot/stderr
809 fi
810 test_done "$testroot" "$ret"
813 test_histedit_abort() {
814 local testroot=`test_init histedit_abort`
816 local orig_commit=`git_show_head $testroot/repo`
818 echo "modified alpha on master" > $testroot/repo/alpha
819 (cd $testroot/repo && git rm -q beta)
820 echo "new file on master" > $testroot/repo/epsilon/new
821 (cd $testroot/repo && git add epsilon/new)
822 git_commit $testroot/repo -m "committing changes"
823 local old_commit1=`git_show_head $testroot/repo`
825 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
826 git_commit $testroot/repo -m "committing to zeta on master"
827 local old_commit2=`git_show_head $testroot/repo`
829 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
830 ret=$?
831 if [ $ret -ne 0 ]; then
832 test_done "$testroot" "$ret"
833 return 1
834 fi
836 # unrelated unversioned file in work tree
837 touch $testroot/wt/unversioned-file
839 echo "edit $old_commit1" > $testroot/histedit-script
840 echo "mesg committing changes" >> $testroot/histedit-script
841 echo "pick $old_commit2" >> $testroot/histedit-script
843 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
844 > $testroot/stdout)
846 local short_old_commit1=`trim_obj_id 28 $old_commit1`
847 local short_old_commit2=`trim_obj_id 28 $old_commit2`
849 echo "G alpha" > $testroot/stdout.expected
850 echo "D beta" >> $testroot/stdout.expected
851 echo "A epsilon/new" >> $testroot/stdout.expected
852 echo "Stopping histedit for amending commit $old_commit1" \
853 >> $testroot/stdout.expected
854 cmp -s $testroot/stdout.expected $testroot/stdout
855 ret=$?
856 if [ $ret -ne 0 ]; then
857 diff -u $testroot/stdout.expected $testroot/stdout
858 test_done "$testroot" "$ret"
859 return 1
860 fi
862 echo "edited modified alpha on master" > $testroot/wt/alpha
864 (cd $testroot/wt && got histedit -a > $testroot/stdout)
866 local new_commit1=`git_show_parent_commit $testroot/repo`
867 local new_commit2=`git_show_head $testroot/repo`
869 echo "Switching work tree to refs/heads/master" \
870 > $testroot/stdout.expected
871 echo "R alpha" >> $testroot/stdout.expected
872 echo "R beta" >> $testroot/stdout.expected
873 echo "R epsilon/new" >> $testroot/stdout.expected
874 echo "Histedit of refs/heads/master aborted" \
875 >> $testroot/stdout.expected
877 cmp -s $testroot/stdout.expected $testroot/stdout
878 ret=$?
879 if [ $ret -ne 0 ]; then
880 diff -u $testroot/stdout.expected $testroot/stdout
881 test_done "$testroot" "$ret"
882 return 1
883 fi
885 for f in alpha beta; do
886 echo "$f" > $testroot/content.expected
887 cat $testroot/wt/$f > $testroot/content
888 cmp -s $testroot/content.expected $testroot/content
889 ret=$?
890 if [ $ret -ne 0 ]; then
891 diff -u $testroot/content.expected $testroot/content
892 test_done "$testroot" "$ret"
893 return 1
894 fi
895 done
897 echo "new file on master" > $testroot/content.expected
898 cat $testroot/wt/epsilon/new > $testroot/content
899 cmp -s $testroot/content.expected $testroot/content
900 ret=$?
901 if [ $ret -ne 0 ]; then
902 diff -u $testroot/content.expected $testroot/content
903 test_done "$testroot" "$ret"
904 return 1
905 fi
907 (cd $testroot/wt && got status > $testroot/stdout)
909 echo "? epsilon/new" > $testroot/stdout.expected
910 echo "? unversioned-file" >> $testroot/stdout.expected
911 cmp -s $testroot/stdout.expected $testroot/stdout
912 ret=$?
913 if [ $ret -ne 0 ]; then
914 diff -u $testroot/stdout.expected $testroot/stdout
915 test_done "$testroot" "$ret"
916 return 1
917 fi
919 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
920 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
921 echo "commit $new_commit1" >> $testroot/stdout.expected
922 echo "commit $orig_commit" >> $testroot/stdout.expected
923 cmp -s $testroot/stdout.expected $testroot/stdout
924 ret=$?
925 if [ $ret -ne 0 ]; then
926 diff -u $testroot/stdout.expected $testroot/stdout
927 fi
928 test_done "$testroot" "$ret"
931 test_histedit_path_prefix_drop() {
932 local testroot=`test_init histedit_path_prefix_drop`
933 local orig_commit=`git_show_head $testroot/repo`
935 echo "modified zeta" > $testroot/repo/epsilon/zeta
936 git_commit $testroot/repo -m "changing zeta"
937 local old_commit1=`git_show_head $testroot/repo`
939 got checkout -c $orig_commit -p gamma $testroot/repo \
940 $testroot/wt > /dev/null
941 ret=$?
942 if [ $ret -ne 0 ]; then
943 test_done "$testroot" "$ret"
944 return 1
945 fi
947 echo "drop $old_commit1" > $testroot/histedit-script
949 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
950 > $testroot/stdout 2> $testroot/stderr)
952 ret=$?
953 if [ $ret -eq 0 ]; then
954 echo "histedit succeeded unexpectedly" >&2
955 test_done "$testroot" "1"
956 return 1
957 fi
959 echo -n "got: cannot edit branch history which contains changes " \
960 > $testroot/stderr.expected
961 echo "outside of this work tree's path prefix" \
962 >> $testroot/stderr.expected
964 cmp -s $testroot/stderr.expected $testroot/stderr
965 ret=$?
966 if [ $ret -ne 0 ]; then
967 diff -u $testroot/stderr.expected $testroot/stderr
968 test_done "$testroot" "$ret"
969 return 1
970 fi
972 rm -rf $testroot/wt
973 got checkout -c $orig_commit -p epsilon $testroot/repo \
974 $testroot/wt > /dev/null
975 ret=$?
976 if [ $ret -ne 0 ]; then
977 test_done "$testroot" "$ret"
978 return 1
979 fi
980 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
981 > $testroot/stdout)
983 local short_old_commit1=`trim_obj_id 28 $old_commit1`
984 local short_old_commit2=`trim_obj_id 28 $old_commit2`
986 echo "$short_old_commit1 -> drop commit: changing zeta" \
987 > $testroot/stdout.expected
988 echo "Switching work tree to refs/heads/master" \
989 >> $testroot/stdout.expected
991 cmp -s $testroot/stdout.expected $testroot/stdout
992 ret=$?
993 if [ $ret -ne 0 ]; then
994 diff -u $testroot/stdout.expected $testroot/stdout
995 test_done "$testroot" "$ret"
996 return 1
997 fi
999 echo "zeta" > $testroot/content.expected
1000 cat $testroot/wt/zeta > $testroot/content
1001 cmp -s $testroot/content.expected $testroot/content
1002 ret=$?
1003 if [ $ret -ne 0 ]; then
1004 diff -u $testroot/content.expected $testroot/content
1005 test_done "$testroot" "$ret"
1006 return 1
1010 (cd $testroot/wt && got status > $testroot/stdout)
1012 echo -n > $testroot/stdout.expected
1013 cmp -s $testroot/stdout.expected $testroot/stdout
1014 ret=$?
1015 if [ $ret -ne 0 ]; then
1016 diff -u $testroot/stdout.expected $testroot/stdout
1017 test_done "$testroot" "$ret"
1018 return 1
1021 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1022 echo "commit $orig_commit (master)" > $testroot/stdout.expected
1023 cmp -s $testroot/stdout.expected $testroot/stdout
1024 ret=$?
1025 if [ $ret -ne 0 ]; then
1026 diff -u $testroot/stdout.expected $testroot/stdout
1028 test_done "$testroot" "$ret"
1031 test_histedit_path_prefix_edit() {
1032 local testroot=`test_init histedit_path_prefix_edit`
1033 local orig_commit=`git_show_head $testroot/repo`
1035 echo "modified zeta" > $testroot/repo/epsilon/zeta
1036 git_commit $testroot/repo -m "changing zeta"
1037 local old_commit1=`git_show_head $testroot/repo`
1039 got diff -r $testroot/repo $orig_commit $old_commit1 \
1040 > $testroot/diff.expected
1042 got checkout -c $orig_commit -p gamma $testroot/repo \
1043 $testroot/wt > /dev/null
1044 ret=$?
1045 if [ $ret -ne 0 ]; then
1046 test_done "$testroot" "$ret"
1047 return 1
1050 echo "edit $old_commit1" > $testroot/histedit-script
1051 echo "mesg modified zeta" >> $testroot/histedit-script
1053 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1054 > $testroot/stdout 2> $testroot/stderr)
1056 ret=$?
1057 if [ $ret -eq 0 ]; then
1058 echo "histedit succeeded unexpectedly" >&2
1059 test_done "$testroot" "1"
1060 return 1
1063 echo -n "got: cannot edit branch history which contains changes " \
1064 > $testroot/stderr.expected
1065 echo "outside of this work tree's path prefix" \
1066 >> $testroot/stderr.expected
1068 cmp -s $testroot/stderr.expected $testroot/stderr
1069 ret=$?
1070 if [ $ret -ne 0 ]; then
1071 diff -u $testroot/stderr.expected $testroot/stderr
1072 test_done "$testroot" "$ret"
1073 return 1
1076 rm -rf $testroot/wt
1077 got checkout -c $orig_commit -p epsilon $testroot/repo \
1078 $testroot/wt > /dev/null
1079 ret=$?
1080 if [ $ret -ne 0 ]; then
1081 test_done "$testroot" "$ret"
1082 return 1
1084 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1085 > $testroot/stdout)
1087 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1089 echo "G zeta" > $testroot/stdout.expected
1090 echo "Stopping histedit for amending commit $old_commit1" \
1091 >> $testroot/stdout.expected
1092 cmp -s $testroot/stdout.expected $testroot/stdout
1093 ret=$?
1094 if [ $ret -ne 0 ]; then
1095 diff -u $testroot/stdout.expected $testroot/stdout
1096 test_done "$testroot" "$ret"
1097 return 1
1100 echo "modified zeta" > $testroot/content.expected
1101 cat $testroot/wt/zeta > $testroot/content
1102 cmp -s $testroot/content.expected $testroot/content
1103 ret=$?
1104 if [ $ret -ne 0 ]; then
1105 diff -u $testroot/content.expected $testroot/content
1106 test_done "$testroot" "$ret"
1107 return 1
1110 (cd $testroot/wt && got status > $testroot/stdout)
1112 echo "M zeta"> $testroot/stdout.expected
1113 cmp -s $testroot/stdout.expected $testroot/stdout
1114 ret=$?
1115 if [ $ret -ne 0 ]; then
1116 diff -u $testroot/stdout.expected $testroot/stdout
1117 test_done "$testroot" "$ret"
1118 return 1
1121 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1123 local new_commit1=`git_show_head $testroot/repo`
1124 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1126 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1127 > $testroot/stdout.expected
1128 echo "modified zeta" >> $testroot/stdout.expected
1129 echo "Switching work tree to refs/heads/master" \
1130 >> $testroot/stdout.expected
1132 cmp -s $testroot/stdout.expected $testroot/stdout
1133 ret=$?
1134 if [ $ret -ne 0 ]; then
1135 diff -u $testroot/stdout.expected $testroot/stdout
1136 test_done "$testroot" "$ret"
1137 return 1
1140 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1141 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1142 echo "commit $orig_commit" >> $testroot/stdout.expected
1143 cmp -s $testroot/stdout.expected $testroot/stdout
1144 ret=$?
1145 if [ $ret -ne 0 ]; then
1146 diff -u $testroot/stdout.expected $testroot/stdout
1147 test_done "$testroot" "$ret"
1148 return 1
1151 got diff -r $testroot/repo $orig_commit $new_commit1 \
1152 > $testroot/diff
1153 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1154 cmp -s $testroot/diff.expected $testroot/diff
1155 ret=$?
1156 if [ $ret -ne 0 ]; then
1157 diff -u $testroot/diff.expected $testroot/diff
1159 test_done "$testroot" "$ret"
1162 test_histedit_outside_refs_heads() {
1163 local testroot=`test_init histedit_outside_refs_heads`
1164 local commit1=`git_show_head $testroot/repo`
1166 got checkout $testroot/repo $testroot/wt > /dev/null
1167 ret=$?
1168 if [ $ret -ne 0 ]; then
1169 echo "got checkout failed unexpectedly"
1170 test_done "$testroot" "$ret"
1171 return 1
1174 echo "modified alpha" > $testroot/wt/alpha
1176 (cd $testroot/wt && got commit -m 'change alpha' \
1177 > $testroot/stdout 2> $testroot/stderr)
1178 ret=$?
1179 if [ $ret -ne 0 ]; then
1180 echo "got commit failed unexpectedly" >&2
1181 test_done "$testroot" "1"
1182 return 1
1184 local commit2=`git_show_head $testroot/repo`
1186 got ref -r $testroot/repo -c master refs/remotes/origin/master
1187 ret=$?
1188 if [ $ret -ne 0 ]; then
1189 echo "got ref failed unexpectedly" >&2
1190 test_done "$testroot" "1"
1191 return 1
1194 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1195 ret=$?
1196 if [ $ret -ne 0 ]; then
1197 echo "got update failed unexpectedly"
1198 test_done "$testroot" "$ret"
1199 return 1
1202 echo "edit $commit2" > $testroot/histedit-script
1203 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1204 2> $testroot/stderr)
1206 echo -n "got: will not edit commit history of a branch outside the " \
1207 > $testroot/stderr.expected
1208 echo '"refs/heads/" reference namespace' \
1209 >> $testroot/stderr.expected
1210 cmp -s $testroot/stderr.expected $testroot/stderr
1211 ret=$?
1212 if [ $ret -ne 0 ]; then
1213 diff -u $testroot/stderr.expected $testroot/stderr
1215 test_done "$testroot" "$ret"
1218 test_histedit_fold_last_commit_swap() {
1219 local testroot=`test_init histedit_fold_last_commit_swap`
1221 local orig_commit=`git_show_head $testroot/repo`
1223 echo "modified alpha on master" > $testroot/repo/alpha
1224 (cd $testroot/repo && git rm -q beta)
1225 echo "new file on master" > $testroot/repo/epsilon/new
1226 (cd $testroot/repo && git add epsilon/new)
1227 git_commit $testroot/repo -m "committing changes"
1228 local old_commit1=`git_show_head $testroot/repo`
1230 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1231 git_commit $testroot/repo -m "committing to zeta on master"
1232 local old_commit2=`git_show_head $testroot/repo`
1234 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1235 ret=$?
1236 if [ $ret -ne 0 ]; then
1237 test_done "$testroot" "$ret"
1238 return 1
1241 # fold commit2 into commit1 (requires swapping commits)
1242 echo "fold $old_commit2" > $testroot/histedit-script
1243 echo "pick $old_commit1" >> $testroot/histedit-script
1244 echo "mesg committing folded changes" >> $testroot/histedit-script
1246 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1247 > $testroot/stdout 2> $testroot/stderr)
1249 ret=$?
1250 if [ $ret -ne 0 ]; then
1251 echo "histedit failed unexpectedly" >&2
1252 test_done "$testroot" "$ret"
1253 return 1
1256 local new_commit=`git_show_head $testroot/repo`
1258 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1259 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1260 local short_new_commit=`trim_obj_id 28 $new_commit`
1262 echo "G epsilon/zeta" >> $testroot/stdout.expected
1263 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1264 >> $testroot/stdout.expected
1265 echo "on master" >> $testroot/stdout.expected
1266 echo "G alpha" >> $testroot/stdout.expected
1267 echo "D beta" >> $testroot/stdout.expected
1268 echo "A epsilon/new" >> $testroot/stdout.expected
1269 echo -n "$short_old_commit1 -> $short_new_commit: " \
1270 >> $testroot/stdout.expected
1271 echo "committing folded changes" >> $testroot/stdout.expected
1272 echo "Switching work tree to refs/heads/master" \
1273 >> $testroot/stdout.expected
1275 cmp -s $testroot/stdout.expected $testroot/stdout
1276 ret=$?
1277 if [ $ret -ne 0 ]; then
1278 diff -u $testroot/stdout.expected $testroot/stdout
1280 test_done "$testroot" "$ret"
1283 test_histedit_split_commit() {
1284 local testroot=`test_init histedit_split_commit`
1286 local orig_commit=`git_show_head $testroot/repo`
1288 echo "modified alpha on master" > $testroot/repo/alpha
1289 (cd $testroot/repo && git rm -q beta)
1290 echo "new file on master" > $testroot/repo/epsilon/new
1291 (cd $testroot/repo && git add epsilon/new)
1292 git_commit $testroot/repo -m "committing changes 1"
1293 local old_commit1=`git_show_head $testroot/repo`
1294 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1296 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1297 git_commit $testroot/repo -m "committing changes 2"
1298 local old_commit2=`git_show_head $testroot/repo`
1299 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1301 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1302 ret=$?
1303 if [ $ret -ne 0 ]; then
1304 test_done "$testroot" "$ret"
1305 return 1
1308 # split commit1 into commitA and commitB and commitC
1309 echo "e $old_commit1" > $testroot/histedit-script
1310 echo "p $old_commit2" >> $testroot/histedit-script
1312 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1313 > $testroot/stdout 2> $testroot/stderr)
1314 ret=$?
1315 if [ $ret -ne 0 ]; then
1316 echo "histedit failed unexpectedly:" >&2
1317 cat $testroot/stderr >&2
1318 test_done "$testroot" "$ret"
1319 return 1
1322 echo "G alpha" > $testroot/stdout.expected
1323 echo "D beta" >> $testroot/stdout.expected
1324 echo "A epsilon/new" >> $testroot/stdout.expected
1325 echo "Stopping histedit for amending commit $old_commit1" \
1326 >> $testroot/stdout.expected
1328 cmp -s $testroot/stdout.expected $testroot/stdout
1329 ret=$?
1330 if [ $ret -ne 0 ]; then
1331 diff -u $testroot/stdout.expected $testroot/stdout
1332 test_done "$testroot" "$ret"
1333 return 1
1336 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1337 ret=$?
1338 if [ $ret -ne 0 ]; then
1339 echo "commit failed unexpectedly" >&2
1340 test_done "$testroot" "$ret"
1341 return 1
1344 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1345 ret=$?
1346 if [ $ret -ne 0 ]; then
1347 echo "commit failed unexpectedly" >&2
1348 test_done "$testroot" "$ret"
1349 return 1
1352 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1353 ret=$?
1354 if [ $ret -ne 0 ]; then
1355 echo "commit failed unexpectedly" >&2
1356 test_done "$testroot" "$ret"
1357 return 1
1360 (cd $testroot/wt && got histedit -c \
1361 > $testroot/stdout 2> $testroot/stderr)
1362 ret=$?
1363 if [ $ret -ne 0 ]; then
1364 echo "histedit failed unexpectedly:" >&2
1365 cat $testroot/stderr >&2
1366 test_done "$testroot" "$ret"
1367 return 1
1369 local new_commit2=`git_show_head $testroot/repo`
1370 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1372 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1373 > $testroot/stdout.expected
1374 echo "G epsilon/zeta" >> $testroot/stdout.expected
1375 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1376 >> $testroot/stdout.expected
1377 echo "Switching work tree to refs/heads/master" \
1378 >> $testroot/stdout.expected
1380 cmp -s $testroot/stdout.expected $testroot/stdout
1381 ret=$?
1382 if [ $ret -ne 0 ]; then
1383 diff -u $testroot/stdout.expected $testroot/stdout
1385 test_done "$testroot" "$ret"
1389 test_histedit_duplicate_commit_in_script() {
1390 local testroot=`test_init histedit_duplicate_commit_in_script`
1392 local orig_commit=`git_show_head $testroot/repo`
1394 echo "modified alpha on master" > $testroot/repo/alpha
1395 (cd $testroot/repo && git rm -q beta)
1396 echo "new file on master" > $testroot/repo/epsilon/new
1397 (cd $testroot/repo && git add epsilon/new)
1398 git_commit $testroot/repo -m "committing changes 1"
1399 local old_commit1=`git_show_head $testroot/repo`
1401 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1402 git_commit $testroot/repo -m "committing changes 2"
1403 local old_commit2=`git_show_head $testroot/repo`
1405 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1406 ret=$?
1407 if [ $ret -ne 0 ]; then
1408 test_done "$testroot" "$ret"
1409 return 1
1412 # This histedit script lists commit1 more than once
1413 echo "p $old_commit1" > $testroot/histedit-script
1414 echo "p $old_commit1" >> $testroot/histedit-script
1415 echo "p $old_commit2" >> $testroot/histedit-script
1417 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1418 > $testroot/stdout 2> $testroot/stderr)
1419 ret=$?
1420 if [ $ret -eq 0 ]; then
1421 echo "histedit succeeded unexpectedly:" >&2
1422 cat $testroot/stdout >&2
1423 test_done "$testroot" "$ret"
1424 return 1
1427 echo -n "got: commit $old_commit1 is listed more than once " \
1428 > $testroot/stderr.expected
1429 echo "in histedit script" >> $testroot/stderr.expected
1431 cmp -s $testroot/stderr.expected $testroot/stderr
1432 ret=$?
1433 if [ $ret -ne 0 ]; then
1434 diff -u $testroot/stderr.expected $testroot/stderr
1436 test_done "$testroot" "$ret"
1440 # if a previous commit introduces a new file, and it is folded into a commit
1441 # that deletes the same file, the file still exists after the histedit
1442 test_histedit_fold_add_delete() {
1443 local testroot=`test_init histedit_fold_add_delete`
1445 local orig_commit=`git_show_head $testroot/repo`
1447 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1448 (cd $testroot/repo && git add epsilon/psi)
1449 git_commit $testroot/repo -m "committing changes"
1450 local old_commit1=`git_show_head $testroot/repo`
1452 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1453 git_commit $testroot/repo -m "editing psi"
1454 local old_commit2=`git_show_head $testroot/repo`
1456 (cd $testroot/repo && git rm -q epsilon/psi)
1457 git_commit $testroot/repo -m "removing psi"
1458 local old_commit3=`git_show_head $testroot/repo`
1460 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1461 ret=$?
1462 if [ $ret -ne 0 ]; then
1463 test_done "$testroot" "$ret"
1464 return 1
1467 echo "fold $old_commit1" > $testroot/histedit-script
1468 echo "fold $old_commit2" >> $testroot/histedit-script
1469 echo "pick $old_commit3" >> $testroot/histedit-script
1470 echo "mesg folded changes" >> $testroot/histedit-script
1472 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1473 > $testroot/stdout)
1475 local new_commit1=`git_show_head $testroot/repo`
1477 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1478 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1479 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1480 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1482 echo "A epsilon/psi" >> $testroot/stdout.expected
1483 echo "$short_old_commit1 -> fold commit: committing changes" \
1484 >> $testroot/stdout.expected
1485 echo "G epsilon/psi" >> $testroot/stdout.expected
1486 echo "$short_old_commit2 -> fold commit: editing psi" \
1487 >> $testroot/stdout.expected
1488 echo "D epsilon/psi" >> $testroot/stdout.expected
1489 echo "$short_old_commit3 -> no-op change: folded changes" \
1490 >> $testroot/stdout.expected
1491 echo "Switching work tree to refs/heads/master" \
1492 >> $testroot/stdout.expected
1494 cmp -s $testroot/stdout.expected $testroot/stdout
1495 ret=$?
1496 if [ $ret -ne 0 ]; then
1497 diff -u $testroot/stdout.expected $testroot/stdout
1498 test_done "$testroot" "$ret"
1499 return 1
1502 if [ -e $testroot/wt/epsilon/psi ]; then
1503 echo "removed file psi still exists on disk" >&2
1504 test_done "$testroot" "1"
1505 return 1
1508 (cd $testroot/wt && got status > $testroot/stdout)
1510 echo -n > $testroot/stdout.expected
1511 cmp -s $testroot/stdout.expected $testroot/stdout
1512 ret=$?
1513 if [ $ret -ne 0 ]; then
1514 diff -u $testroot/stdout.expected $testroot/stdout
1515 test_done "$testroot" "$ret"
1516 return 1
1519 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1520 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1521 cmp -s $testroot/stdout.expected $testroot/stdout
1522 ret=$?
1523 if [ $ret -ne 0 ]; then
1524 diff -u $testroot/stdout.expected $testroot/stdout
1525 test_done "$testroot" "$ret"
1526 return 1
1529 got tree -r $testroot/repo epsilon > $testroot/stdout
1530 echo "zeta" > $testroot/stdout.expected
1531 cmp -s $testroot/stdout.expected $testroot/stdout
1532 ret=$?
1533 if [ $ret -ne 0 ]; then
1534 diff -u $testroot/stdout.expected $testroot/stdout
1536 test_done "$testroot" "$ret"
1539 test_histedit_fold_only() {
1540 local testroot=`test_init histedit_fold_only`
1542 local orig_commit=`git_show_head $testroot/repo`
1544 echo "modified alpha on master" > $testroot/repo/alpha
1545 (cd $testroot/repo && git rm -q beta)
1546 echo "new file on master" > $testroot/repo/epsilon/new
1547 (cd $testroot/repo && git add epsilon/new)
1548 git_commit $testroot/repo -m "committing changes"
1549 local old_commit1=`git_show_head $testroot/repo`
1551 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1552 git_commit $testroot/repo -m "committing to zeta on master"
1553 local old_commit2=`git_show_head $testroot/repo`
1555 echo "modified delta on master" > $testroot/repo/gamma/delta
1556 git_commit $testroot/repo -m "committing to delta on master"
1557 local old_commit3=`git_show_head $testroot/repo`
1559 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1560 ret=$?
1561 if [ $ret -ne 0 ]; then
1562 test_done "$testroot" "$ret"
1563 return 1
1566 cat > $testroot/editor.sh <<EOF
1567 #!/bin/sh
1568 sed -i 's/.*/committing folded changes/' "\$1"
1569 EOF
1570 chmod +x $testroot/editor.sh
1572 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1573 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1575 local new_commit1=`git_show_head $testroot/repo`
1577 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1578 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1579 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1580 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1581 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1583 echo "G alpha" > $testroot/stdout.expected
1584 echo "D beta" >> $testroot/stdout.expected
1585 echo "A epsilon/new" >> $testroot/stdout.expected
1586 echo "$short_old_commit1 -> fold commit: committing changes" \
1587 >> $testroot/stdout.expected
1588 echo "G epsilon/zeta" >> $testroot/stdout.expected
1589 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1590 echo "fold commit: committing to zeta on master" \
1591 >> $testroot/stdout.expected
1592 echo "G gamma/delta" >> $testroot/stdout.expected
1593 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1594 >> $testroot/stdout.expected
1595 echo "committing folded changes" >> $testroot/stdout.expected
1596 echo "Switching work tree to refs/heads/master" \
1597 >> $testroot/stdout.expected
1599 cmp -s $testroot/stdout.expected $testroot/stdout
1600 ret=$?
1601 if [ $ret -ne 0 ]; then
1602 diff -u $testroot/stdout.expected $testroot/stdout
1603 test_done "$testroot" "$ret"
1604 return 1
1607 echo "modified alpha on master" > $testroot/content.expected
1608 cat $testroot/wt/alpha > $testroot/content
1609 cmp -s $testroot/content.expected $testroot/content
1610 ret=$?
1611 if [ $ret -ne 0 ]; then
1612 diff -u $testroot/content.expected $testroot/content
1613 test_done "$testroot" "$ret"
1614 return 1
1617 if [ -e $testroot/wt/beta ]; then
1618 echo "removed file beta still exists on disk" >&2
1619 test_done "$testroot" "1"
1620 return 1
1623 echo "new file on master" > $testroot/content.expected
1624 cat $testroot/wt/epsilon/new > $testroot/content
1625 cmp -s $testroot/content.expected $testroot/content
1626 ret=$?
1627 if [ $ret -ne 0 ]; then
1628 diff -u $testroot/content.expected $testroot/content
1629 test_done "$testroot" "$ret"
1630 return 1
1633 (cd $testroot/wt && got status > $testroot/stdout)
1635 echo -n > $testroot/stdout.expected
1636 cmp -s $testroot/stdout.expected $testroot/stdout
1637 ret=$?
1638 if [ $ret -ne 0 ]; then
1639 diff -u $testroot/stdout.expected $testroot/stdout
1640 test_done "$testroot" "$ret"
1641 return 1
1644 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1645 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1646 echo "commit $orig_commit" >> $testroot/stdout.expected
1647 cmp -s $testroot/stdout.expected $testroot/stdout
1648 ret=$?
1649 if [ $ret -ne 0 ]; then
1650 diff -u $testroot/stdout.expected $testroot/stdout
1652 test_done "$testroot" "$ret"
1655 test_histedit_fold_only_empty_logmsg() {
1656 local testroot=`test_init histedit_fold_only_empty_logmsg`
1658 local orig_commit=`git_show_head $testroot/repo`
1660 echo "modified alpha on master" > $testroot/repo/alpha
1661 (cd $testroot/repo && git rm -q beta)
1662 echo "new file on master" > $testroot/repo/epsilon/new
1663 (cd $testroot/repo && git add epsilon/new)
1664 git_commit $testroot/repo -m "committing changes"
1665 local old_commit1=`git_show_head $testroot/repo`
1667 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1668 git_commit $testroot/repo -m "committing to zeta on master"
1669 local old_commit2=`git_show_head $testroot/repo`
1671 echo "modified delta on master" > $testroot/repo/gamma/delta
1672 git_commit $testroot/repo -m "committing to delta on master"
1673 local old_commit3=`git_show_head $testroot/repo`
1675 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1676 ret=$?
1677 if [ $ret -ne 0 ]; then
1678 test_done "$testroot" "$ret"
1679 return 1
1682 cat > $testroot/editor.sh <<EOF
1683 #!/bin/sh
1684 sed -i 'd' "\$1"
1685 EOF
1686 chmod +x $testroot/editor.sh
1688 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1689 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1691 local new_commit1=`git_show_head $testroot/repo`
1693 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1694 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1695 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1696 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1697 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1698 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1700 echo "G alpha" > $testroot/stdout.expected
1701 echo "D beta" >> $testroot/stdout.expected
1702 echo "A epsilon/new" >> $testroot/stdout.expected
1703 echo "$short_old_commit1 -> fold commit: committing changes" \
1704 >> $testroot/stdout.expected
1705 echo "G epsilon/zeta" >> $testroot/stdout.expected
1706 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1707 echo "fold commit: committing to zeta on master" \
1708 >> $testroot/stdout.expected
1709 echo "G gamma/delta" >> $testroot/stdout.expected
1710 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1711 >> $testroot/stdout.expected
1712 echo "# log message of folded commit $very_short_old_commit1" \
1713 >> $testroot/stdout.expected
1714 echo "Switching work tree to refs/heads/master" \
1715 >> $testroot/stdout.expected
1717 cmp -s $testroot/stdout.expected $testroot/stdout
1718 ret=$?
1719 if [ $ret -ne 0 ]; then
1720 diff -u $testroot/stdout.expected $testroot/stdout
1721 test_done "$testroot" "$ret"
1722 return 1
1725 echo "modified alpha on master" > $testroot/content.expected
1726 cat $testroot/wt/alpha > $testroot/content
1727 cmp -s $testroot/content.expected $testroot/content
1728 ret=$?
1729 if [ $ret -ne 0 ]; then
1730 diff -u $testroot/content.expected $testroot/content
1731 test_done "$testroot" "$ret"
1732 return 1
1735 if [ -e $testroot/wt/beta ]; then
1736 echo "removed file beta still exists on disk" >&2
1737 test_done "$testroot" "1"
1738 return 1
1741 echo "new file on master" > $testroot/content.expected
1742 cat $testroot/wt/epsilon/new > $testroot/content
1743 cmp -s $testroot/content.expected $testroot/content
1744 ret=$?
1745 if [ $ret -ne 0 ]; then
1746 diff -u $testroot/content.expected $testroot/content
1747 test_done "$testroot" "$ret"
1748 return 1
1751 (cd $testroot/wt && got status > $testroot/stdout)
1753 echo -n > $testroot/stdout.expected
1754 cmp -s $testroot/stdout.expected $testroot/stdout
1755 ret=$?
1756 if [ $ret -ne 0 ]; then
1757 diff -u $testroot/stdout.expected $testroot/stdout
1758 test_done "$testroot" "$ret"
1759 return 1
1762 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1763 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1764 echo "commit $orig_commit" >> $testroot/stdout.expected
1765 cmp -s $testroot/stdout.expected $testroot/stdout
1766 ret=$?
1767 if [ $ret -ne 0 ]; then
1768 diff -u $testroot/stdout.expected $testroot/stdout
1770 test_done "$testroot" "$ret"
1773 test_histedit_edit_only() {
1774 local testroot=`test_init histedit_edit_only`
1776 local orig_commit=`git_show_head $testroot/repo`
1778 echo "modified alpha on master" > $testroot/repo/alpha
1779 (cd $testroot/repo && git rm -q beta)
1780 echo "new file on master" > $testroot/repo/epsilon/new
1781 (cd $testroot/repo && git add epsilon/new)
1782 git_commit $testroot/repo -m "committing changes"
1783 local old_commit1=`git_show_head $testroot/repo`
1785 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1786 git_commit $testroot/repo -m "committing to zeta on master"
1787 local old_commit2=`git_show_head $testroot/repo`
1789 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1790 ret=$?
1791 if [ $ret -ne 0 ]; then
1792 test_done "$testroot" "$ret"
1793 return 1
1796 (cd $testroot/wt && got histedit -e > $testroot/stdout)
1798 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1799 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1801 echo "G alpha" > $testroot/stdout.expected
1802 echo "D beta" >> $testroot/stdout.expected
1803 echo "A epsilon/new" >> $testroot/stdout.expected
1804 echo "Stopping histedit for amending commit $old_commit1" \
1805 >> $testroot/stdout.expected
1806 cmp -s $testroot/stdout.expected $testroot/stdout
1807 ret=$?
1808 if [ $ret -ne 0 ]; then
1809 diff -u $testroot/stdout.expected $testroot/stdout
1810 test_done "$testroot" "$ret"
1811 return 1
1814 echo "edited modified alpha on master" > $testroot/wt/alpha
1816 cat > $testroot/editor.sh <<EOF
1817 #!/bin/sh
1818 sed -i 's/.*/committing edited changes 1/' "\$1"
1819 EOF
1820 chmod +x $testroot/editor.sh
1822 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1823 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1825 local new_commit1=$(cd $testroot/wt && got info | \
1826 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1827 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1829 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1830 > $testroot/stdout.expected
1831 echo "committing edited changes 1" >> $testroot/stdout.expected
1832 echo "G epsilon/zeta" >> $testroot/stdout.expected
1833 echo "Stopping histedit for amending commit $old_commit2" \
1834 >> $testroot/stdout.expected
1835 cmp -s $testroot/stdout.expected $testroot/stdout
1836 ret=$?
1837 if [ $ret -ne 0 ]; then
1838 diff -u $testroot/stdout.expected $testroot/stdout
1839 test_done "$testroot" "$ret"
1840 return 1
1843 echo "edited zeta on master" > $testroot/wt/epsilon/zeta
1845 cat > $testroot/editor.sh <<EOF
1846 #!/bin/sh
1847 sed -i 's/.*/committing edited changes 2/' "\$1"
1848 EOF
1849 chmod +x $testroot/editor.sh
1851 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1852 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1854 local new_commit2=`git_show_head $testroot/repo`
1855 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1857 echo -n "$short_old_commit2 -> $short_new_commit2: " \
1858 > $testroot/stdout.expected
1859 echo "committing edited changes 2" >> $testroot/stdout.expected
1860 echo "Switching work tree to refs/heads/master" \
1861 >> $testroot/stdout.expected
1863 cmp -s $testroot/stdout.expected $testroot/stdout
1864 ret=$?
1865 if [ $ret -ne 0 ]; then
1866 diff -u $testroot/stdout.expected $testroot/stdout
1867 test_done "$testroot" "$ret"
1868 return 1
1871 echo "edited modified alpha on master" > $testroot/content.expected
1872 cat $testroot/wt/alpha > $testroot/content
1873 cmp -s $testroot/content.expected $testroot/content
1874 ret=$?
1875 if [ $ret -ne 0 ]; then
1876 diff -u $testroot/content.expected $testroot/content
1877 test_done "$testroot" "$ret"
1878 return 1
1881 if [ -e $testroot/wt/beta ]; then
1882 echo "removed file beta still exists on disk" >&2
1883 test_done "$testroot" "1"
1884 return 1
1887 echo "new file on master" > $testroot/content.expected
1888 cat $testroot/wt/epsilon/new > $testroot/content
1889 cmp -s $testroot/content.expected $testroot/content
1890 ret=$?
1891 if [ $ret -ne 0 ]; then
1892 diff -u $testroot/content.expected $testroot/content
1893 test_done "$testroot" "$ret"
1894 return 1
1897 (cd $testroot/wt && got status > $testroot/stdout)
1899 echo -n > $testroot/stdout.expected
1900 cmp -s $testroot/stdout.expected $testroot/stdout
1901 ret=$?
1902 if [ $ret -ne 0 ]; then
1903 diff -u $testroot/stdout.expected $testroot/stdout
1904 test_done "$testroot" "$ret"
1905 return 1
1908 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1909 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
1910 echo "commit $new_commit1" >> $testroot/stdout.expected
1911 echo "commit $orig_commit" >> $testroot/stdout.expected
1912 cmp -s $testroot/stdout.expected $testroot/stdout
1913 ret=$?
1914 if [ $ret -ne 0 ]; then
1915 diff -u $testroot/stdout.expected $testroot/stdout
1917 test_done "$testroot" "$ret"
1920 test_histedit_prepend_line() {
1921 local testroot=`test_init histedit_prepend_line`
1922 local orig_commit=`git_show_head $testroot/repo`
1924 got checkout $testroot/repo $testroot/wt > /dev/null
1926 ed "$testroot/wt/alpha" <<EOF >/dev/null 2>&1
1928 first line
1931 EOF
1933 cp $testroot/wt/alpha $testroot/content.expected
1935 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
1936 alpha > /dev/null)
1937 ret=$?
1938 if [ "$?" != 0 ]; then
1939 echo "got commit failed unexpectedly" >&2
1940 test_done "$testroot" "$ret"
1941 return 1
1944 local top_commit=`git_show_head $testroot/repo`
1945 echo "pick $top_commit" > "$testroot/histedit-script"
1947 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
1948 ret=$?
1949 if [ "$?" != 0 ]; then
1950 echo "got update failed unexpectedly" >&2
1951 test_done "$testroot" "$ret"
1952 return 1
1955 (cd $testroot/wt && got histedit -F "$testroot/histedit-script" \
1956 > /dev/null)
1957 ret=$?
1958 if [ "$?" != 0 ]; then
1959 echo "got histedit failed unexpectedly" >&2
1960 test_done "$testroot" "$ret"
1961 return 1
1964 cp $testroot/wt/alpha $testroot/content
1965 cmp -s $testroot/content.expected $testroot/content
1966 ret=$?
1967 if [ $ret -ne 0 ]; then
1968 diff -u $testroot/content.expected $testroot/content
1969 test_done "$testroot" "$ret"
1970 return 1
1973 test_done "$testroot" $ret
1976 test_parseargs "$@"
1977 run_test test_histedit_no_op
1978 run_test test_histedit_swap
1979 run_test test_histedit_drop
1980 run_test test_histedit_fold
1981 run_test test_histedit_edit
1982 run_test test_histedit_fold_last_commit
1983 run_test test_histedit_missing_commit
1984 run_test test_histedit_abort
1985 run_test test_histedit_path_prefix_drop
1986 run_test test_histedit_path_prefix_edit
1987 run_test test_histedit_outside_refs_heads
1988 run_test test_histedit_fold_last_commit_swap
1989 run_test test_histedit_split_commit
1990 run_test test_histedit_duplicate_commit_in_script
1991 run_test test_histedit_fold_add_delete
1992 run_test test_histedit_fold_only
1993 run_test test_histedit_fold_only_empty_logmsg
1994 run_test test_histedit_edit_only
1995 run_test test_histedit_prepend_line