2 test_description
='Test picking commits'
7 'Initialize the repository' \
9 echo "hello" > a.txt &&
11 git commit -m "add a.txt" &&
13 git branch a-branch &&
14 git checkout a-branch &&
15 echo "world" >> a.txt &&
17 git commit --allow-empty-message -m "" &&
18 git rev-parse HEAD > empty-msg-hash.txt &&
19 echo "more" >> a.txt &&
21 git commit -m "more" &&
22 git rev-parse HEAD > more-msg-hash.txt &&
23 git commit -m "one" -m "two" -m "three" --allow-empty &&
24 git rev-parse HEAD > multi-line-msg-hash.txt &&
29 'Pick commit with empty message' \
31 stg pick "$(cat empty-msg-hash.txt)" &&
32 test "$(echo $(stg series --applied --noprefix))" = "patch"
36 'Pick commit with non-empty message' \
38 stg pick "$(cat more-msg-hash.txt)" &&
39 test "$(echo $(stg series --applied --noprefix))" = "patch more"
43 'Pick with expose commit with empty message' \
45 stg delete patch more &&
46 stg pick --expose "$(cat empty-msg-hash.txt)" &&
47 test "$(echo $(stg series --applied --noprefix))" = "patch" &&
48 test_when_finished rm -f pick-expected.txt pick-message.txt &&
51 "(imported from commit $(cat empty-msg-hash.txt))" \
52 > pick-expected.txt &&
53 git show --no-patch --pretty=format:%B > pick-message.txt &&
54 test_cmp pick-expected.txt pick-message.txt
58 'Pick with expose commit with non-empty message' \
60 stg pick --expose "$(cat more-msg-hash.txt)" &&
61 test "$(echo $(stg series --applied --noprefix))" = "patch more" &&
62 test_when_finished rm -f pick-expected.txt pick-message.txt &&
66 "(imported from commit $(cat more-msg-hash.txt))" \
67 > pick-expected.txt &&
68 git show --no-patch --pretty=format:%B > pick-message.txt &&
69 test_cmp pick-expected.txt pick-message.txt
73 'Pick with expose commit with multi-empty message' \
75 stg pick --expose "$(cat multi-line-msg-hash.txt)" &&
76 test "$(echo $(stg series --applied --noprefix))" = "patch more one" &&
77 test_when_finished rm -f pick-expected.txt pick-message.txt &&
85 "(imported from commit $(cat multi-line-msg-hash.txt))" \
86 > pick-expected.txt &&
87 git show --no-patch --pretty=format:%B > pick-message.txt &&
88 test_cmp pick-expected.txt pick-message.txt &&
89 stg delete patch more one
93 'Pick with expose custom format commit with empty message' \
95 test_config stgit.pick.expose-format %s%n%nPREFIX%n%bSUFFIX
96 stg pick --expose "$(cat empty-msg-hash.txt)" &&
97 test "$(echo $(stg series --applied --noprefix))" = "patch" &&
98 test_when_finished rm -f pick-expected.txt pick-message.txt &&
104 > pick-expected.txt &&
105 git show --no-patch --pretty=format:%B > pick-message.txt &&
106 test_cmp pick-expected.txt pick-message.txt
109 test_expect_success \
110 'Pick with expose custom format commit with non-empty message' \
112 test_config stgit.pick.expose-format %s%n%nPREFIX%n%bSUFFIX &&
113 stg pick --expose "$(cat more-msg-hash.txt)" &&
114 test "$(echo $(stg series --applied --noprefix))" = "patch more" &&
115 test_when_finished rm -f pick-expected.txt pick-message.txt &&
121 > pick-expected.txt &&
122 git show --no-patch --pretty=format:%B > pick-message.txt &&
123 test_cmp pick-expected.txt pick-message.txt
126 test_expect_success \
127 'Pick with expose custom format commit with multi-line message' \
129 test_config stgit.pick.expose-format %s%n%nPREFIX%n%bSUFFIX &&
130 stg pick --expose "$(cat multi-line-msg-hash.txt)" &&
131 test "$(echo $(stg series --applied --noprefix))" = "patch more one" &&
132 test_when_finished rm -f pick-expected.txt pick-message.txt &&
141 > pick-expected.txt &&
142 git show --no-patch --pretty=format:%B > pick-message.txt &&
143 test_cmp pick-expected.txt pick-message.txt