]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3511-cherry-pick-x.sh
pretty: add %D format specifier
[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
5. ./test-lib.sh
6
7pristine_detach () {
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
12}
13
14mesg_one_line='base: commit message'
15
16mesg_no_footer="$mesg_one_line
17
18OneWordBodyThatsNotA-S-o-B"
19
20mesg_with_footer="$mesg_no_footer
21
22Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
23Signed-off-by: A.U. Thor <author@example.com>
24Signed-off-by: B.U. Thor <buthor@example.com>"
25
26mesg_broken_footer="$mesg_no_footer
27
28The signed-off-by string should begin with the words Signed-off-by followed
29by a colon and space, and then the signers name and email address. e.g.
30Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
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
f2b9a755
BC
39
40test_expect_success setup '
41 git config advice.detachedhead false &&
42 echo unrelated >unrelated &&
43 git add unrelated &&
44 test_commit initial foo a &&
45 test_commit "$mesg_one_line" foo b mesg-one-line &&
46 git reset --hard initial &&
47 test_commit "$mesg_no_footer" foo b mesg-no-footer &&
48 git reset --hard initial &&
49 test_commit "$mesg_broken_footer" foo b mesg-broken-footer &&
50 git reset --hard initial &&
51 test_commit "$mesg_with_footer" foo b mesg-with-footer &&
52 git reset --hard initial &&
53 test_commit "$mesg_with_footer_sob" foo b mesg-with-footer-sob &&
cd650a4e
BC
54 git reset --hard initial &&
55 test_commit "$mesg_with_cherry_footer" foo b mesg-with-cherry-footer &&
f2b9a755
BC
56 pristine_detach initial &&
57 test_commit conflicting unrelated
58'
59
b971e04f
BC
60test_expect_success 'cherry-pick -x inserts blank line after one line subject' '
61 pristine_detach initial &&
62 sha1=`git rev-parse mesg-one-line^0` &&
63 git cherry-pick -x mesg-one-line &&
64 cat <<-EOF >expect &&
65 $mesg_one_line
66
67 (cherry picked from commit $sha1)
68 EOF
69 git log -1 --pretty=format:%B >actual &&
70 test_cmp expect actual
71'
72
f2b9a755
BC
73test_expect_success 'cherry-pick -s inserts blank line after one line subject' '
74 pristine_detach initial &&
75 git cherry-pick -s mesg-one-line &&
76 cat <<-EOF >expect &&
77 $mesg_one_line
78
79 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
80 EOF
81 git log -1 --pretty=format:%B >actual &&
82 test_cmp expect actual
83'
84
bab4d109 85test_expect_success 'cherry-pick -s inserts blank line after non-conforming footer' '
f2b9a755
BC
86 pristine_detach initial &&
87 git cherry-pick -s mesg-broken-footer &&
88 cat <<-EOF >expect &&
89 $mesg_broken_footer
90
91 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
92 EOF
93 git log -1 --pretty=format:%B >actual &&
94 test_cmp expect actual
95'
96
b971e04f
BC
97test_expect_success 'cherry-pick -x inserts blank line when conforming footer not found' '
98 pristine_detach initial &&
99 sha1=`git rev-parse mesg-no-footer^0` &&
100 git cherry-pick -x mesg-no-footer &&
101 cat <<-EOF >expect &&
102 $mesg_no_footer
103
104 (cherry picked from commit $sha1)
105 EOF
106 git log -1 --pretty=format:%B >actual &&
107 test_cmp expect actual
108'
109
f2b9a755
BC
110test_expect_success 'cherry-pick -s inserts blank line when conforming footer not found' '
111 pristine_detach initial &&
112 git cherry-pick -s mesg-no-footer &&
113 cat <<-EOF >expect &&
114 $mesg_no_footer
115
116 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
117 EOF
118 git log -1 --pretty=format:%B >actual &&
119 test_cmp expect actual
120'
121
b971e04f
BC
122test_expect_success 'cherry-pick -x -s inserts blank line when conforming footer not found' '
123 pristine_detach initial &&
124 sha1=`git rev-parse mesg-no-footer^0` &&
125 git cherry-pick -x -s mesg-no-footer &&
126 cat <<-EOF >expect &&
127 $mesg_no_footer
128
129 (cherry picked from commit $sha1)
130 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
131 EOF
132 git log -1 --pretty=format:%B >actual &&
133 test_cmp expect actual
134'
135
f2b9a755
BC
136test_expect_success 'cherry-pick -s adds sob when last sob doesnt match committer' '
137 pristine_detach initial &&
138 git cherry-pick -s mesg-with-footer &&
139 cat <<-EOF >expect &&
140 $mesg_with_footer
141 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
142 EOF
143 git log -1 --pretty=format:%B >actual &&
144 test_cmp expect actual
145'
146
cd650a4e
BC
147test_expect_success 'cherry-pick -x -s adds sob when last sob doesnt match committer' '
148 pristine_detach initial &&
149 sha1=`git rev-parse mesg-with-footer^0` &&
150 git cherry-pick -x -s mesg-with-footer &&
151 cat <<-EOF >expect &&
152 $mesg_with_footer
153 (cherry picked from commit $sha1)
154 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
155 EOF
156 git log -1 --pretty=format:%B >actual &&
157 test_cmp expect actual
158'
159
f2b9a755
BC
160test_expect_success 'cherry-pick -s refrains from adding duplicate trailing sob' '
161 pristine_detach initial &&
162 git cherry-pick -s mesg-with-footer-sob &&
163 cat <<-EOF >expect &&
164 $mesg_with_footer_sob
165 EOF
166 git log -1 --pretty=format:%B >actual &&
167 test_cmp expect actual
168'
169
cd650a4e
BC
170test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists for committer' '
171 pristine_detach initial &&
172 sha1=`git rev-parse mesg-with-footer-sob^0` &&
173 git cherry-pick -x -s mesg-with-footer-sob &&
174 cat <<-EOF >expect &&
175 $mesg_with_footer_sob
176 (cherry picked from commit $sha1)
177 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
178 EOF
179 git log -1 --pretty=format:%B >actual &&
180 test_cmp expect actual
181'
182
183test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
184 pristine_detach initial &&
185 sha1=`git rev-parse mesg-with-cherry-footer^0` &&
186 git cherry-pick -x mesg-with-cherry-footer &&
187 cat <<-EOF >expect &&
188 $mesg_with_cherry_footer
189 (cherry picked from commit $sha1)
190 EOF
191 git log -1 --pretty=format:%B >actual &&
192 test_cmp expect actual
193'
194
195test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part of footer' '
196 pristine_detach initial &&
197 git cherry-pick -s mesg-with-cherry-footer &&
198 cat <<-EOF >expect &&
199 $mesg_with_cherry_footer
200 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
201 EOF
202 git log -1 --pretty=format:%B >actual &&
203 test_cmp expect actual
204'
205
b971e04f
BC
206test_expect_success 'cherry-pick -x -s treats "(cherry picked from..." line as part of footer' '
207 pristine_detach initial &&
208 sha1=`git rev-parse mesg-with-cherry-footer^0` &&
209 git cherry-pick -x -s mesg-with-cherry-footer &&
210 cat <<-EOF >expect &&
211 $mesg_with_cherry_footer
212 (cherry picked from commit $sha1)
213 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
214 EOF
215 git log -1 --pretty=format:%B >actual &&
216 test_cmp expect actual
217'
218
f2b9a755 219test_done