3 test_description
='Run "stg squash"'
7 test_expect_success
'Initialize StGit stack' '
8 test_commit_bulk --start=0 --filename=foo.txt --contents="foo %s" --message="p%s" 6 &&
11 for i in 0 1 2 3 4 5; do
12 git notes add -m "note$i" $(stg id p$i)
16 test_expect_success
'Too few arguments' '
17 command_error stg squash p0 2>err &&
18 grep -e "Need at least two patches" err
21 test_expect_success
'Attempt duplicate patch name' '
22 command_error stg squash -n p3 -- p0 p1 2>err &&
23 grep -e "Patch name \"p3\" already taken" err
26 test_expect_success
'Attempt invalid patch name' '
27 command_error stg squash -n invalid..name -- p0 p1 2>err &&
28 grep -e "Patch name \"invalid..name\" is invalid" err
31 test_expect_success
'Attempt out of order' '
32 conflict stg squash --name=q4 p5 p4 &&
36 test_expect_success
'Squash out of order no conflict' '
37 echo hello > bar.txt &&
39 stg new -m bar-patch &&
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 &&
48 stg new -m baz-patch &&
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
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>err &&
84 grep -e "Aborting squash due to empty commit message" err &&
85 test "$(echo $(stg series))" = "+ p0 > q1"
90 echo "Editor was invoked" | tee editor-invoked
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