]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4068-diff-symmetric-merge-base.sh
Merge branch 'en/strmap'
[thirdparty/git.git] / t / t4068-diff-symmetric-merge-base.sh
CommitLineData
8bfcb3a6
CT
1#!/bin/sh
2
df7dbab8 3test_description='behavior of diff with symmetric-diff setups and --merge-base'
8bfcb3a6
CT
4
5. ./test-lib.sh
6
7# build these situations:
8# - normal merge with one merge base (br1...b2r);
9# - criss-cross merge ie 2 merge bases (br1...master);
10# - disjoint subgraph (orphan branch, br3...master).
11#
12# B---E <-- master
13# / \ /
14# A X
15# \ / \
16# C---D--G <-- br1
17# \ /
18# ---F <-- br2
19#
20# H <-- br3
21#
22# We put files into a few commits so that we can verify the
23# output as well.
24
25test_expect_success setup '
26 git commit --allow-empty -m A &&
27 echo b >b &&
28 git add b &&
29 git commit -m B &&
30 git checkout -b br1 HEAD^ &&
31 echo c >c &&
32 git add c &&
33 git commit -m C &&
34 git tag commit-C &&
35 git merge -m D master &&
36 git tag commit-D &&
37 git checkout master &&
38 git merge -m E commit-C &&
39 git checkout -b br2 commit-C &&
40 echo f >f &&
41 git add f &&
42 git commit -m F &&
43 git checkout br1 &&
44 git merge -m G br2 &&
45 git checkout --orphan br3 &&
46 git commit -m H
47'
48
49test_expect_success 'diff with one merge base' '
50 git diff commit-D...br1 >tmp &&
51 tail -n 1 tmp >actual &&
52 echo +f >expect &&
53 test_cmp expect actual
54'
55
56# The output (in tmp) can have +b or +c depending
57# on which merge base (commit B or C) is picked.
58# It should have one of those two, which comes out
59# to seven lines.
60test_expect_success 'diff with two merge bases' '
61 git diff br1...master >tmp 2>err &&
62 test_line_count = 7 tmp &&
63 test_line_count = 1 err
64'
65
66test_expect_success 'diff with no merge bases' '
8023a5e8 67 test_must_fail git diff br2...br3 2>err &&
8bfcb3a6
CT
68 test_i18ngrep "fatal: br2...br3: no merge base" err
69'
70
71test_expect_success 'diff with too many symmetric differences' '
8023a5e8 72 test_must_fail git diff br1...master br2...br3 2>err &&
8bfcb3a6
CT
73 test_i18ngrep "usage" err
74'
75
76test_expect_success 'diff with symmetric difference and extraneous arg' '
8023a5e8 77 test_must_fail git diff master br1...master 2>err &&
8bfcb3a6
CT
78 test_i18ngrep "usage" err
79'
80
81test_expect_success 'diff with two ranges' '
8023a5e8 82 test_must_fail git diff master br1..master br2..br3 2>err &&
8bfcb3a6
CT
83 test_i18ngrep "usage" err
84'
85
86test_expect_success 'diff with ranges and extra arg' '
8023a5e8 87 test_must_fail git diff master br1..master commit-D 2>err &&
8bfcb3a6
CT
88 test_i18ngrep "usage" err
89'
90
df7dbab8
DL
91test_expect_success 'diff --merge-base with no commits' '
92 test_must_fail git diff --merge-base
93'
94
95test_expect_success 'diff --merge-base with three commits' '
96 test_must_fail git diff --merge-base br1 br2 master 2>err &&
97 test_i18ngrep "usage" err
98'
99
0f5a1d44
DL
100for cmd in diff-index diff
101do
102 test_expect_success "$cmd --merge-base with one commit" '
103 git checkout master &&
104 git $cmd commit-C >expect &&
105 git $cmd --merge-base br2 >actual &&
106 test_cmp expect actual
107 '
108
109 test_expect_success "$cmd --merge-base with one commit and unstaged changes" '
110 git checkout master &&
111 test_when_finished git reset --hard &&
112 echo unstaged >>c &&
113 git $cmd commit-C >expect &&
114 git $cmd --merge-base br2 >actual &&
115 test_cmp expect actual
116 '
117
118 test_expect_success "$cmd --merge-base with one commit and staged and unstaged changes" '
119 git checkout master &&
120 test_when_finished git reset --hard &&
121 echo staged >>c &&
122 git add c &&
123 echo unstaged >>c &&
124 git $cmd commit-C >expect &&
125 git $cmd --merge-base br2 >actual &&
126 test_cmp expect actual
127 '
128
129 test_expect_success "$cmd --merge-base --cached with one commit and staged and unstaged changes" '
130 git checkout master &&
131 test_when_finished git reset --hard &&
132 echo staged >>c &&
133 git add c &&
134 echo unstaged >>c &&
135 git $cmd --cached commit-C >expect &&
136 git $cmd --cached --merge-base br2 >actual &&
137 test_cmp expect actual
138 '
139
140 test_expect_success "$cmd --merge-base with non-commit" '
141 git checkout master &&
142 test_must_fail git $cmd --merge-base master^{tree} 2>err &&
143 test_i18ngrep "fatal: --merge-base only works with commits" err
144 '
145
146 test_expect_success "$cmd --merge-base with no merge bases and one commit" '
147 git checkout master &&
148 test_must_fail git $cmd --merge-base br3 2>err &&
149 test_i18ngrep "fatal: no merge base found" err
150 '
151
152 test_expect_success "$cmd --merge-base with multiple merge bases and one commit" '
153 git checkout master &&
154 test_must_fail git $cmd --merge-base br1 2>err &&
155 test_i18ngrep "fatal: multiple merge bases found" err
156 '
157done
158
3d09c228
DL
159for cmd in diff-tree diff
160do
161 test_expect_success "$cmd --merge-base with two commits" '
162 git $cmd commit-C master >expect &&
163 git $cmd --merge-base br2 master >actual &&
164 test_cmp expect actual
165 '
166
167 test_expect_success "$cmd --merge-base commit and non-commit" '
168 test_must_fail git $cmd --merge-base br2 master^{tree} 2>err &&
169 test_i18ngrep "fatal: --merge-base only works with commits" err
170 '
171
172 test_expect_success "$cmd --merge-base with no merge bases and two commits" '
173 test_must_fail git $cmd --merge-base br2 br3 2>err &&
174 test_i18ngrep "fatal: no merge base found" err
175 '
176
177 test_expect_success "$cmd --merge-base with multiple merge bases and two commits" '
178 test_must_fail git $cmd --merge-base master br1 2>err &&
179 test_i18ngrep "fatal: multiple merge bases found" err
180 '
181done
182
183test_expect_success 'diff-tree --merge-base with one commit' '
184 test_must_fail git diff-tree --merge-base master 2>err &&
185 test_i18ngrep "fatal: --merge-base only works with two commits" err
186'
187
188test_expect_success 'diff --merge-base with range' '
189 test_must_fail git diff --merge-base br2..br3 2>err &&
190 test_i18ngrep "fatal: --merge-base does not work with ranges" err
191'
192
8bfcb3a6 193test_done