64b72a3e209b16d8de3d2975324f7fa7d9bed624
1#!/bin/sh
2
3test_description='test git rev-list --cherry-pick -- file'
4
5. ./test-lib.sh
6
7# A---B---D
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 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'
45
46cat >expect <<EOF
47<tags/B
48>tags/C
49EOF
50
51test_expect_success '--left-right' '
52 git rev-list --left-right B...C > actual &&
53 git name-rev --stdin --name-only --refs="*tags/*" \
54 < actual > actual.named &&
55 test_cmp actual.named expect
56'
57
58test_expect_success '--count' '
59 git rev-list --count B...C > actual &&
60 test "$(cat actual)" = 2
61'
62
63test_expect_success '--cherry-pick foo comes up empty' '
64 test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)"
65'
66
67cat >expect <<EOF
68>tags/C
69EOF
70
71test_expect_success '--cherry-pick bar does not come up empty' '
72 git rev-list --left-right --cherry-pick B...C -- bar > actual &&
73 git name-rev --stdin --name-only --refs="*tags/*" \
74 < actual > actual.named &&
75 test_cmp actual.named expect
76'
77
78test_expect_success 'bar does not come up empty' '
79 git rev-list --left-right B...C -- bar > actual &&
80 git name-rev --stdin --name-only --refs="*tags/*" \
81 < actual > actual.named &&
82 test_cmp actual.named expect
83'
84
85cat >expect <<EOF
86>tags/E
87EOF
88
89test_expect_success '--cherry-pick bar does not come up empty (II)' '
90 git rev-list --left-right --cherry-pick D...E -- bar > actual &&
91 git name-rev --stdin --name-only --refs="*tags/*" \
92 < actual > actual.named &&
93 test_cmp actual.named expect
94'
95
96test_expect_success '--cherry-pick with independent, but identical branches' '
97 git symbolic-ref HEAD refs/heads/independent &&
98 rm .git/index &&
99 echo Hallo > foo &&
100 git add foo &&
101 test_tick &&
102 git commit -m "independent" &&
103 echo Bello > foo &&
104 test_tick &&
105 git commit -m "independent, too" foo &&
106 test -z "$(git rev-list --left-right --cherry-pick \
107 HEAD...master -- foo)"
108'
109
110cat >expect <<EOF
1111 2
112EOF
113
114test_expect_success '--count --left-right' '
115 git rev-list --count --left-right C...D > actual &&
116 test_cmp expect actual
117'
118
119test_done