d9827a6389a3c468d5c6a8d8ef82bc361993078f
1#!/bin/sh
2
3test_description='test git rev-list --cherry-pick -- file'
4
5. ./test-lib.sh
6
7# A---B---D---F
8# \
9# \
10# C---E
11#
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.
15
16test_expect_success setup '
17 echo Hallo > foo &&
18 git add foo &&
19 test_tick &&
20 git commit -m "A" &&
21 git tag A &&
22 git checkout -b branch &&
23 echo Bello > foo &&
24 echo Cello > bar &&
25 git add foo bar &&
26 test_tick &&
27 git commit -m "C" &&
28 git tag C &&
29 echo Dello > bar &&
30 git add bar &&
31 test_tick &&
32 git commit -m "E" &&
33 git tag E &&
34 git checkout master &&
35 git checkout branch foo &&
36 test_tick &&
37 git commit -m "B" &&
38 git tag B &&
39 echo Cello > bar &&
40 git add bar &&
41 test_tick &&
42 git commit -m "D" &&
43 git tag D &&
44 echo Nello > bar &&
45 git add bar &&
46 test_tick &&
47 git commit -m "F" &&
48 git tag F
49'
50
51cat >expect <<EOF
52<tags/B
53>tags/C
54EOF
55
56test_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 actual.named expect
61'
62
63test_expect_success '--count' '
64 git rev-list --count B...C > actual &&
65 test "$(cat actual)" = 2
66'
67
68test_expect_success '--cherry-pick foo comes up empty' '
69 test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)"
70'
71
72cat >expect <<EOF
73>tags/C
74EOF
75
76test_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 actual.named expect
81'
82
83test_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 actual.named expect
88'
89
90cat >expect <<EOF
91<tags/F
92>tags/E
93EOF
94
95test_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 actual.named expect
100'
101
102test_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 actual.named expect
107'
108
109cat >expect <<EOF
110<tags/F
111EOF
112
113test_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 actual.named expect
119'
120
121test_expect_success 'name-rev --no-refs clears the refs list' '
122 git rev-list --left-right --cherry-pick F...E -- bar >expect &&
123 git name-rev --stdin --name-only --refs="*tags/F" --refs="*tags/E" --no-refs --refs="*tags/G" \
124 <expect >actual &&
125 test_cmp actual expect
126'
127
128cat >expect <<EOF
129+tags/F
130=tags/D
131+tags/E
132=tags/C
133EOF
134
135test_expect_success '--cherry-mark' '
136 git rev-list --cherry-mark F...E -- bar > actual &&
137 git name-rev --stdin --name-only --refs="*tags/*" \
138 < actual > actual.named &&
139 test_cmp actual.named expect
140'
141
142cat >expect <<EOF
143<tags/F
144=tags/D
145>tags/E
146=tags/C
147EOF
148
149test_expect_success '--cherry-mark --left-right' '
150 git rev-list --cherry-mark --left-right F...E -- bar > actual &&
151 git name-rev --stdin --name-only --refs="*tags/*" \
152 < actual > actual.named &&
153 test_cmp actual.named expect
154'
155
156cat >expect <<EOF
157tags/E
158EOF
159
160test_expect_success '--cherry-pick --right-only' '
161 git rev-list --cherry-pick --right-only F...E -- bar > actual &&
162 git name-rev --stdin --name-only --refs="*tags/*" \
163 < actual > actual.named &&
164 test_cmp actual.named expect
165'
166
167test_expect_success '--cherry-pick --left-only' '
168 git rev-list --cherry-pick --left-only E...F -- bar > actual &&
169 git name-rev --stdin --name-only --refs="*tags/*" \
170 < actual > actual.named &&
171 test_cmp actual.named expect
172'
173
174cat >expect <<EOF
175+tags/E
176=tags/C
177EOF
178
179test_expect_success '--cherry' '
180 git rev-list --cherry F...E -- bar > actual &&
181 git name-rev --stdin --name-only --refs="*tags/*" \
182 < actual > actual.named &&
183 test_cmp actual.named expect
184'
185
186cat >expect <<EOF
1871 1
188EOF
189
190test_expect_success '--cherry --count' '
191 git rev-list --cherry --count F...E -- bar > actual &&
192 test_cmp actual expect
193'
194
195cat >expect <<EOF
1962 2
197EOF
198
199test_expect_success '--cherry-mark --count' '
200 git rev-list --cherry-mark --count F...E -- bar > actual &&
201 test_cmp actual expect
202'
203
204cat >expect <<EOF
2051 1 2
206EOF
207
208test_expect_success '--cherry-mark --left-right --count' '
209 git rev-list --cherry-mark --left-right --count F...E -- bar > actual &&
210 test_cmp actual expect
211'
212
213test_expect_success '--cherry-pick with independent, but identical branches' '
214 git symbolic-ref HEAD refs/heads/independent &&
215 rm .git/index &&
216 echo Hallo > foo &&
217 git add foo &&
218 test_tick &&
219 git commit -m "independent" &&
220 echo Bello > foo &&
221 test_tick &&
222 git commit -m "independent, too" foo &&
223 test -z "$(git rev-list --left-right --cherry-pick \
224 HEAD...master -- foo)"
225'
226
227cat >expect <<EOF
2281 2
229EOF
230
231test_expect_success '--count --left-right' '
232 git rev-list --count --left-right C...D > actual &&
233 test_cmp expect actual
234'
235
236# Corrupt the object store deliberately to make sure
237# the object is not even checked for its existence.
238remove_loose_object () {
239 sha1="$(git rev-parse "$1")" &&
240 remainder=${sha1#??} &&
241 firsttwo=${sha1%$remainder} &&
242 rm .git/objects/$firsttwo/$remainder
243}
244
245test_expect_success '--cherry-pick avoids looking at full diffs' '
246 git checkout -b shy-diff &&
247 test_commit dont-look-at-me &&
248 echo Hello >dont-look-at-me.t &&
249 test_tick &&
250 git commit -m tip dont-look-at-me.t &&
251 git checkout -b mainline HEAD^ &&
252 test_commit to-cherry-pick &&
253 remove_loose_object shy-diff^:dont-look-at-me.t &&
254 git rev-list --cherry-pick ...shy-diff
255'
256
257test_done