Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t6007-rev-list-cherry-pick-file.sh
blob2d337d7287a3c2b003e61c85494ef4da4d28bcd1
1 #!/bin/sh
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
9 . ./test-lib.sh
11 # A---B---D---F
12 # \
13 # \
14 # C---E
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 '
21 echo Hallo > foo &&
22 git add foo &&
23 test_tick &&
24 git commit -m "A" &&
25 git tag A &&
26 git checkout -b branch &&
27 echo Bello > foo &&
28 echo Cello > bar &&
29 git add foo bar &&
30 test_tick &&
31 git commit -m "C" &&
32 git tag C &&
33 echo Dello > bar &&
34 git add bar &&
35 test_tick &&
36 git commit -m "E" &&
37 git tag E &&
38 git checkout main &&
39 git checkout branch foo &&
40 test_tick &&
41 git commit -m "B" &&
42 git tag B &&
43 echo Cello > bar &&
44 git add bar &&
45 test_tick &&
46 git commit -m "D" &&
47 git tag D &&
48 echo Nello > bar &&
49 git add bar &&
50 test_tick &&
51 git commit -m "F" &&
52 git tag F
55 cat >expect <<EOF
56 <tags/B
57 >tags/C
58 EOF
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)"
76 cat >expect <<EOF
77 >tags/C
78 EOF
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
94 cat >expect <<EOF
95 <tags/F
96 >tags/E
97 EOF
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
113 cat >expect <<EOF
114 <tags/F
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
125 cat >expect <<EOF
126 <tags/F
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" \
140 <expect >actual &&
141 test_cmp expect actual
144 cat >expect <<EOF
145 +tags/F
146 =tags/D
147 +tags/E
148 =tags/C
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
158 cat >expect <<EOF
159 <tags/F
160 =tags/D
161 >tags/E
162 =tags/C
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
172 cat >expect <<EOF
173 tags/E
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
190 cat >expect <<EOF
191 +tags/E
192 =tags/C
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
202 cat >expect <<EOF
206 test_expect_success '--cherry --count' '
207 git rev-list --cherry --count F...E -- bar > actual &&
208 test_cmp expect actual
211 cat >expect <<EOF
215 test_expect_success '--cherry-mark --count' '
216 git rev-list --cherry-mark --count F...E -- bar > actual &&
217 test_cmp expect actual
220 cat >expect <<EOF
221 1 1 2
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 &&
231 rm .git/index &&
232 echo Hallo > foo &&
233 git add foo &&
234 test_tick &&
235 git commit -m "independent" &&
236 echo Bello > foo &&
237 test_tick &&
238 git commit -m "independent, too" foo &&
239 test -z "$(git rev-list --left-right --cherry-pick \
240 HEAD...main -- foo)"
243 cat >expect <<EOF
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 &&
258 test_tick &&
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 &&
277 test_tick &&
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
285 test_done