git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-09-20 13:22:24 +02:00
|
|
|
test_description='behavior of diff with symmetric-diff setups and --merge-base'
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
|
2020-11-19 00:44:27 +01:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-19 00:44:19 +01:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
# build these situations:
|
|
|
|
# - normal merge with one merge base (br1...b2r);
|
2020-11-19 00:44:27 +01:00
|
|
|
# - criss-cross merge ie 2 merge bases (br1...main);
|
|
|
|
# - disjoint subgraph (orphan branch, br3...main).
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
#
|
2020-11-19 00:44:27 +01:00
|
|
|
# B---E <-- main
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
# / \ /
|
|
|
|
# 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 &&
|
2020-11-19 00:44:27 +01:00
|
|
|
git merge -m D main &&
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
git tag commit-D &&
|
2020-11-19 00:44:27 +01:00
|
|
|
git checkout main &&
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
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' '
|
2020-11-19 00:44:27 +01:00
|
|
|
git diff br1...main >tmp 2>err &&
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
test_line_count = 7 tmp &&
|
|
|
|
test_line_count = 1 err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff with no merge bases' '
|
2020-09-17 09:44:05 +02:00
|
|
|
test_must_fail git diff br2...br3 2>err &&
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
test_i18ngrep "fatal: br2...br3: no merge base" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff with too many symmetric differences' '
|
2020-11-19 00:44:27 +01:00
|
|
|
test_must_fail git diff br1...main br2...br3 2>err &&
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
test_i18ngrep "usage" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff with symmetric difference and extraneous arg' '
|
2020-11-19 00:44:27 +01:00
|
|
|
test_must_fail git diff main br1...main 2>err &&
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
test_i18ngrep "usage" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff with two ranges' '
|
2020-11-19 00:44:27 +01:00
|
|
|
test_must_fail git diff main br1..main br2..br3 2>err &&
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
test_i18ngrep "usage" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff with ranges and extra arg' '
|
2020-11-19 00:44:27 +01:00
|
|
|
test_must_fail git diff main br1..main commit-D 2>err &&
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
test_i18ngrep "usage" err
|
|
|
|
'
|
|
|
|
|
2020-09-20 13:22:24 +02:00
|
|
|
test_expect_success 'diff --merge-base with no commits' '
|
|
|
|
test_must_fail git diff --merge-base
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff --merge-base with three commits' '
|
2020-11-19 00:44:27 +01:00
|
|
|
test_must_fail git diff --merge-base br1 br2 main 2>err &&
|
2020-09-20 13:22:24 +02:00
|
|
|
test_i18ngrep "usage" err
|
|
|
|
'
|
|
|
|
|
2020-09-20 13:22:25 +02:00
|
|
|
for cmd in diff-index diff
|
|
|
|
do
|
|
|
|
test_expect_success "$cmd --merge-base with one commit" '
|
2020-11-19 00:44:27 +01:00
|
|
|
git checkout main &&
|
2020-09-20 13:22:25 +02:00
|
|
|
git $cmd commit-C >expect &&
|
|
|
|
git $cmd --merge-base br2 >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$cmd --merge-base with one commit and unstaged changes" '
|
2020-11-19 00:44:27 +01:00
|
|
|
git checkout main &&
|
2020-09-20 13:22:25 +02:00
|
|
|
test_when_finished git reset --hard &&
|
|
|
|
echo unstaged >>c &&
|
|
|
|
git $cmd commit-C >expect &&
|
|
|
|
git $cmd --merge-base br2 >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$cmd --merge-base with one commit and staged and unstaged changes" '
|
2020-11-19 00:44:27 +01:00
|
|
|
git checkout main &&
|
2020-09-20 13:22:25 +02:00
|
|
|
test_when_finished git reset --hard &&
|
|
|
|
echo staged >>c &&
|
|
|
|
git add c &&
|
|
|
|
echo unstaged >>c &&
|
|
|
|
git $cmd commit-C >expect &&
|
|
|
|
git $cmd --merge-base br2 >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$cmd --merge-base --cached with one commit and staged and unstaged changes" '
|
2020-11-19 00:44:27 +01:00
|
|
|
git checkout main &&
|
2020-09-20 13:22:25 +02:00
|
|
|
test_when_finished git reset --hard &&
|
|
|
|
echo staged >>c &&
|
|
|
|
git add c &&
|
|
|
|
echo unstaged >>c &&
|
|
|
|
git $cmd --cached commit-C >expect &&
|
|
|
|
git $cmd --cached --merge-base br2 >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$cmd --merge-base with non-commit" '
|
2020-11-19 00:44:27 +01:00
|
|
|
git checkout main &&
|
|
|
|
test_must_fail git $cmd --merge-base main^{tree} 2>err &&
|
2020-09-20 13:22:25 +02:00
|
|
|
test_i18ngrep "fatal: --merge-base only works with commits" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$cmd --merge-base with no merge bases and one commit" '
|
2020-11-19 00:44:27 +01:00
|
|
|
git checkout main &&
|
2020-09-20 13:22:25 +02:00
|
|
|
test_must_fail git $cmd --merge-base br3 2>err &&
|
|
|
|
test_i18ngrep "fatal: no merge base found" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$cmd --merge-base with multiple merge bases and one commit" '
|
2020-11-19 00:44:27 +01:00
|
|
|
git checkout main &&
|
2020-09-20 13:22:25 +02:00
|
|
|
test_must_fail git $cmd --merge-base br1 2>err &&
|
|
|
|
test_i18ngrep "fatal: multiple merge bases found" err
|
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2020-09-14 20:36:52 +02:00
|
|
|
for cmd in diff-tree diff
|
|
|
|
do
|
|
|
|
test_expect_success "$cmd --merge-base with two commits" '
|
2020-11-19 00:44:27 +01:00
|
|
|
git $cmd commit-C main >expect &&
|
|
|
|
git $cmd --merge-base br2 main >actual &&
|
2020-09-14 20:36:52 +02:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$cmd --merge-base commit and non-commit" '
|
2020-11-19 00:44:27 +01:00
|
|
|
test_must_fail git $cmd --merge-base br2 main^{tree} 2>err &&
|
2020-09-14 20:36:52 +02:00
|
|
|
test_i18ngrep "fatal: --merge-base only works with commits" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$cmd --merge-base with no merge bases and two commits" '
|
|
|
|
test_must_fail git $cmd --merge-base br2 br3 2>err &&
|
|
|
|
test_i18ngrep "fatal: no merge base found" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$cmd --merge-base with multiple merge bases and two commits" '
|
2020-11-19 00:44:27 +01:00
|
|
|
test_must_fail git $cmd --merge-base main br1 2>err &&
|
2020-09-14 20:36:52 +02:00
|
|
|
test_i18ngrep "fatal: multiple merge bases found" err
|
|
|
|
'
|
|
|
|
done
|
|
|
|
|
|
|
|
test_expect_success 'diff-tree --merge-base with one commit' '
|
2020-11-19 00:44:27 +01:00
|
|
|
test_must_fail git diff-tree --merge-base main 2>err &&
|
2020-09-14 20:36:52 +02:00
|
|
|
test_i18ngrep "fatal: --merge-base only works with two commits" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff --merge-base with range' '
|
|
|
|
test_must_fail git diff --merge-base br2..br3 2>err &&
|
|
|
|
test_i18ngrep "fatal: --merge-base does not work with ranges" err
|
|
|
|
'
|
|
|
|
|
git diff: improve range handling
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>
2020-06-12 18:19:59 +02:00
|
|
|
test_done
|