3 test_description
='Test cherry-pick -x and -s'
8 git cherry-pick
--quit &&
9 git checkout
-f "$1^0" &&
10 git read-tree
-u --reset HEAD
&&
11 git clean
-d -f -f -q -x
14 mesg_one_line
='base: commit message'
16 mesg_no_footer
="$mesg_one_line
18 OneWordBodyThatsNotA-S-o-B"
20 mesg_with_footer
="$mesg_no_footer
22 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
23 Signed-off-by: A.U. Thor <author@example.com>
24 Signed-off-by: B.U. Thor <buthor@example.com>"
26 mesg_broken_footer
="$mesg_no_footer
28 This is not recognized as a footer because Myfooter is not a recognized token.
29 Myfooter: A.U. Thor <author@example.com>"
31 mesg_with_footer_sob
="$mesg_with_footer
32 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
34 mesg_with_cherry_footer
="$mesg_with_footer_sob
35 (cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
36 Tested-by: C.U. Thor <cuthor@example.com>"
38 mesg_unclean
="$mesg_one_line
44 consecutive empty lines
53 test_expect_success setup
'
54 git config advice.detachedhead false &&
55 echo unrelated >unrelated &&
57 test_commit initial foo a &&
58 test_commit "$mesg_one_line" foo b mesg-one-line &&
59 git reset --hard initial &&
60 test_commit "$mesg_no_footer" foo b mesg-no-footer &&
61 git reset --hard initial &&
62 test_commit "$mesg_broken_footer" foo b mesg-broken-footer &&
63 git reset --hard initial &&
64 test_commit "$mesg_with_footer" foo b mesg-with-footer &&
65 git reset --hard initial &&
66 test_commit "$mesg_with_footer_sob" foo b mesg-with-footer-sob &&
67 git reset --hard initial &&
68 test_commit "$mesg_with_cherry_footer" foo b mesg-with-cherry-footer &&
69 git reset --hard initial &&
70 test_config commit.cleanup verbatim &&
71 test_commit "$mesg_unclean" foo b mesg-unclean &&
72 test_unconfig commit.cleanup &&
73 pristine_detach initial &&
74 test_commit conflicting unrelated
77 test_expect_success
'cherry-pick -x inserts blank line after one line subject' '
78 pristine_detach initial &&
79 sha1=$(git rev-parse mesg-one-line^0) &&
80 git cherry-pick -x mesg-one-line &&
84 (cherry picked from commit $sha1)
86 git log -1 --pretty=format:%B >actual &&
87 test_cmp expect actual
90 test_expect_success
'cherry-pick -s inserts blank line after one line subject' '
91 pristine_detach initial &&
92 git cherry-pick -s mesg-one-line &&
96 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
98 git log -1 --pretty=format:%B >actual &&
99 test_cmp expect actual
102 test_expect_success
'cherry-pick -s inserts blank line after non-conforming footer' '
103 pristine_detach initial &&
104 git cherry-pick -s mesg-broken-footer &&
105 cat <<-EOF >expect &&
108 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
110 git log -1 --pretty=format:%B >actual &&
111 test_cmp expect actual
114 test_expect_success
'cherry-pick -s recognizes trailer config' '
115 pristine_detach initial &&
116 git -c "trailer.Myfooter.ifexists=add" cherry-pick -s mesg-broken-footer &&
117 cat <<-EOF >expect &&
119 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
121 git log -1 --pretty=format:%B >actual &&
122 test_cmp expect actual
125 test_expect_success
'cherry-pick -x inserts blank line when conforming footer not found' '
126 pristine_detach initial &&
127 sha1=$(git rev-parse mesg-no-footer^0) &&
128 git cherry-pick -x mesg-no-footer &&
129 cat <<-EOF >expect &&
132 (cherry picked from commit $sha1)
134 git log -1 --pretty=format:%B >actual &&
135 test_cmp expect actual
138 test_expect_success
'cherry-pick -s inserts blank line when conforming footer not found' '
139 pristine_detach initial &&
140 git cherry-pick -s mesg-no-footer &&
141 cat <<-EOF >expect &&
144 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
146 git log -1 --pretty=format:%B >actual &&
147 test_cmp expect actual
150 test_expect_success
'cherry-pick -x -s inserts blank line when conforming footer not found' '
151 pristine_detach initial &&
152 sha1=$(git rev-parse mesg-no-footer^0) &&
153 git cherry-pick -x -s mesg-no-footer &&
154 cat <<-EOF >expect &&
157 (cherry picked from commit $sha1)
158 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
160 git log -1 --pretty=format:%B >actual &&
161 test_cmp expect actual
164 test_expect_success
'cherry-pick -s adds sob when last sob doesnt match committer' '
165 pristine_detach initial &&
166 git cherry-pick -s mesg-with-footer &&
167 cat <<-EOF >expect &&
169 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
171 git log -1 --pretty=format:%B >actual &&
172 test_cmp expect actual
175 test_expect_success
'cherry-pick -x -s adds sob when last sob doesnt match committer' '
176 pristine_detach initial &&
177 sha1=$(git rev-parse mesg-with-footer^0) &&
178 git cherry-pick -x -s mesg-with-footer &&
179 cat <<-EOF >expect &&
181 (cherry picked from commit $sha1)
182 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
184 git log -1 --pretty=format:%B >actual &&
185 test_cmp expect actual
188 test_expect_success
'cherry-pick -s refrains from adding duplicate trailing sob' '
189 pristine_detach initial &&
190 git cherry-pick -s mesg-with-footer-sob &&
191 cat <<-EOF >expect &&
192 $mesg_with_footer_sob
194 git log -1 --pretty=format:%B >actual &&
195 test_cmp expect actual
198 test_expect_success
'cherry-pick -x -s adds sob even when trailing sob exists for committer' '
199 pristine_detach initial &&
200 sha1=$(git rev-parse mesg-with-footer-sob^0) &&
201 git cherry-pick -x -s mesg-with-footer-sob &&
202 cat <<-EOF >expect &&
203 $mesg_with_footer_sob
204 (cherry picked from commit $sha1)
205 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
207 git log -1 --pretty=format:%B >actual &&
208 test_cmp expect actual
211 test_expect_success
'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
212 pristine_detach initial &&
213 sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
214 git cherry-pick -x mesg-with-cherry-footer &&
215 cat <<-EOF >expect &&
216 $mesg_with_cherry_footer
217 (cherry picked from commit $sha1)
219 git log -1 --pretty=format:%B >actual &&
220 test_cmp expect actual
223 test_expect_success
'cherry-pick -s treats "(cherry picked from..." line as part of footer' '
224 pristine_detach initial &&
225 git cherry-pick -s mesg-with-cherry-footer &&
226 cat <<-EOF >expect &&
227 $mesg_with_cherry_footer
228 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
230 git log -1 --pretty=format:%B >actual &&
231 test_cmp expect actual
234 test_expect_success
'cherry-pick -x -s treats "(cherry picked from..." line as part of footer' '
235 pristine_detach initial &&
236 sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
237 git cherry-pick -x -s mesg-with-cherry-footer &&
238 cat <<-EOF >expect &&
239 $mesg_with_cherry_footer
240 (cherry picked from commit $sha1)
241 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
243 git log -1 --pretty=format:%B >actual &&
244 test_cmp expect actual
247 test_expect_success
'cherry-pick preserves commit message' '
248 pristine_detach initial &&
249 printf "$mesg_unclean" >expect &&
250 git log -1 --pretty=format:%B mesg-unclean >actual &&
251 test_cmp expect actual &&
252 git cherry-pick mesg-unclean &&
253 git log -1 --pretty=format:%B >actual &&
254 test_cmp expect actual