Repair crash when attempting to export empty patch
[stgit.git] / t / t2600-squash.sh
blobdd7da109184574b855b7f7a79798a26a5d9380cc
1 #!/bin/sh
3 test_description='Run "stg squash"'
5 . ./test-lib.sh
7 test_expect_success 'Initialize StGit stack' '
8 stg init &&
9 for i in 0 1 2 3; do
10 stg new p$i -m "foo $i" &&
11 git notes add -m note$i &&
12 echo "foo $i" >> foo.txt &&
13 stg add foo.txt &&
14 stg refresh
15 done
18 test_expect_success 'Too few arguments' '
19 command_error stg squash p0 2>&1 |
20 grep -e "Need at least two patches"
23 test_expect_success 'Attempt duplicate patch name' '
24 command_error stg squash -n p3 -- p0 p1 2>&1 |
25 grep -e "Patch name \"p3\" already taken"
28 test_expect_success 'Attempt invalid patch name' '
29 command_error stg squash -n invalid..name -- p0 p1 2>&1 |
30 grep -e "Patch name \"invalid..name\" is invalid"
33 test_expect_success 'Save template' '
34 stg squash --save-template mytemplate p0 p1 &&
35 test_path_is_file mytemplate &&
36 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3" ]
39 test_expect_success 'Squash some patches' '
40 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3" ] &&
41 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
42 stg squash --name=q0 --message="wee woo" p1 p2 &&
43 [ "$(echo $(stg series --applied --noprefix))" = "p0 q0 p3" ] &&
44 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
47 test_expect_success 'Squash at stack top' '
48 stg squash --name=q1 --message="wee woo wham" q0 p3 &&
49 [ "$(echo $(stg series --applied --noprefix))" = "p0 q1" ] &&
50 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
53 cat > editor <<EOF
54 #!/bin/sh
55 echo "Editor was invoked" | tee editor-invoked
56 EOF
57 chmod a+x editor
58 test_expect_success 'Squash with top != head' '
59 echo blahonga >> foo.txt &&
60 git commit -a -m "a new commit" &&
61 EDITOR=./editor command_error stg squash --name=r0 p0 q1 &&
62 test "$(echo $(stg series))" = "+ p0 > q1" &&
63 test_path_is_missing editor-invoked
66 test_done