Merge branch 'nd/gc-aggressive'
[git/debian.git] / t / t3511-cherry-pick-x.sh
blobf97727975b880ae52394c6af11dde15b71ac6eb7
1 #!/bin/sh
3 test_description='Test cherry-pick -x and -s'
5 . ./test-lib.sh
7 pristine_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
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 The signed-off-by string should begin with the words Signed-off-by followed
29 by a colon and space, and then the signers name and email address. e.g.
30 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
32 mesg_with_footer_sob="$mesg_with_footer
33 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
35 mesg_with_cherry_footer="$mesg_with_footer_sob
36 (cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
37 Tested-by: C.U. Thor <cuthor@example.com>"
40 test_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 &&
54 git reset --hard initial &&
55 test_commit "$mesg_with_cherry_footer" foo b mesg-with-cherry-footer &&
56 pristine_detach initial &&
57 test_commit conflicting unrelated
60 test_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
67 (cherry picked from commit $sha1)
68 EOF
69 git log -1 --pretty=format:%B >actual &&
70 test_cmp expect actual
73 test_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
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
85 test_expect_success 'cherry-pick -s inserts blank line after non-conforming footer' '
86 pristine_detach initial &&
87 git cherry-pick -s mesg-broken-footer &&
88 cat <<-EOF >expect &&
89 $mesg_broken_footer
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
97 test_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
104 (cherry picked from commit $sha1)
106 git log -1 --pretty=format:%B >actual &&
107 test_cmp expect actual
110 test_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
116 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
118 git log -1 --pretty=format:%B >actual &&
119 test_cmp expect actual
122 test_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
129 (cherry picked from commit $sha1)
130 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
132 git log -1 --pretty=format:%B >actual &&
133 test_cmp expect actual
136 test_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>
143 git log -1 --pretty=format:%B >actual &&
144 test_cmp expect actual
147 test_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>
156 git log -1 --pretty=format:%B >actual &&
157 test_cmp expect actual
160 test_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
166 git log -1 --pretty=format:%B >actual &&
167 test_cmp expect actual
170 test_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>
179 git log -1 --pretty=format:%B >actual &&
180 test_cmp expect actual
183 test_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)
191 git log -1 --pretty=format:%B >actual &&
192 test_cmp expect actual
195 test_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>
202 git log -1 --pretty=format:%B >actual &&
203 test_cmp expect actual
206 test_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>
215 git log -1 --pretty=format:%B >actual &&
216 test_cmp expect actual
219 test_done