]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3511-cherry-pick-x.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t3511-cherry-pick-x.sh
CommitLineData
f2b9a755
BC
1#!/bin/sh
2
3test_description='Test cherry-pick -x and -s'
4
9ff2f060 5TEST_PASSES_SANITIZE_LEAK=true
f2b9a755
BC
6. ./test-lib.sh
7
8pristine_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
15mesg_one_line='base: commit message'
16
17mesg_no_footer="$mesg_one_line
18
19OneWordBodyThatsNotA-S-o-B"
20
21mesg_with_footer="$mesg_no_footer
22
23Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
24Signed-off-by: A.U. Thor <author@example.com>
25Signed-off-by: B.U. Thor <buthor@example.com>"
26
27mesg_broken_footer="$mesg_no_footer
28
967dfd4d
JT
29This is not recognized as a footer because Myfooter is not a recognized token.
30Myfooter: A.U. Thor <author@example.com>"
f2b9a755
BC
31
32mesg_with_footer_sob="$mesg_with_footer
33Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
34
cd650a4e
BC
35mesg_with_cherry_footer="$mesg_with_footer_sob
36(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
37Tested-by: C.U. Thor <cuthor@example.com>"
38
17d65f03
MG
39mesg_unclean="$mesg_one_line
40
41
42leading empty lines
43
44
45consecutive empty lines
46
47# hash tag comment
48
49trailing empty lines
50
51
52"
f2b9a755
BC
53
54test_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 &&
cd650a4e
BC
68 git reset --hard initial &&
69 test_commit "$mesg_with_cherry_footer" foo b mesg-with-cherry-footer &&
17d65f03
MG
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 &&
f2b9a755
BC
74 pristine_detach initial &&
75 test_commit conflicting unrelated
76'
77
b971e04f
BC
78test_expect_success 'cherry-pick -x inserts blank line after one line subject' '
79 pristine_detach initial &&
9b495089 80 sha1=$(git rev-parse mesg-one-line^0) &&
b971e04f
BC
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
f2b9a755
BC
91test_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
bab4d109 103test_expect_success 'cherry-pick -s inserts blank line after non-conforming footer' '
f2b9a755
BC
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 &&
967dfd4d
JT
112 test_cmp expect actual
113'
114
115test_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 &&
f2b9a755
BC
123 test_cmp expect actual
124'
125
b971e04f
BC
126test_expect_success 'cherry-pick -x inserts blank line when conforming footer not found' '
127 pristine_detach initial &&
9b495089 128 sha1=$(git rev-parse mesg-no-footer^0) &&
b971e04f
BC
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
f2b9a755
BC
139test_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
b971e04f
BC
151test_expect_success 'cherry-pick -x -s inserts blank line when conforming footer not found' '
152 pristine_detach initial &&
9b495089 153 sha1=$(git rev-parse mesg-no-footer^0) &&
b971e04f
BC
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
f2b9a755
BC
165test_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
cd650a4e
BC
176test_expect_success 'cherry-pick -x -s adds sob when last sob doesnt match committer' '
177 pristine_detach initial &&
9b495089 178 sha1=$(git rev-parse mesg-with-footer^0) &&
cd650a4e
BC
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
f2b9a755
BC
189test_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
cd650a4e
BC
199test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists for committer' '
200 pristine_detach initial &&
9b495089 201 sha1=$(git rev-parse mesg-with-footer-sob^0) &&
cd650a4e
BC
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
44dc738a
JT
212test_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
223test_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
234test_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
245test_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
cd650a4e
BC
256test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
257 pristine_detach initial &&
9b495089 258 sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
cd650a4e
BC
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
268test_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
b971e04f
BC
279test_expect_success 'cherry-pick -x -s treats "(cherry picked from..." line as part of footer' '
280 pristine_detach initial &&
9b495089 281 sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
b971e04f
BC
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
17d65f03
MG
292test_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
d74f3e58
PW
302test_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
312test_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
f2b9a755 322test_done