3 test_description='test git rev-list --cherry-pick -- file'
12 # B changes a file foo.c, adding a line of text. C changes foo.c as
13 # well as bar.c, but the change in foo.c was identical to change B.
14 # D and C change bar in the same way, E and F differently.
16 test_expect_success setup '
22 git checkout -b branch &&
34 git checkout master &&
35 git checkout branch foo &&
56 test_expect_success '--left-right' '
57 git rev-list --left-right B...C > actual &&
58 git name-rev --stdin --name-only --refs="*tags/*" \
59 < actual > actual.named &&
60 test_cmp expect actual.named
63 test_expect_success '--count' '
64 git rev-list --count B...C > actual &&
65 test "$(cat actual)" = 2
68 test_expect_success '--cherry-pick foo comes up empty' '
69 test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)"
76 test_expect_success '--cherry-pick bar does not come up empty' '
77 git rev-list --left-right --cherry-pick B...C -- bar > actual &&
78 git name-rev --stdin --name-only --refs="*tags/*" \
79 < actual > actual.named &&
80 test_cmp expect actual.named
83 test_expect_success 'bar does not come up empty' '
84 git rev-list --left-right B...C -- bar > actual &&
85 git name-rev --stdin --name-only --refs="*tags/*" \
86 < actual > actual.named &&
87 test_cmp expect actual.named
95 test_expect_success '--cherry-pick bar does not come up empty (II)' '
96 git rev-list --left-right --cherry-pick F...E -- bar > actual &&
97 git name-rev --stdin --name-only --refs="*tags/*" \
98 < actual > actual.named &&
99 test_cmp expect actual.named
102 test_expect_success 'name-rev multiple --refs combine inclusive' '
103 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
104 git name-rev --stdin --name-only --refs="*tags/F" --refs="*tags/E" \
105 <actual >actual.named &&
106 test_cmp expect actual.named
113 test_expect_success 'name-rev --refs excludes non-matched patterns' '
114 git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect &&
115 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
116 git name-rev --stdin --name-only --refs="*tags/F" \
117 <actual >actual.named &&
118 test_cmp expect actual.named
125 test_expect_success 'name-rev --exclude excludes matched patterns' '
126 git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect &&
127 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
128 git name-rev --stdin --name-only --refs="*tags/*" --exclude="*E" \
129 <actual >actual.named &&
130 test_cmp expect actual.named
133 test_expect_success 'name-rev --no-refs clears the refs list' '
134 git rev-list --left-right --cherry-pick F...E -- bar >expect &&
135 git name-rev --stdin --name-only --refs="*tags/F" --refs="*tags/E" --no-refs --refs="*tags/G" \
137 test_cmp expect actual
147 test_expect_success '--cherry-mark' '
148 git rev-list --cherry-mark F...E -- bar > actual &&
149 git name-rev --stdin --name-only --refs="*tags/*" \
150 < actual > actual.named &&
151 test_cmp expect actual.named
161 test_expect_success '--cherry-mark --left-right' '
162 git rev-list --cherry-mark --left-right F...E -- bar > actual &&
163 git name-rev --stdin --name-only --refs="*tags/*" \
164 < actual > actual.named &&
165 test_cmp expect actual.named
172 test_expect_success '--cherry-pick --right-only' '
173 git rev-list --cherry-pick --right-only F...E -- bar > actual &&
174 git name-rev --stdin --name-only --refs="*tags/*" \
175 < actual > actual.named &&
176 test_cmp expect actual.named
179 test_expect_success '--cherry-pick --left-only' '
180 git rev-list --cherry-pick --left-only E...F -- bar > actual &&
181 git name-rev --stdin --name-only --refs="*tags/*" \
182 < actual > actual.named &&
183 test_cmp expect actual.named
191 test_expect_success '--cherry' '
192 git rev-list --cherry F...E -- bar > actual &&
193 git name-rev --stdin --name-only --refs="*tags/*" \
194 < actual > actual.named &&
195 test_cmp expect actual.named
202 test_expect_success '--cherry --count' '
203 git rev-list --cherry --count F...E -- bar > actual &&
204 test_cmp expect actual
211 test_expect_success '--cherry-mark --count' '
212 git rev-list --cherry-mark --count F...E -- bar > actual &&
213 test_cmp expect actual
220 test_expect_success '--cherry-mark --left-right --count' '
221 git rev-list --cherry-mark --left-right --count F...E -- bar > actual &&
222 test_cmp expect actual
225 test_expect_success '--cherry-pick with independent, but identical branches' '
226 git symbolic-ref HEAD refs/heads/independent &&
231 git commit -m "independent" &&
234 git commit -m "independent, too" foo &&
235 test -z "$(git rev-list --left-right --cherry-pick \
236 HEAD...master -- foo)"
243 test_expect_success '--count --left-right' '
244 git rev-list --count --left-right C...D > actual &&
245 test_cmp expect actual
248 test_expect_success '--cherry-pick with duplicates on each side' '
249 git checkout -b dup-orig &&
250 test_commit dup-base &&
251 git revert dup-base &&
252 git cherry-pick dup-base &&
253 git checkout -b dup-side HEAD~3 &&
255 git cherry-pick -3 dup-orig &&
256 git rev-list --cherry-pick dup-orig...dup-side >actual &&
257 test_must_be_empty actual
260 # Corrupt the object store deliberately to make sure
261 # the object is not even checked for its existence.
262 remove_loose_object () {
263 sha1="$(git rev-parse "$1")" &&
264 remainder=${sha1#??} &&
265 firsttwo=${sha1%$remainder} &&
266 rm .git/objects/$firsttwo/$remainder
269 test_expect_success '--cherry-pick avoids looking at full diffs' '
270 git checkout -b shy-diff &&
271 test_commit dont-look-at-me &&
272 echo Hello >dont-look-at-me.t &&
274 git commit -m tip dont-look-at-me.t &&
275 git checkout -b mainline HEAD^ &&
276 test_commit to-cherry-pick &&
277 remove_loose_object shy-diff^:dont-look-at-me.t &&
278 git rev-list --cherry-pick ...shy-diff