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
15 # B changes a file foo.c, adding a line of text. C changes foo.c as
16 # well as bar.c, but the change in foo.c was identical to change B.
17 # D and C change bar in the same way, E and F differently.
19 test_expect_success setup '
25 git checkout -b branch &&
38 git checkout branch foo &&
59 test_expect_success '--left-right' '
60 git rev-list --left-right B...C > actual &&
61 git name-rev --stdin --name-only --refs="*tags/*" \
62 < actual > actual.named &&
63 test_cmp expect actual.named
66 test_expect_success '--count' '
67 git rev-list --count B...C > actual &&
68 test "$(cat actual)" = 2
71 test_expect_success '--cherry-pick foo comes up empty' '
72 test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)"
79 test_expect_success '--cherry-pick bar does not come up empty' '
80 git rev-list --left-right --cherry-pick B...C -- bar > actual &&
81 git name-rev --stdin --name-only --refs="*tags/*" \
82 < actual > actual.named &&
83 test_cmp expect actual.named
86 test_expect_success 'bar does not come up empty' '
87 git rev-list --left-right B...C -- bar > actual &&
88 git name-rev --stdin --name-only --refs="*tags/*" \
89 < actual > actual.named &&
90 test_cmp expect actual.named
98 test_expect_success '--cherry-pick bar does not come up empty (II)' '
99 git rev-list --left-right --cherry-pick F...E -- bar > actual &&
100 git name-rev --stdin --name-only --refs="*tags/*" \
101 < actual > actual.named &&
102 test_cmp expect actual.named
105 test_expect_success 'name-rev multiple --refs combine inclusive' '
106 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
107 git name-rev --stdin --name-only --refs="*tags/F" --refs="*tags/E" \
108 <actual >actual.named &&
109 test_cmp expect actual.named
116 test_expect_success 'name-rev --refs excludes non-matched patterns' '
117 git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect &&
118 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
119 git name-rev --stdin --name-only --refs="*tags/F" \
120 <actual >actual.named &&
121 test_cmp expect actual.named
128 test_expect_success 'name-rev --exclude excludes matched patterns' '
129 git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect &&
130 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
131 git name-rev --stdin --name-only --refs="*tags/*" --exclude="*E" \
132 <actual >actual.named &&
133 test_cmp expect actual.named
136 test_expect_success 'name-rev --no-refs clears the refs list' '
137 git rev-list --left-right --cherry-pick F...E -- bar >expect &&
138 git name-rev --stdin --name-only --refs="*tags/F" --refs="*tags/E" --no-refs --refs="*tags/G" \
140 test_cmp expect actual
150 test_expect_success '--cherry-mark' '
151 git rev-list --cherry-mark F...E -- bar > actual &&
152 git name-rev --stdin --name-only --refs="*tags/*" \
153 < actual > actual.named &&
154 test_cmp expect actual.named
164 test_expect_success '--cherry-mark --left-right' '
165 git rev-list --cherry-mark --left-right F...E -- bar > actual &&
166 git name-rev --stdin --name-only --refs="*tags/*" \
167 < actual > actual.named &&
168 test_cmp expect actual.named
175 test_expect_success '--cherry-pick --right-only' '
176 git rev-list --cherry-pick --right-only F...E -- bar > actual &&
177 git name-rev --stdin --name-only --refs="*tags/*" \
178 < actual > actual.named &&
179 test_cmp expect actual.named
182 test_expect_success '--cherry-pick --left-only' '
183 git rev-list --cherry-pick --left-only E...F -- bar > actual &&
184 git name-rev --stdin --name-only --refs="*tags/*" \
185 < actual > actual.named &&
186 test_cmp expect actual.named
194 test_expect_success '--cherry' '
195 git rev-list --cherry F...E -- bar > actual &&
196 git name-rev --stdin --name-only --refs="*tags/*" \
197 < actual > actual.named &&
198 test_cmp expect actual.named
205 test_expect_success '--cherry --count' '
206 git rev-list --cherry --count F...E -- bar > actual &&
207 test_cmp expect actual
214 test_expect_success '--cherry-mark --count' '
215 git rev-list --cherry-mark --count F...E -- bar > actual &&
216 test_cmp expect actual
223 test_expect_success '--cherry-mark --left-right --count' '
224 git rev-list --cherry-mark --left-right --count F...E -- bar > actual &&
225 test_cmp expect actual
228 test_expect_success '--cherry-pick with independent, but identical branches' '
229 git symbolic-ref HEAD refs/heads/independent &&
234 git commit -m "independent" &&
237 git commit -m "independent, too" foo &&
238 test -z "$(git rev-list --left-right --cherry-pick \
246 test_expect_success '--count --left-right' '
247 git rev-list --count --left-right C...D > actual &&
248 test_cmp expect actual
251 # Corrupt the object store deliberately to make sure
252 # the object is not even checked for its existence.
253 remove_loose_object () {
254 sha1="$(git rev-parse "$1")" &&
255 remainder=${sha1#??} &&
256 firsttwo=${sha1%$remainder} &&
257 rm .git/objects/$firsttwo/$remainder
260 test_expect_success '--cherry-pick avoids looking at full diffs' '
261 git checkout -b shy-diff &&
262 test_commit dont-look-at-me &&
263 echo Hello >dont-look-at-me.t &&
265 git commit -m tip dont-look-at-me.t &&
266 git checkout -b mainline HEAD^ &&
267 test_commit to-cherry-pick &&
268 remove_loose_object shy-diff^:dont-look-at-me.t &&
269 git rev-list --cherry-pick ...shy-diff