3 test_description
='test git rev-list --cherry-pick -- file'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
16 # B changes a file foo.c, adding a line of text. C changes foo.c as
17 # well as bar.c, but the change in foo.c was identical to change B.
18 # D and C change bar in the same way, E and F differently.
20 test_expect_success setup
'
26 git checkout -b branch &&
39 git checkout branch foo &&
60 test_expect_success
'--left-right' '
61 git rev-list --left-right B...C > actual &&
62 git name-rev --annotate-stdin --name-only --refs="*tags/*" \
63 < actual > actual.named &&
64 test_cmp expect actual.named
67 test_expect_success
'--count' '
68 git rev-list --count B...C > actual &&
69 test "$(cat actual)" = 2
72 test_expect_success
'--cherry-pick foo comes up empty' '
73 test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)"
80 test_expect_success
'--cherry-pick bar does not come up empty' '
81 git rev-list --left-right --cherry-pick B...C -- bar > actual &&
82 git name-rev --annotate-stdin --name-only --refs="*tags/*" \
83 < actual > actual.named &&
84 test_cmp expect actual.named
87 test_expect_success
'bar does not come up empty' '
88 git rev-list --left-right B...C -- bar > actual &&
89 git name-rev --annotate-stdin --name-only --refs="*tags/*" \
90 < actual > actual.named &&
91 test_cmp expect actual.named
99 test_expect_success
'--cherry-pick bar does not come up empty (II)' '
100 git rev-list --left-right --cherry-pick F...E -- bar > actual &&
101 git name-rev --annotate-stdin --name-only --refs="*tags/*" \
102 < actual > actual.named &&
103 test_cmp expect actual.named
106 test_expect_success
'name-rev multiple --refs combine inclusive' '
107 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
108 git name-rev --annotate-stdin --name-only --refs="*tags/F" --refs="*tags/E" \
109 <actual >actual.named &&
110 test_cmp expect actual.named
117 test_expect_success
'name-rev --refs excludes non-matched patterns' '
118 git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect &&
119 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
120 git name-rev --annotate-stdin --name-only --refs="*tags/F" \
121 <actual >actual.named &&
122 test_cmp expect actual.named
129 test_expect_success
'name-rev --exclude excludes matched patterns' '
130 git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect &&
131 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
132 git name-rev --annotate-stdin --name-only --refs="*tags/*" --exclude="*E" \
133 <actual >actual.named &&
134 test_cmp expect actual.named
137 test_expect_success
'name-rev --no-refs clears the refs list' '
138 git rev-list --left-right --cherry-pick F...E -- bar >expect &&
139 git name-rev --annotate-stdin --name-only --refs="*tags/F" --refs="*tags/E" --no-refs --refs="*tags/G" \
141 test_cmp expect actual
151 test_expect_success
'--cherry-mark' '
152 git rev-list --cherry-mark F...E -- bar > actual &&
153 git name-rev --annotate-stdin --name-only --refs="*tags/*" \
154 < actual > actual.named &&
155 test_cmp expect actual.named
165 test_expect_success
'--cherry-mark --left-right' '
166 git rev-list --cherry-mark --left-right F...E -- bar > actual &&
167 git name-rev --annotate-stdin --name-only --refs="*tags/*" \
168 < actual > actual.named &&
169 test_cmp expect actual.named
176 test_expect_success
'--cherry-pick --right-only' '
177 git rev-list --cherry-pick --right-only F...E -- bar > actual &&
178 git name-rev --annotate-stdin --name-only --refs="*tags/*" \
179 < actual > actual.named &&
180 test_cmp expect actual.named
183 test_expect_success
'--cherry-pick --left-only' '
184 git rev-list --cherry-pick --left-only E...F -- bar > actual &&
185 git name-rev --annotate-stdin --name-only --refs="*tags/*" \
186 < actual > actual.named &&
187 test_cmp expect actual.named
195 test_expect_success
'--cherry' '
196 git rev-list --cherry F...E -- bar > actual &&
197 git name-rev --annotate-stdin --name-only --refs="*tags/*" \
198 < actual > actual.named &&
199 test_cmp expect actual.named
206 test_expect_success
'--cherry --count' '
207 git rev-list --cherry --count F...E -- bar > actual &&
208 test_cmp expect actual
215 test_expect_success
'--cherry-mark --count' '
216 git rev-list --cherry-mark --count F...E -- bar > actual &&
217 test_cmp expect actual
224 test_expect_success
'--cherry-mark --left-right --count' '
225 git rev-list --cherry-mark --left-right --count F...E -- bar > actual &&
226 test_cmp expect actual
229 test_expect_success
'--cherry-pick with independent, but identical branches' '
230 git symbolic-ref HEAD refs/heads/independent &&
235 git commit -m "independent" &&
238 git commit -m "independent, too" foo &&
239 test -z "$(git rev-list --left-right --cherry-pick \
247 test_expect_success
'--count --left-right' '
248 git rev-list --count --left-right C...D > actual &&
249 test_cmp expect actual
252 test_expect_success
'--cherry-pick with duplicates on each side' '
253 git checkout -b dup-orig &&
254 test_commit dup-base &&
255 git revert dup-base &&
256 git cherry-pick dup-base &&
257 git checkout -b dup-side HEAD~3 &&
259 git cherry-pick -3 dup-orig &&
260 git rev-list --cherry-pick dup-orig...dup-side >actual &&
261 test_must_be_empty actual
264 # Corrupt the object store deliberately to make sure
265 # the object is not even checked for its existence.
266 remove_loose_object
() {
267 sha1
="$(git rev-parse "$1")" &&
268 remainder
=${sha1#??} &&
269 firsttwo
=${sha1%$remainder} &&
270 rm .git
/objects
/$firsttwo/$remainder
273 test_expect_success
'--cherry-pick avoids looking at full diffs' '
274 git checkout -b shy-diff &&
275 test_commit dont-look-at-me &&
276 echo Hello >dont-look-at-me.t &&
278 git commit -m tip dont-look-at-me.t &&
279 git checkout -b mainline HEAD^ &&
280 test_commit to-cherry-pick &&
281 remove_loose_object shy-diff^:dont-look-at-me.t &&
282 git rev-list --cherry-pick ...shy-diff