Improve test coverage for stg pull
[stgit.git] / t / t2600-squash.sh
blob845e82c3c4cd65d426a4c752fa432a77baa047b8
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 test_expect_success 'Setup fake editor' '
54 write_script fake-editor <<-\eof
55 echo "" >"$1"
56 eof
58 test_expect_success 'Empty commit message aborts the squash' '
59 test_set_editor "$(pwd)/fake-editor" &&
60 test_when_finished test_set_editor false &&
61 command_error stg squash --name=p0 p0 q1 2>&1 |
62 grep -e "Aborting squash due to empty commit message" &&
63 test "$(echo $(stg series))" = "+ p0 > q1"
66 cat > editor <<EOF
67 #!/bin/sh
68 echo "Editor was invoked" | tee editor-invoked
69 EOF
70 chmod a+x editor
71 test_expect_success 'Squash with top != head' '
72 echo blahonga >> foo.txt &&
73 git commit -a -m "a new commit" &&
74 EDITOR=./editor command_error stg squash --name=r0 p0 q1 &&
75 test "$(echo $(stg series))" = "+ p0 > q1" &&
76 test_path_is_missing editor-invoked
79 test_done