Restore `stg sink --nopush` capability
[stgit.git] / t / t2600-squash.sh
blob090566486b42ca1a0377eefa50ba5df6b813f594
1 #!/bin/sh
3 test_description='Run "stg squash"'
5 . ./test-lib.sh
7 test_expect_success 'Initialize StGit stack' '
8 test_commit_bulk --start=0 --filename=foo.txt --contents="foo %s" --message="p%s" 6 &&
9 stg init &&
10 stg uncommit -n 6 &&
11 for i in 0 1 2 3 4 5; do
12 git notes add -m "note$i" $(stg id p$i)
13 done
16 test_expect_success 'Too few arguments' '
17 command_error stg squash p0 2>&1 |
18 grep -e "Need at least two patches"
21 test_expect_success 'Attempt duplicate patch name' '
22 command_error stg squash -n p3 -- p0 p1 2>&1 |
23 grep -e "Patch name \"p3\" already taken"
26 test_expect_success 'Attempt invalid patch name' '
27 command_error stg squash -n invalid..name -- p0 p1 2>&1 |
28 grep -e "Patch name \"invalid..name\" is invalid"
31 test_expect_success 'Attempt out of order' '
32 conflict stg squash --name=q4 p5 p4 &&
33 stg undo --hard
36 test_expect_success 'Squash out of order no conflict' '
37 echo hello > bar.txt &&
38 stg add bar.txt &&
39 stg new -m bar-patch &&
40 stg refresh &&
41 stg squash -n q5 bar-patch p5 &&
42 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 q5" ]
45 test_expect_success 'Squash out of order no conflict no name' '
46 echo hello > baz.txt &&
47 stg add baz.txt &&
48 stg new -m baz-patch &&
49 stg refresh &&
50 stg squash -m q6 baz-patch q5 &&
51 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 q6" ]
54 test_expect_success 'Save template' '
55 stg squash --save-template mytemplate p1 p2 &&
56 test_path_is_file mytemplate &&
57 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 q6" ] &&
58 echo "squashed patch" > mytemplate &&
59 stg squash --file=mytemplate p1 p2 &&
60 [ "$(echo $(stg series --applied --noprefix))" = "p0 squashed-patch p3 p4 q6" ]
63 test_expect_success 'Squash some patches' '
64 stg squash --message="wee woo" p3 p4 q6 &&
65 [ "$(echo $(stg series --applied --noprefix))" = "p0 squashed-patch wee-woo" ] &&
66 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
69 test_expect_success 'Squash at stack top' '
70 stg squash --name=q1 --message="wee woo wham" squashed-patch wee-woo &&
71 [ "$(echo $(stg series --applied --noprefix))" = "p0 q1" ] &&
72 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
75 test_expect_success 'Setup fake editor' '
76 write_script fake-editor <<-\eof
77 echo "" >"$1"
78 eof
80 test_expect_success 'Empty commit message aborts the squash' '
81 test_set_editor "$(pwd)/fake-editor" &&
82 test_when_finished test_set_editor false &&
83 command_error stg squash --name=p0 p0 q1 2>&1 |
84 grep -e "Aborting squash due to empty commit message" &&
85 test "$(echo $(stg series))" = "+ p0 > q1"
88 cat > editor <<EOF
89 #!/bin/sh
90 echo "Editor was invoked" | tee editor-invoked
91 EOF
92 chmod a+x editor
93 test_expect_success 'Squash with top != head' '
94 echo blahonga >> foo.txt &&
95 git commit -a -m "a new commit" &&
96 EDITOR=./editor command_error stg squash --name=r0 p0 q1 &&
97 test "$(echo $(stg series))" = "+ p0 > q1" &&
98 test_path_is_missing editor-invoked
101 test_done