rev-list: documentation and test for --left/right-only
[alt-git.git] / t / t6007-rev-list-cherry-pick-file.sh
blobcd089a913bb93abc882db5a128429dab0d0275db
1 #!/bin/sh
3 test_description='test git rev-list --cherry-pick -- file'
5 . ./test-lib.sh
7 # A---B---D---F
8 # \
9 # \
10 # C---E
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.
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 &&
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
51 cat >expect <<EOF
52 <tags/B
53 >tags/C
54 EOF
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 &&
60 test_cmp actual.named expect
63 test_expect_success '--count' '
64 git rev-list --count B...C > actual &&
65 test "$(cat actual)" = 2
68 test_expect_success '--cherry-pick foo comes up empty' '
69 test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)"
72 cat >expect <<EOF
73 >tags/C
74 EOF
76 test_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
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 &&
87 test_cmp actual.named expect
90 cat >expect <<EOF
91 <tags/F
92 >tags/E
93 EOF
95 test_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
102 cat >expect <<EOF
103 tags/E
106 test_expect_success '--cherry-pick --right-only' '
107 git rev-list --cherry-pick --right-only F...E -- bar > actual &&
108 git name-rev --stdin --name-only --refs="*tags/*" \
109 < actual > actual.named &&
110 test_cmp actual.named expect
113 test_expect_success '--cherry-pick --left-only' '
114 git rev-list --cherry-pick --left-only E...F -- bar > actual &&
115 git name-rev --stdin --name-only --refs="*tags/*" \
116 < actual > actual.named &&
117 test_cmp actual.named expect
120 test_expect_success '--cherry-pick with independent, but identical branches' '
121 git symbolic-ref HEAD refs/heads/independent &&
122 rm .git/index &&
123 echo Hallo > foo &&
124 git add foo &&
125 test_tick &&
126 git commit -m "independent" &&
127 echo Bello > foo &&
128 test_tick &&
129 git commit -m "independent, too" foo &&
130 test -z "$(git rev-list --left-right --cherry-pick \
131 HEAD...master -- foo)"
134 cat >expect <<EOF
138 test_expect_success '--count --left-right' '
139 git rev-list --count --left-right C...D > actual &&
140 test_cmp expect actual
143 test_done