]>
Commit | Line | Data |
---|---|---|
36d56de6 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='test git rev-list --cherry-pick -- file' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
59c8afdf | 7 | # A---B---D---F |
36d56de6 JS |
8 | # \ |
9 | # \ | |
e0b9c34f | 10 | # C---E |
36d56de6 JS |
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. | |
59c8afdf | 14 | # D and C change bar in the same way, E and F differently. |
36d56de6 JS |
15 | |
16 | test_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 && | |
e0b9c34f MG |
29 | echo Dello > bar && |
30 | git add bar && | |
31 | test_tick && | |
32 | git commit -m "E" && | |
33 | git tag E && | |
36d56de6 JS |
34 | git checkout master && |
35 | git checkout branch foo && | |
36 | test_tick && | |
37 | git commit -m "B" && | |
e0b9c34f MG |
38 | git tag B && |
39 | echo Cello > bar && | |
40 | git add bar && | |
41 | test_tick && | |
42 | git commit -m "D" && | |
59c8afdf MG |
43 | git tag D && |
44 | echo Nello > bar && | |
45 | git add bar && | |
46 | test_tick && | |
47 | git commit -m "F" && | |
48 | git tag F | |
36d56de6 JS |
49 | ' |
50 | ||
f69c5018 TR |
51 | cat >expect <<EOF |
52 | <tags/B | |
53 | >tags/C | |
54 | EOF | |
55 | ||
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 && | |
9c5b2fab | 60 | test_cmp expect actual.named |
f69c5018 TR |
61 | ' |
62 | ||
63 | test_expect_success '--count' ' | |
64 | git rev-list --count B...C > actual && | |
65 | test "$(cat actual)" = 2 | |
66 | ' | |
67 | ||
36d56de6 JS |
68 | test_expect_success '--cherry-pick foo comes up empty' ' |
69 | test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)" | |
70 | ' | |
71 | ||
e0b9c34f MG |
72 | cat >expect <<EOF |
73 | >tags/C | |
74 | EOF | |
75 | ||
36d56de6 | 76 | test_expect_success '--cherry-pick bar does not come up empty' ' |
e0b9c34f MG |
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 && | |
9c5b2fab | 80 | test_cmp expect actual.named |
e0b9c34f MG |
81 | ' |
82 | ||
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 && | |
9c5b2fab | 87 | test_cmp expect actual.named |
e0b9c34f MG |
88 | ' |
89 | ||
90 | cat >expect <<EOF | |
59c8afdf | 91 | <tags/F |
e0b9c34f MG |
92 | >tags/E |
93 | EOF | |
94 | ||
95 | test_expect_success '--cherry-pick bar does not come up empty (II)' ' | |
59c8afdf MG |
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 && | |
9c5b2fab | 99 | test_cmp expect actual.named |
59c8afdf MG |
100 | ' |
101 | ||
290be667 JK |
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 && | |
9c5b2fab | 106 | test_cmp expect actual.named |
290be667 JK |
107 | ' |
108 | ||
109 | cat >expect <<EOF | |
110 | <tags/F | |
111 | EOF | |
112 | ||
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 && | |
9c5b2fab | 118 | test_cmp expect actual.named |
290be667 JK |
119 | ' |
120 | ||
96415b49 JK |
121 | cat >expect <<EOF |
122 | <tags/F | |
123 | EOF | |
124 | ||
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 && | |
9c5b2fab | 130 | test_cmp expect actual.named |
96415b49 JK |
131 | ' |
132 | ||
290be667 JK |
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" \ | |
136 | <expect >actual && | |
9c5b2fab | 137 | test_cmp expect actual |
290be667 JK |
138 | ' |
139 | ||
59c8afdf | 140 | cat >expect <<EOF |
cb56e309 MG |
141 | +tags/F |
142 | =tags/D | |
143 | +tags/E | |
144 | =tags/C | |
145 | EOF | |
146 | ||
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 && | |
9c5b2fab | 151 | test_cmp expect actual.named |
cb56e309 MG |
152 | ' |
153 | ||
154 | cat >expect <<EOF | |
155 | <tags/F | |
156 | =tags/D | |
157 | >tags/E | |
158 | =tags/C | |
159 | EOF | |
160 | ||
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 && | |
9c5b2fab | 165 | test_cmp expect actual.named |
cb56e309 MG |
166 | ' |
167 | ||
168 | cat >expect <<EOF | |
59c8afdf MG |
169 | tags/E |
170 | EOF | |
171 | ||
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 && | |
9c5b2fab | 176 | test_cmp expect actual.named |
59c8afdf MG |
177 | ' |
178 | ||
179 | test_expect_success '--cherry-pick --left-only' ' | |
180 | git rev-list --cherry-pick --left-only E...F -- bar > actual && | |
e0b9c34f MG |
181 | git name-rev --stdin --name-only --refs="*tags/*" \ |
182 | < actual > actual.named && | |
9c5b2fab | 183 | test_cmp expect actual.named |
36d56de6 JS |
184 | ' |
185 | ||
fe3b59e5 MG |
186 | cat >expect <<EOF |
187 | +tags/E | |
188 | =tags/C | |
189 | EOF | |
190 | ||
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 && | |
9c5b2fab | 195 | test_cmp expect actual.named |
fe3b59e5 MG |
196 | ' |
197 | ||
b388e14b MG |
198 | cat >expect <<EOF |
199 | 1 1 | |
200 | EOF | |
201 | ||
202 | test_expect_success '--cherry --count' ' | |
203 | git rev-list --cherry --count F...E -- bar > actual && | |
9c5b2fab | 204 | test_cmp expect actual |
b388e14b MG |
205 | ' |
206 | ||
207 | cat >expect <<EOF | |
208 | 2 2 | |
209 | EOF | |
210 | ||
211 | test_expect_success '--cherry-mark --count' ' | |
212 | git rev-list --cherry-mark --count F...E -- bar > actual && | |
9c5b2fab | 213 | test_cmp expect actual |
b388e14b MG |
214 | ' |
215 | ||
216 | cat >expect <<EOF | |
217 | 1 1 2 | |
218 | EOF | |
219 | ||
220 | test_expect_success '--cherry-mark --left-right --count' ' | |
221 | git rev-list --cherry-mark --left-right --count F...E -- bar > actual && | |
9c5b2fab | 222 | test_cmp expect actual |
b388e14b MG |
223 | ' |
224 | ||
023756f4 JS |
225 | test_expect_success '--cherry-pick with independent, but identical branches' ' |
226 | git symbolic-ref HEAD refs/heads/independent && | |
227 | rm .git/index && | |
228 | echo Hallo > foo && | |
229 | git add foo && | |
230 | test_tick && | |
231 | git commit -m "independent" && | |
232 | echo Bello > foo && | |
233 | test_tick && | |
234 | git commit -m "independent, too" foo && | |
235 | test -z "$(git rev-list --left-right --cherry-pick \ | |
236 | HEAD...master -- foo)" | |
237 | ' | |
238 | ||
f69c5018 TR |
239 | cat >expect <<EOF |
240 | 1 2 | |
241 | EOF | |
242 | ||
f69c5018 | 243 | test_expect_success '--count --left-right' ' |
e0b9c34f | 244 | git rev-list --count --left-right C...D > actual && |
f69c5018 TR |
245 | test_cmp expect actual |
246 | ' | |
247 | ||
b3dfeebb KW |
248 | # Corrupt the object store deliberately to make sure |
249 | # the object is not even checked for its existence. | |
250 | remove_loose_object () { | |
251 | sha1="$(git rev-parse "$1")" && | |
252 | remainder=${sha1#??} && | |
253 | firsttwo=${sha1%$remainder} && | |
254 | rm .git/objects/$firsttwo/$remainder | |
255 | } | |
256 | ||
257 | test_expect_success '--cherry-pick avoids looking at full diffs' ' | |
258 | git checkout -b shy-diff && | |
259 | test_commit dont-look-at-me && | |
260 | echo Hello >dont-look-at-me.t && | |
261 | test_tick && | |
262 | git commit -m tip dont-look-at-me.t && | |
263 | git checkout -b mainline HEAD^ && | |
264 | test_commit to-cherry-pick && | |
265 | remove_loose_object shy-diff^:dont-look-at-me.t && | |
266 | git rev-list --cherry-pick ...shy-diff | |
267 | ' | |
268 | ||
36d56de6 | 269 | test_done |