blob: aebe4b69e13ea56444dc760cb1b6058702f2d241 [file] [log] [blame]
Johannes Schindelin36d56de2007-07-10 14:50:49 +01001#!/bin/sh
2
3test_description='test git rev-list --cherry-pick -- file'
4
Johannes Schindelin1550bb62020-11-18 23:44:36 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Johannes Schindelin36d56de2007-07-10 14:50:49 +01008. ./test-lib.sh
9
Michael J Gruber59c8afd2011-02-21 17:09:12 +010010# A---B---D---F
Johannes Schindelin36d56de2007-07-10 14:50:49 +010011# \
12# \
Michael J Grubere0b9c342011-02-18 13:34:19 +010013# C---E
Johannes Schindelin36d56de2007-07-10 14:50:49 +010014#
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.
Michael J Gruber59c8afd2011-02-21 17:09:12 +010017# D and C change bar in the same way, E and F differently.
Johannes Schindelin36d56de2007-07-10 14:50:49 +010018
19test_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 &&
Michael J Grubere0b9c342011-02-18 13:34:19 +010032 echo Dello > bar &&
33 git add bar &&
34 test_tick &&
35 git commit -m "E" &&
36 git tag E &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +000037 git checkout main &&
Johannes Schindelin36d56de2007-07-10 14:50:49 +010038 git checkout branch foo &&
39 test_tick &&
40 git commit -m "B" &&
Michael J Grubere0b9c342011-02-18 13:34:19 +010041 git tag B &&
42 echo Cello > bar &&
43 git add bar &&
44 test_tick &&
45 git commit -m "D" &&
Michael J Gruber59c8afd2011-02-21 17:09:12 +010046 git tag D &&
47 echo Nello > bar &&
48 git add bar &&
49 test_tick &&
50 git commit -m "F" &&
51 git tag F
Johannes Schindelin36d56de2007-07-10 14:50:49 +010052'
53
Thomas Rastf69c5012010-06-10 13:47:23 +020054cat >expect <<EOF
55<tags/B
56>tags/C
57EOF
58
59test_expect_success '--left-right' '
60 git rev-list --left-right B...C > actual &&
61 git name-rev --stdin --name-only --refs="*tags/*" \
62 < actual > actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -070063 test_cmp expect actual.named
Thomas Rastf69c5012010-06-10 13:47:23 +020064'
65
66test_expect_success '--count' '
67 git rev-list --count B...C > actual &&
68 test "$(cat actual)" = 2
69'
70
Johannes Schindelin36d56de2007-07-10 14:50:49 +010071test_expect_success '--cherry-pick foo comes up empty' '
72 test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)"
73'
74
Michael J Grubere0b9c342011-02-18 13:34:19 +010075cat >expect <<EOF
76>tags/C
77EOF
78
Johannes Schindelin36d56de2007-07-10 14:50:49 +010079test_expect_success '--cherry-pick bar does not come up empty' '
Michael J Grubere0b9c342011-02-18 13:34:19 +010080 git rev-list --left-right --cherry-pick B...C -- bar > actual &&
81 git name-rev --stdin --name-only --refs="*tags/*" \
82 < actual > actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -070083 test_cmp expect actual.named
Michael J Grubere0b9c342011-02-18 13:34:19 +010084'
85
86test_expect_success 'bar does not come up empty' '
87 git rev-list --left-right B...C -- bar > actual &&
88 git name-rev --stdin --name-only --refs="*tags/*" \
89 < actual > actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -070090 test_cmp expect actual.named
Michael J Grubere0b9c342011-02-18 13:34:19 +010091'
92
93cat >expect <<EOF
Michael J Gruber59c8afd2011-02-21 17:09:12 +010094<tags/F
Michael J Grubere0b9c342011-02-18 13:34:19 +010095>tags/E
96EOF
97
98test_expect_success '--cherry-pick bar does not come up empty (II)' '
Michael J Gruber59c8afd2011-02-21 17:09:12 +010099 git rev-list --left-right --cherry-pick F...E -- bar > actual &&
100 git name-rev --stdin --name-only --refs="*tags/*" \
101 < actual > actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700102 test_cmp expect actual.named
Michael J Gruber59c8afd2011-02-21 17:09:12 +0100103'
104
Jacob Keller290be662017-01-18 15:06:05 -0800105test_expect_success 'name-rev multiple --refs combine inclusive' '
106 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
107 git name-rev --stdin --name-only --refs="*tags/F" --refs="*tags/E" \
108 <actual >actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700109 test_cmp expect actual.named
Jacob Keller290be662017-01-18 15:06:05 -0800110'
111
112cat >expect <<EOF
113<tags/F
114EOF
115
116test_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 &&
119 git name-rev --stdin --name-only --refs="*tags/F" \
120 <actual >actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700121 test_cmp expect actual.named
Jacob Keller290be662017-01-18 15:06:05 -0800122'
123
Jacob Keller96415b42017-01-18 15:06:06 -0800124cat >expect <<EOF
125<tags/F
126EOF
127
128test_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 &&
131 git name-rev --stdin --name-only --refs="*tags/*" --exclude="*E" \
132 <actual >actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700133 test_cmp expect actual.named
Jacob Keller96415b42017-01-18 15:06:06 -0800134'
135
Jacob Keller290be662017-01-18 15:06:05 -0800136test_expect_success 'name-rev --no-refs clears the refs list' '
137 git rev-list --left-right --cherry-pick F...E -- bar >expect &&
138 git name-rev --stdin --name-only --refs="*tags/F" --refs="*tags/E" --no-refs --refs="*tags/G" \
139 <expect >actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700140 test_cmp expect actual
Jacob Keller290be662017-01-18 15:06:05 -0800141'
142
Michael J Gruber59c8afd2011-02-21 17:09:12 +0100143cat >expect <<EOF
Michael J Grubercb56e302011-03-07 13:31:41 +0100144+tags/F
145=tags/D
146+tags/E
147=tags/C
148EOF
149
150test_expect_success '--cherry-mark' '
151 git rev-list --cherry-mark F...E -- bar > actual &&
152 git name-rev --stdin --name-only --refs="*tags/*" \
153 < actual > actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700154 test_cmp expect actual.named
Michael J Grubercb56e302011-03-07 13:31:41 +0100155'
156
157cat >expect <<EOF
158<tags/F
159=tags/D
160>tags/E
161=tags/C
162EOF
163
164test_expect_success '--cherry-mark --left-right' '
165 git rev-list --cherry-mark --left-right F...E -- bar > actual &&
166 git name-rev --stdin --name-only --refs="*tags/*" \
167 < actual > actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700168 test_cmp expect actual.named
Michael J Grubercb56e302011-03-07 13:31:41 +0100169'
170
171cat >expect <<EOF
Michael J Gruber59c8afd2011-02-21 17:09:12 +0100172tags/E
173EOF
174
175test_expect_success '--cherry-pick --right-only' '
176 git rev-list --cherry-pick --right-only F...E -- bar > actual &&
177 git name-rev --stdin --name-only --refs="*tags/*" \
178 < actual > actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700179 test_cmp expect actual.named
Michael J Gruber59c8afd2011-02-21 17:09:12 +0100180'
181
182test_expect_success '--cherry-pick --left-only' '
183 git rev-list --cherry-pick --left-only E...F -- bar > actual &&
Michael J Grubere0b9c342011-02-18 13:34:19 +0100184 git name-rev --stdin --name-only --refs="*tags/*" \
185 < actual > actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700186 test_cmp expect actual.named
Johannes Schindelin36d56de2007-07-10 14:50:49 +0100187'
188
Michael J Gruberfe3b59e2011-03-07 13:31:43 +0100189cat >expect <<EOF
190+tags/E
191=tags/C
192EOF
193
194test_expect_success '--cherry' '
195 git rev-list --cherry F...E -- bar > actual &&
196 git name-rev --stdin --name-only --refs="*tags/*" \
197 < actual > actual.named &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700198 test_cmp expect actual.named
Michael J Gruberfe3b59e2011-03-07 13:31:43 +0100199'
200
Michael J Gruberb388e142011-04-26 10:24:29 +0200201cat >expect <<EOF
2021 1
203EOF
204
205test_expect_success '--cherry --count' '
206 git rev-list --cherry --count F...E -- bar > actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700207 test_cmp expect actual
Michael J Gruberb388e142011-04-26 10:24:29 +0200208'
209
210cat >expect <<EOF
2112 2
212EOF
213
214test_expect_success '--cherry-mark --count' '
215 git rev-list --cherry-mark --count F...E -- bar > actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700216 test_cmp expect actual
Michael J Gruberb388e142011-04-26 10:24:29 +0200217'
218
219cat >expect <<EOF
2201 1 2
221EOF
222
223test_expect_success '--cherry-mark --left-right --count' '
224 git rev-list --cherry-mark --left-right --count F...E -- bar > actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700225 test_cmp expect actual
Michael J Gruberb388e142011-04-26 10:24:29 +0200226'
227
Johannes Schindelin023756f2007-09-15 18:39:52 +0100228test_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 \
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000239 HEAD...main -- foo)"
Johannes Schindelin023756f2007-09-15 18:39:52 +0100240'
241
Thomas Rastf69c5012010-06-10 13:47:23 +0200242cat >expect <<EOF
2431 2
244EOF
245
Thomas Rastf69c5012010-06-10 13:47:23 +0200246test_expect_success '--count --left-right' '
Michael J Grubere0b9c342011-02-18 13:34:19 +0100247 git rev-list --count --left-right C...D > actual &&
Thomas Rastf69c5012010-06-10 13:47:23 +0200248 test_cmp expect actual
249'
250
Jeff Kingc9e3a4e2021-01-12 10:52:32 -0500251test_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
Kevin Willfordb3dfeeb2016-07-29 12:19:20 -0400263# Corrupt the object store deliberately to make sure
264# the object is not even checked for its existence.
265remove_loose_object () {
266 sha1="$(git rev-parse "$1")" &&
267 remainder=${sha1#??} &&
268 firsttwo=${sha1%$remainder} &&
269 rm .git/objects/$firsttwo/$remainder
270}
271
272test_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
Johannes Schindelin36d56de2007-07-10 14:50:49 +0100284test_done