3 test_description='behavior of diff with symmetric-diff setups and --merge-base'
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).
22 # We put files into a few commits so that we can verify the
25 test_expect_success setup '
26 git commit --allow-empty -m A &&
30 git checkout -b br1 HEAD^ &&
35 git merge -m D master &&
37 git checkout master &&
38 git merge -m E commit-C &&
39 git checkout -b br2 commit-C &&
45 git checkout --orphan br3 &&
49 test_expect_success 'diff with one merge base' '
50 git diff commit-D...br1 >tmp &&
51 tail -n 1 tmp >actual &&
53 test_cmp expect actual
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
60 test_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
66 test_expect_success 'diff with no merge bases' '
67 test_must_fail git diff br2...br3 2>err &&
68 test_i18ngrep "fatal: br2...br3: no merge base" err
71 test_expect_success 'diff with too many symmetric differences' '
72 test_must_fail git diff br1...master br2...br3 2>err &&
73 test_i18ngrep "usage" err
76 test_expect_success 'diff with symmetric difference and extraneous arg' '
77 test_must_fail git diff master br1...master 2>err &&
78 test_i18ngrep "usage" err
81 test_expect_success 'diff with two ranges' '
82 test_must_fail git diff master br1..master br2..br3 2>err &&
83 test_i18ngrep "usage" err
86 test_expect_success 'diff with ranges and extra arg' '
87 test_must_fail git diff master br1..master commit-D 2>err &&
88 test_i18ngrep "usage" err
91 test_expect_success 'diff --merge-base with no commits' '
92 test_must_fail git diff --merge-base
95 test_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
100 for cmd in diff-index diff
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
109 test_expect_success "$cmd --merge-base with one commit and unstaged changes" '
110 git checkout master &&
111 test_when_finished git reset --hard &&
113 git $cmd commit-C >expect &&
114 git $cmd --merge-base br2 >actual &&
115 test_cmp expect actual
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 &&
124 git $cmd commit-C >expect &&
125 git $cmd --merge-base br2 >actual &&
126 test_cmp expect actual
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 &&
135 git $cmd --cached commit-C >expect &&
136 git $cmd --cached --merge-base br2 >actual &&
137 test_cmp expect actual
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
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
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
159 for cmd in diff-tree diff
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
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
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
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
183 test_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
188 test_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