]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3511-cherry-pick-x.sh
The third batch
[thirdparty/git.git] / t / t3511-cherry-pick-x.sh
1 #!/bin/sh
2
3 test_description='Test cherry-pick -x and -s'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 pristine_detach () {
9 git cherry-pick --quit &&
10 git checkout -f "$1^0" &&
11 git read-tree -u --reset HEAD &&
12 git clean -d -f -f -q -x
13 }
14
15 mesg_one_line='base: commit message'
16
17 mesg_no_footer="$mesg_one_line
18
19 OneWordBodyThatsNotA-S-o-B"
20
21 mesg_with_footer="$mesg_no_footer
22
23 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
24 Signed-off-by: A.U. Thor <author@example.com>
25 Signed-off-by: B.U. Thor <buthor@example.com>"
26
27 mesg_broken_footer="$mesg_no_footer
28
29 This is not recognized as a footer because Myfooter is not a recognized token.
30 Myfooter: A.U. Thor <author@example.com>"
31
32 mesg_with_footer_sob="$mesg_with_footer
33 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
34
35 mesg_with_cherry_footer="$mesg_with_footer_sob
36 (cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
37 Tested-by: C.U. Thor <cuthor@example.com>"
38
39 mesg_unclean="$mesg_one_line
40
41
42 leading empty lines
43
44
45 consecutive empty lines
46
47 # hash tag comment
48
49 trailing empty lines
50
51
52 "
53
54 test_expect_success setup '
55 git config advice.detachedhead false &&
56 echo unrelated >unrelated &&
57 git add unrelated &&
58 test_commit initial foo a &&
59 test_commit "$mesg_one_line" foo b mesg-one-line &&
60 git reset --hard initial &&
61 test_commit "$mesg_no_footer" foo b mesg-no-footer &&
62 git reset --hard initial &&
63 test_commit "$mesg_broken_footer" foo b mesg-broken-footer &&
64 git reset --hard initial &&
65 test_commit "$mesg_with_footer" foo b mesg-with-footer &&
66 git reset --hard initial &&
67 test_commit "$mesg_with_footer_sob" foo b mesg-with-footer-sob &&
68 git reset --hard initial &&
69 test_commit "$mesg_with_cherry_footer" foo b mesg-with-cherry-footer &&
70 git reset --hard initial &&
71 test_config commit.cleanup verbatim &&
72 test_commit "$mesg_unclean" foo b mesg-unclean &&
73 test_unconfig commit.cleanup &&
74 pristine_detach initial &&
75 test_commit conflicting unrelated
76 '
77
78 test_expect_success 'cherry-pick -x inserts blank line after one line subject' '
79 pristine_detach initial &&
80 sha1=$(git rev-parse mesg-one-line^0) &&
81 git cherry-pick -x mesg-one-line &&
82 cat <<-EOF >expect &&
83 $mesg_one_line
84
85 (cherry picked from commit $sha1)
86 EOF
87 git log -1 --pretty=format:%B >actual &&
88 test_cmp expect actual
89 '
90
91 test_expect_success 'cherry-pick -s inserts blank line after one line subject' '
92 pristine_detach initial &&
93 git cherry-pick -s mesg-one-line &&
94 cat <<-EOF >expect &&
95 $mesg_one_line
96
97 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
98 EOF
99 git log -1 --pretty=format:%B >actual &&
100 test_cmp expect actual
101 '
102
103 test_expect_success 'cherry-pick -s inserts blank line after non-conforming footer' '
104 pristine_detach initial &&
105 git cherry-pick -s mesg-broken-footer &&
106 cat <<-EOF >expect &&
107 $mesg_broken_footer
108
109 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
110 EOF
111 git log -1 --pretty=format:%B >actual &&
112 test_cmp expect actual
113 '
114
115 test_expect_success 'cherry-pick -s recognizes trailer config' '
116 pristine_detach initial &&
117 git -c "trailer.Myfooter.ifexists=add" cherry-pick -s mesg-broken-footer &&
118 cat <<-EOF >expect &&
119 $mesg_broken_footer
120 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
121 EOF
122 git log -1 --pretty=format:%B >actual &&
123 test_cmp expect actual
124 '
125
126 test_expect_success 'cherry-pick -x inserts blank line when conforming footer not found' '
127 pristine_detach initial &&
128 sha1=$(git rev-parse mesg-no-footer^0) &&
129 git cherry-pick -x mesg-no-footer &&
130 cat <<-EOF >expect &&
131 $mesg_no_footer
132
133 (cherry picked from commit $sha1)
134 EOF
135 git log -1 --pretty=format:%B >actual &&
136 test_cmp expect actual
137 '
138
139 test_expect_success 'cherry-pick -s inserts blank line when conforming footer not found' '
140 pristine_detach initial &&
141 git cherry-pick -s mesg-no-footer &&
142 cat <<-EOF >expect &&
143 $mesg_no_footer
144
145 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
146 EOF
147 git log -1 --pretty=format:%B >actual &&
148 test_cmp expect actual
149 '
150
151 test_expect_success 'cherry-pick -x -s inserts blank line when conforming footer not found' '
152 pristine_detach initial &&
153 sha1=$(git rev-parse mesg-no-footer^0) &&
154 git cherry-pick -x -s mesg-no-footer &&
155 cat <<-EOF >expect &&
156 $mesg_no_footer
157
158 (cherry picked from commit $sha1)
159 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
160 EOF
161 git log -1 --pretty=format:%B >actual &&
162 test_cmp expect actual
163 '
164
165 test_expect_success 'cherry-pick -s adds sob when last sob doesnt match committer' '
166 pristine_detach initial &&
167 git cherry-pick -s mesg-with-footer &&
168 cat <<-EOF >expect &&
169 $mesg_with_footer
170 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
171 EOF
172 git log -1 --pretty=format:%B >actual &&
173 test_cmp expect actual
174 '
175
176 test_expect_success 'cherry-pick -x -s adds sob when last sob doesnt match committer' '
177 pristine_detach initial &&
178 sha1=$(git rev-parse mesg-with-footer^0) &&
179 git cherry-pick -x -s mesg-with-footer &&
180 cat <<-EOF >expect &&
181 $mesg_with_footer
182 (cherry picked from commit $sha1)
183 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
184 EOF
185 git log -1 --pretty=format:%B >actual &&
186 test_cmp expect actual
187 '
188
189 test_expect_success 'cherry-pick -s refrains from adding duplicate trailing sob' '
190 pristine_detach initial &&
191 git cherry-pick -s mesg-with-footer-sob &&
192 cat <<-EOF >expect &&
193 $mesg_with_footer_sob
194 EOF
195 git log -1 --pretty=format:%B >actual &&
196 test_cmp expect actual
197 '
198
199 test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists for committer' '
200 pristine_detach initial &&
201 sha1=$(git rev-parse mesg-with-footer-sob^0) &&
202 git cherry-pick -x -s mesg-with-footer-sob &&
203 cat <<-EOF >expect &&
204 $mesg_with_footer_sob
205 (cherry picked from commit $sha1)
206 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
207 EOF
208 git log -1 --pretty=format:%B >actual &&
209 test_cmp expect actual
210 '
211
212 test_expect_success 'cherry-pick -x handles commits with no NL at end of message' '
213 pristine_detach initial &&
214 printf "title\n\nSigned-off-by: A <a@example.com>" >msg &&
215 sha1=$(git commit-tree -p initial mesg-with-footer^{tree} <msg) &&
216 git cherry-pick -x $sha1 &&
217 git log -1 --pretty=format:%B >actual &&
218
219 printf "\n(cherry picked from commit %s)\n" $sha1 >>msg &&
220 test_cmp msg actual
221 '
222
223 test_expect_success 'cherry-pick -x handles commits with no footer and no NL at end of message' '
224 pristine_detach initial &&
225 printf "title\n\nnot a footer" >msg &&
226 sha1=$(git commit-tree -p initial mesg-with-footer^{tree} <msg) &&
227 git cherry-pick -x $sha1 &&
228 git log -1 --pretty=format:%B >actual &&
229
230 printf "\n\n(cherry picked from commit %s)\n" $sha1 >>msg &&
231 test_cmp msg actual
232 '
233
234 test_expect_success 'cherry-pick -s handles commits with no NL at end of message' '
235 pristine_detach initial &&
236 printf "title\n\nSigned-off-by: A <a@example.com>" >msg &&
237 sha1=$(git commit-tree -p initial mesg-with-footer^{tree} <msg) &&
238 git cherry-pick -s $sha1 &&
239 git log -1 --pretty=format:%B >actual &&
240
241 printf "\nSigned-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\n" >>msg &&
242 test_cmp msg actual
243 '
244
245 test_expect_success 'cherry-pick -s handles commits with no footer and no NL at end of message' '
246 pristine_detach initial &&
247 printf "title\n\nnot a footer" >msg &&
248 sha1=$(git commit-tree -p initial mesg-with-footer^{tree} <msg) &&
249 git cherry-pick -s $sha1 &&
250 git log -1 --pretty=format:%B >actual &&
251
252 printf "\n\nSigned-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\n" >>msg &&
253 test_cmp msg actual
254 '
255
256 test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
257 pristine_detach initial &&
258 sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
259 git cherry-pick -x mesg-with-cherry-footer &&
260 cat <<-EOF >expect &&
261 $mesg_with_cherry_footer
262 (cherry picked from commit $sha1)
263 EOF
264 git log -1 --pretty=format:%B >actual &&
265 test_cmp expect actual
266 '
267
268 test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part of footer' '
269 pristine_detach initial &&
270 git cherry-pick -s mesg-with-cherry-footer &&
271 cat <<-EOF >expect &&
272 $mesg_with_cherry_footer
273 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
274 EOF
275 git log -1 --pretty=format:%B >actual &&
276 test_cmp expect actual
277 '
278
279 test_expect_success 'cherry-pick -x -s treats "(cherry picked from..." line as part of footer' '
280 pristine_detach initial &&
281 sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
282 git cherry-pick -x -s mesg-with-cherry-footer &&
283 cat <<-EOF >expect &&
284 $mesg_with_cherry_footer
285 (cherry picked from commit $sha1)
286 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
287 EOF
288 git log -1 --pretty=format:%B >actual &&
289 test_cmp expect actual
290 '
291
292 test_expect_success 'cherry-pick preserves commit message' '
293 pristine_detach initial &&
294 printf "$mesg_unclean" >expect &&
295 git log -1 --pretty=format:%B mesg-unclean >actual &&
296 test_cmp expect actual &&
297 git cherry-pick mesg-unclean &&
298 git log -1 --pretty=format:%B >actual &&
299 test_cmp expect actual
300 '
301
302 test_expect_success 'cherry-pick -x cleans commit message' '
303 pristine_detach initial &&
304 git cherry-pick -x mesg-unclean &&
305 git log -1 --pretty=format:%B >actual &&
306 printf "%s\n(cherry picked from commit %s)\n" \
307 "$mesg_unclean" $(git rev-parse mesg-unclean) |
308 git stripspace >expect &&
309 test_cmp expect actual
310 '
311
312 test_expect_success 'cherry-pick -x respects commit.cleanup' '
313 pristine_detach initial &&
314 git -c commit.cleanup=strip cherry-pick -x mesg-unclean &&
315 git log -1 --pretty=format:%B >actual &&
316 printf "%s\n(cherry picked from commit %s)\n" \
317 "$mesg_unclean" $(git rev-parse mesg-unclean) |
318 git stripspace -s >expect &&
319 test_cmp expect actual
320 '
321
322 test_done