]>
Commit | Line | Data |
---|---|---|
36d56de6 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='test git rev-list --cherry-pick -- file' | |
4 | ||
1550bb6e | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
36d56de6 JS |
8 | . ./test-lib.sh |
9 | ||
59c8afdf | 10 | # A---B---D---F |
36d56de6 JS |
11 | # \ |
12 | # \ | |
e0b9c34f | 13 | # C---E |
36d56de6 JS |
14 | # |
15 | # B changes a file foo.c, adding a line of text. C changes foo.c as | |
16 | # well as bar.c, but the change in foo.c was identical to change B. | |
59c8afdf | 17 | # D and C change bar in the same way, E and F differently. |
36d56de6 JS |
18 | |
19 | test_expect_success setup ' | |
20 | echo Hallo > foo && | |
21 | git add foo && | |
22 | test_tick && | |
23 | git commit -m "A" && | |
24 | git tag A && | |
25 | git checkout -b branch && | |
26 | echo Bello > foo && | |
27 | echo Cello > bar && | |
28 | git add foo bar && | |
29 | test_tick && | |
30 | git commit -m "C" && | |
31 | git tag C && | |
e0b9c34f MG |
32 | echo Dello > bar && |
33 | git add bar && | |
34 | test_tick && | |
35 | git commit -m "E" && | |
36 | git tag E && | |
1550bb6e | 37 | git checkout main && |
36d56de6 JS |
38 | git checkout branch foo && |
39 | test_tick && | |
40 | git commit -m "B" && | |
e0b9c34f MG |
41 | git tag B && |
42 | echo Cello > bar && | |
43 | git add bar && | |
44 | test_tick && | |
45 | git commit -m "D" && | |
59c8afdf MG |
46 | git tag D && |
47 | echo Nello > bar && | |
48 | git add bar && | |
49 | test_tick && | |
50 | git commit -m "F" && | |
51 | git tag F | |
36d56de6 JS |
52 | ' |
53 | ||
f69c5018 TR |
54 | cat >expect <<EOF |
55 | <tags/B | |
56 | >tags/C | |
57 | EOF | |
58 | ||
59 | test_expect_success '--left-right' ' | |
60 | git rev-list --left-right B...C > actual && | |
34ae3b70 | 61 | git name-rev --annotate-stdin --name-only --refs="*tags/*" \ |
f69c5018 | 62 | < actual > actual.named && |
9c5b2fab | 63 | test_cmp expect actual.named |
f69c5018 TR |
64 | ' |
65 | ||
66 | test_expect_success '--count' ' | |
67 | git rev-list --count B...C > actual && | |
68 | test "$(cat actual)" = 2 | |
69 | ' | |
70 | ||
36d56de6 JS |
71 | test_expect_success '--cherry-pick foo comes up empty' ' |
72 | test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)" | |
73 | ' | |
74 | ||
e0b9c34f MG |
75 | cat >expect <<EOF |
76 | >tags/C | |
77 | EOF | |
78 | ||
36d56de6 | 79 | test_expect_success '--cherry-pick bar does not come up empty' ' |
e0b9c34f | 80 | git rev-list --left-right --cherry-pick B...C -- bar > actual && |
34ae3b70 | 81 | git name-rev --annotate-stdin --name-only --refs="*tags/*" \ |
e0b9c34f | 82 | < actual > actual.named && |
9c5b2fab | 83 | test_cmp expect actual.named |
e0b9c34f MG |
84 | ' |
85 | ||
86 | test_expect_success 'bar does not come up empty' ' | |
87 | git rev-list --left-right B...C -- bar > actual && | |
34ae3b70 | 88 | git name-rev --annotate-stdin --name-only --refs="*tags/*" \ |
e0b9c34f | 89 | < actual > actual.named && |
9c5b2fab | 90 | test_cmp expect actual.named |
e0b9c34f MG |
91 | ' |
92 | ||
93 | cat >expect <<EOF | |
59c8afdf | 94 | <tags/F |
e0b9c34f MG |
95 | >tags/E |
96 | EOF | |
97 | ||
98 | test_expect_success '--cherry-pick bar does not come up empty (II)' ' | |
59c8afdf | 99 | git rev-list --left-right --cherry-pick F...E -- bar > actual && |
34ae3b70 | 100 | git name-rev --annotate-stdin --name-only --refs="*tags/*" \ |
59c8afdf | 101 | < actual > actual.named && |
9c5b2fab | 102 | test_cmp expect actual.named |
59c8afdf MG |
103 | ' |
104 | ||
290be667 JK |
105 | test_expect_success 'name-rev multiple --refs combine inclusive' ' |
106 | git rev-list --left-right --cherry-pick F...E -- bar >actual && | |
34ae3b70 | 107 | git name-rev --annotate-stdin --name-only --refs="*tags/F" --refs="*tags/E" \ |
290be667 | 108 | <actual >actual.named && |
9c5b2fab | 109 | test_cmp expect actual.named |
290be667 JK |
110 | ' |
111 | ||
112 | cat >expect <<EOF | |
113 | <tags/F | |
114 | EOF | |
115 | ||
116 | test_expect_success 'name-rev --refs excludes non-matched patterns' ' | |
117 | git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect && | |
118 | git rev-list --left-right --cherry-pick F...E -- bar >actual && | |
34ae3b70 | 119 | git name-rev --annotate-stdin --name-only --refs="*tags/F" \ |
290be667 | 120 | <actual >actual.named && |
9c5b2fab | 121 | test_cmp expect actual.named |
290be667 JK |
122 | ' |
123 | ||
96415b49 JK |
124 | cat >expect <<EOF |
125 | <tags/F | |
126 | EOF | |
127 | ||
128 | test_expect_success 'name-rev --exclude excludes matched patterns' ' | |
129 | git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect && | |
130 | git rev-list --left-right --cherry-pick F...E -- bar >actual && | |
34ae3b70 | 131 | git name-rev --annotate-stdin --name-only --refs="*tags/*" --exclude="*E" \ |
96415b49 | 132 | <actual >actual.named && |
9c5b2fab | 133 | test_cmp expect actual.named |
96415b49 JK |
134 | ' |
135 | ||
290be667 JK |
136 | test_expect_success 'name-rev --no-refs clears the refs list' ' |
137 | git rev-list --left-right --cherry-pick F...E -- bar >expect && | |
34ae3b70 | 138 | git name-rev --annotate-stdin --name-only --refs="*tags/F" --refs="*tags/E" --no-refs --refs="*tags/G" \ |
290be667 | 139 | <expect >actual && |
9c5b2fab | 140 | test_cmp expect actual |
290be667 JK |
141 | ' |
142 | ||
59c8afdf | 143 | cat >expect <<EOF |
cb56e309 MG |
144 | +tags/F |
145 | =tags/D | |
146 | +tags/E | |
147 | =tags/C | |
148 | EOF | |
149 | ||
150 | test_expect_success '--cherry-mark' ' | |
151 | git rev-list --cherry-mark F...E -- bar > actual && | |
34ae3b70 | 152 | git name-rev --annotate-stdin --name-only --refs="*tags/*" \ |
cb56e309 | 153 | < actual > actual.named && |
9c5b2fab | 154 | test_cmp expect actual.named |
cb56e309 MG |
155 | ' |
156 | ||
157 | cat >expect <<EOF | |
158 | <tags/F | |
159 | =tags/D | |
160 | >tags/E | |
161 | =tags/C | |
162 | EOF | |
163 | ||
164 | test_expect_success '--cherry-mark --left-right' ' | |
165 | git rev-list --cherry-mark --left-right F...E -- bar > actual && | |
34ae3b70 | 166 | git name-rev --annotate-stdin --name-only --refs="*tags/*" \ |
cb56e309 | 167 | < actual > actual.named && |
9c5b2fab | 168 | test_cmp expect actual.named |
cb56e309 MG |
169 | ' |
170 | ||
171 | cat >expect <<EOF | |
59c8afdf MG |
172 | tags/E |
173 | EOF | |
174 | ||
175 | test_expect_success '--cherry-pick --right-only' ' | |
176 | git rev-list --cherry-pick --right-only F...E -- bar > actual && | |
34ae3b70 | 177 | git name-rev --annotate-stdin --name-only --refs="*tags/*" \ |
59c8afdf | 178 | < actual > actual.named && |
9c5b2fab | 179 | test_cmp expect actual.named |
59c8afdf MG |
180 | ' |
181 | ||
182 | test_expect_success '--cherry-pick --left-only' ' | |
183 | git rev-list --cherry-pick --left-only E...F -- bar > actual && | |
34ae3b70 | 184 | git name-rev --annotate-stdin --name-only --refs="*tags/*" \ |
e0b9c34f | 185 | < actual > actual.named && |
9c5b2fab | 186 | test_cmp expect actual.named |
36d56de6 JS |
187 | ' |
188 | ||
fe3b59e5 MG |
189 | cat >expect <<EOF |
190 | +tags/E | |
191 | =tags/C | |
192 | EOF | |
193 | ||
194 | test_expect_success '--cherry' ' | |
195 | git rev-list --cherry F...E -- bar > actual && | |
34ae3b70 | 196 | git name-rev --annotate-stdin --name-only --refs="*tags/*" \ |
fe3b59e5 | 197 | < actual > actual.named && |
9c5b2fab | 198 | test_cmp expect actual.named |
fe3b59e5 MG |
199 | ' |
200 | ||
b388e14b MG |
201 | cat >expect <<EOF |
202 | 1 1 | |
203 | EOF | |
204 | ||
205 | test_expect_success '--cherry --count' ' | |
206 | git rev-list --cherry --count F...E -- bar > actual && | |
9c5b2fab | 207 | test_cmp expect actual |
b388e14b MG |
208 | ' |
209 | ||
210 | cat >expect <<EOF | |
211 | 2 2 | |
212 | EOF | |
213 | ||
214 | test_expect_success '--cherry-mark --count' ' | |
215 | git rev-list --cherry-mark --count F...E -- bar > actual && | |
9c5b2fab | 216 | test_cmp expect actual |
b388e14b MG |
217 | ' |
218 | ||
219 | cat >expect <<EOF | |
220 | 1 1 2 | |
221 | EOF | |
222 | ||
223 | test_expect_success '--cherry-mark --left-right --count' ' | |
224 | git rev-list --cherry-mark --left-right --count F...E -- bar > actual && | |
9c5b2fab | 225 | test_cmp expect actual |
b388e14b MG |
226 | ' |
227 | ||
023756f4 JS |
228 | test_expect_success '--cherry-pick with independent, but identical branches' ' |
229 | git symbolic-ref HEAD refs/heads/independent && | |
230 | rm .git/index && | |
231 | echo Hallo > foo && | |
232 | git add foo && | |
233 | test_tick && | |
234 | git commit -m "independent" && | |
235 | echo Bello > foo && | |
236 | test_tick && | |
237 | git commit -m "independent, too" foo && | |
238 | test -z "$(git rev-list --left-right --cherry-pick \ | |
1550bb6e | 239 | HEAD...main -- foo)" |
023756f4 JS |
240 | ' |
241 | ||
f69c5018 TR |
242 | cat >expect <<EOF |
243 | 1 2 | |
244 | EOF | |
245 | ||
f69c5018 | 246 | test_expect_success '--count --left-right' ' |
e0b9c34f | 247 | git rev-list --count --left-right C...D > actual && |
f69c5018 TR |
248 | test_cmp expect actual |
249 | ' | |
250 | ||
c9e3a4e7 JK |
251 | test_expect_success '--cherry-pick with duplicates on each side' ' |
252 | git checkout -b dup-orig && | |
253 | test_commit dup-base && | |
254 | git revert dup-base && | |
255 | git cherry-pick dup-base && | |
256 | git checkout -b dup-side HEAD~3 && | |
257 | test_tick && | |
258 | git cherry-pick -3 dup-orig && | |
259 | git rev-list --cherry-pick dup-orig...dup-side >actual && | |
260 | test_must_be_empty actual | |
261 | ' | |
262 | ||
b3dfeebb KW |
263 | # Corrupt the object store deliberately to make sure |
264 | # the object is not even checked for its existence. | |
265 | remove_loose_object () { | |
266 | sha1="$(git rev-parse "$1")" && | |
267 | remainder=${sha1#??} && | |
268 | firsttwo=${sha1%$remainder} && | |
269 | rm .git/objects/$firsttwo/$remainder | |
270 | } | |
271 | ||
272 | test_expect_success '--cherry-pick avoids looking at full diffs' ' | |
273 | git checkout -b shy-diff && | |
274 | test_commit dont-look-at-me && | |
275 | echo Hello >dont-look-at-me.t && | |
276 | test_tick && | |
277 | git commit -m tip dont-look-at-me.t && | |
278 | git checkout -b mainline HEAD^ && | |
279 | test_commit to-cherry-pick && | |
280 | remove_loose_object shy-diff^:dont-look-at-me.t && | |
281 | git rev-list --cherry-pick ...shy-diff | |
282 | ' | |
283 | ||
36d56de6 | 284 | test_done |