Browse Source
When git diff is given a symmetric difference A...B, it chooses some merge base from the two specified commits (as documented). This fails, however, if there is *no* merge base: instead, you see the differences between A and B, which is certainly not what is expected. Moreover, if additional revisions are specified on the command line ("git diff A...B C"), the results get a bit weird: * If there is a symmetric difference merge base, this is used as the left side of the diff. The last final ref is used as the right side. * If there is no merge base, the symmetric status is completely lost. We will produce a combined diff instead. Similar weirdness occurs if you use, e.g., "git diff C A...B D". Likewise, using multiple two-dot ranges, or tossing extra revision specifiers into the command line with two-dot ranges, or mixing two and three dot ranges, all produce nonsense. To avoid all this, add a routine to catch the range cases and verify that that the arguments make sense. As a side effect, produce a warning showing *which* merge base is being used when there are multiple choices; die if there is no merge base. Signed-off-by: Chris Torek <chris.torek@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
Chris Torek
5 years ago
committed by
Junio C Hamano
2 changed files with 202 additions and 13 deletions
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
#!/bin/sh |
||||
|
||||
test_description='behavior of diff with symmetric-diff setups' |
||||
|
||||
. ./test-lib.sh |
||||
|
||||
# build these situations: |
||||
# - normal merge with one merge base (br1...b2r); |
||||
# - criss-cross merge ie 2 merge bases (br1...master); |
||||
# - disjoint subgraph (orphan branch, br3...master). |
||||
# |
||||
# B---E <-- master |
||||
# / \ / |
||||
# A X |
||||
# \ / \ |
||||
# C---D--G <-- br1 |
||||
# \ / |
||||
# ---F <-- br2 |
||||
# |
||||
# H <-- br3 |
||||
# |
||||
# We put files into a few commits so that we can verify the |
||||
# output as well. |
||||
|
||||
test_expect_success setup ' |
||||
git commit --allow-empty -m A && |
||||
echo b >b && |
||||
git add b && |
||||
git commit -m B && |
||||
git checkout -b br1 HEAD^ && |
||||
echo c >c && |
||||
git add c && |
||||
git commit -m C && |
||||
git tag commit-C && |
||||
git merge -m D master && |
||||
git tag commit-D && |
||||
git checkout master && |
||||
git merge -m E commit-C && |
||||
git checkout -b br2 commit-C && |
||||
echo f >f && |
||||
git add f && |
||||
git commit -m F && |
||||
git checkout br1 && |
||||
git merge -m G br2 && |
||||
git checkout --orphan br3 && |
||||
git commit -m H |
||||
' |
||||
|
||||
test_expect_success 'diff with one merge base' ' |
||||
git diff commit-D...br1 >tmp && |
||||
tail -n 1 tmp >actual && |
||||
echo +f >expect && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
# The output (in tmp) can have +b or +c depending |
||||
# on which merge base (commit B or C) is picked. |
||||
# It should have one of those two, which comes out |
||||
# to seven lines. |
||||
test_expect_success 'diff with two merge bases' ' |
||||
git diff br1...master >tmp 2>err && |
||||
test_line_count = 7 tmp && |
||||
test_line_count = 1 err |
||||
' |
||||
|
||||
test_expect_success 'diff with no merge bases' ' |
||||
test_must_fail git diff br2...br3 >tmp 2>err && |
||||
test_i18ngrep "fatal: br2...br3: no merge base" err |
||||
' |
||||
|
||||
test_expect_success 'diff with too many symmetric differences' ' |
||||
test_must_fail git diff br1...master br2...br3 >tmp 2>err && |
||||
test_i18ngrep "usage" err |
||||
' |
||||
|
||||
test_expect_success 'diff with symmetric difference and extraneous arg' ' |
||||
test_must_fail git diff master br1...master >tmp 2>err && |
||||
test_i18ngrep "usage" err |
||||
' |
||||
|
||||
test_expect_success 'diff with two ranges' ' |
||||
test_must_fail git diff master br1..master br2..br3 >tmp 2>err && |
||||
test_i18ngrep "usage" err |
||||
' |
||||
|
||||
test_expect_success 'diff with ranges and extra arg' ' |
||||
test_must_fail git diff master br1..master commit-D >tmp 2>err && |
||||
test_i18ngrep "usage" err |
||||
' |
||||
|
||||
test_done |
Loading…
Reference in new issue