Restore `stg sink --nopush` capability
[stgit.git] / t / t3401-pick-commit.sh
blobb07dc5a84fbe8d74facc57aee707fc72b8ec0c89
1 #!/bin/sh
2 test_description='Test picking commits'
4 . ./test-lib.sh
6 test_expect_success \
7 'Initialize the repository' \
9 echo "hello" > a.txt &&
10 git add a.txt &&
11 git commit -m "add a.txt" &&
12 stg init &&
13 git branch a-branch &&
14 git checkout a-branch &&
15 echo "world" >> a.txt &&
16 git add a.txt &&
17 git commit --allow-empty-message -m "" &&
18 git rev-parse HEAD > empty-msg-hash.txt &&
19 echo "more" >> a.txt &&
20 git add 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 &&
25 git checkout master
28 test_expect_success \
29 'Pick commit with empty message' \
31 stg pick "$(cat empty-msg-hash.txt)" &&
32 test "$(echo $(stg series --applied --noprefix))" = "patch"
35 test_expect_success \
36 'Pick commit with non-empty message' \
38 stg pick "$(cat more-msg-hash.txt)" &&
39 test "$(echo $(stg series --applied --noprefix))" = "patch more"
42 test_expect_success \
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 &&
49 test_write_lines \
50 "" \
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
57 test_expect_success \
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 &&
63 test_write_lines \
64 "more" \
65 "" \
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
72 test_expect_success \
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 &&
78 test_write_lines \
79 "one" \
80 "" \
81 "two" \
82 "" \
83 "three" \
84 "" \
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
92 test_expect_success \
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 &&
99 test_write_lines \
100 "" \
101 "" \
102 "PREFIX" \
103 "SUFFIX" \
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 &&
116 test_write_lines \
117 "more" \
118 "" \
119 "PREFIX" \
120 "SUFFIX" \
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 &&
133 test_write_lines \
134 "one" \
135 "" \
136 "PREFIX" \
137 "two" \
138 "" \
139 "three" \
140 "SUFFIX" \
141 > pick-expected.txt &&
142 git show --no-patch --pretty=format:%B > pick-message.txt &&
143 test_cmp pick-expected.txt pick-message.txt
146 test_done