зеркало из https://github.com/microsoft/git.git
t: teach test_cmp_rev to accept ! for not-equals
In the case where we are using test_cmp_rev() to report not-equals, we write `! test_cmp_rev`. However, since test_cmp_rev() contains r1=$(git rev-parse --verify "$1") && r2=$(git rev-parse --verify "$2") && `! test_cmp_rev` will succeed if any of the rev-parses fail. This behavior is not desired. We want the rev-parses to _always_ be successful. Rewrite test_cmp_rev() to optionally accept "!" as the first argument to do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !` in all tests to take advantage of this new functionality. Also, rewrite the rev-parse logic to end with a `|| return 1` instead of &&-chaining into the rev-comparison logic. This makes it obvious to future readers that we explicitly intend on returning early if either of the rev-parses fail. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
8cb7980382
Коммит
2c9e125b27
|
@ -438,7 +438,7 @@ test_expect_success 'git worktree add does not match remote' '
|
||||||
cd foo &&
|
cd foo &&
|
||||||
test_must_fail git config "branch.foo.remote" &&
|
test_must_fail git config "branch.foo.remote" &&
|
||||||
test_must_fail git config "branch.foo.merge" &&
|
test_must_fail git config "branch.foo.merge" &&
|
||||||
! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
|
test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -483,7 +483,7 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' '
|
||||||
cd foo &&
|
cd foo &&
|
||||||
test_must_fail git config "branch.foo.remote" &&
|
test_must_fail git config "branch.foo.remote" &&
|
||||||
test_must_fail git config "branch.foo.merge" &&
|
test_must_fail git config "branch.foo.merge" &&
|
||||||
! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
|
test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ test_expect_success 'rebase sets ORIG_HEAD to pre-rebase state' '
|
||||||
pre="$(git rev-parse --verify HEAD)" &&
|
pre="$(git rev-parse --verify HEAD)" &&
|
||||||
git rebase master &&
|
git rebase master &&
|
||||||
test_cmp_rev "$pre" ORIG_HEAD &&
|
test_cmp_rev "$pre" ORIG_HEAD &&
|
||||||
! test_cmp_rev "$pre" HEAD
|
test_cmp_rev ! "$pre" HEAD
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '
|
test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '
|
||||||
|
|
|
@ -61,7 +61,7 @@ test_run_rebase () {
|
||||||
test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" "
|
test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" "
|
||||||
reset_rebase &&
|
reset_rebase &&
|
||||||
git rebase $* -f b e &&
|
git rebase $* -f b e &&
|
||||||
! test_cmp_rev e HEAD &&
|
test_cmp_rev ! e HEAD &&
|
||||||
test_cmp_rev b HEAD~2 &&
|
test_cmp_rev b HEAD~2 &&
|
||||||
test_linear_range 'd e' b..
|
test_linear_range 'd e' b..
|
||||||
"
|
"
|
||||||
|
@ -78,7 +78,7 @@ test_run_rebase () {
|
||||||
test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
|
test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
|
||||||
reset_rebase &&
|
reset_rebase &&
|
||||||
git rebase $* -f branch-b branch-e &&
|
git rebase $* -f branch-b branch-e &&
|
||||||
! test_cmp_rev branch-e origin/branch-e &&
|
test_cmp_rev ! branch-e origin/branch-e &&
|
||||||
test_cmp_rev branch-b HEAD~2 &&
|
test_cmp_rev branch-b HEAD~2 &&
|
||||||
test_linear_range 'd e' branch-b..
|
test_linear_range 'd e' branch-b..
|
||||||
"
|
"
|
||||||
|
@ -368,7 +368,7 @@ test_run_rebase () {
|
||||||
test_expect_$result "rebase $* -f --root on linear history causes re-write" "
|
test_expect_$result "rebase $* -f --root on linear history causes re-write" "
|
||||||
reset_rebase &&
|
reset_rebase &&
|
||||||
git rebase $* -f --root c &&
|
git rebase $* -f --root c &&
|
||||||
! test_cmp_rev a HEAD~2 &&
|
test_cmp_rev ! a HEAD~2 &&
|
||||||
test_linear_range 'a b c' HEAD
|
test_linear_range 'a b c' HEAD
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
|
@ -346,7 +346,7 @@ test_expect_success 'A root commit can be a cousin, treat it that way' '
|
||||||
git merge --allow-unrelated-histories khnum &&
|
git merge --allow-unrelated-histories khnum &&
|
||||||
test_tick &&
|
test_tick &&
|
||||||
git rebase -f -r HEAD^ &&
|
git rebase -f -r HEAD^ &&
|
||||||
! test_cmp_rev HEAD^2 khnum &&
|
test_cmp_rev ! HEAD^2 khnum &&
|
||||||
test_cmp_graph HEAD^.. <<-\EOF &&
|
test_cmp_graph HEAD^.. <<-\EOF &&
|
||||||
* Merge branch '\''khnum'\'' into asherah
|
* Merge branch '\''khnum'\'' into asherah
|
||||||
|\
|
|\
|
||||||
|
|
|
@ -64,7 +64,7 @@ test_rebase_same_head_ () {
|
||||||
test_cmp_rev \$oldhead \$newhead
|
test_cmp_rev \$oldhead \$newhead
|
||||||
elif test $cmp = diff
|
elif test $cmp = diff
|
||||||
then
|
then
|
||||||
! test_cmp_rev \$oldhead \$newhead
|
test_cmp_rev ! \$oldhead \$newhead
|
||||||
fi
|
fi
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ test_expect_success 'cherry-pick on unborn branch' '
|
||||||
rm -rf * &&
|
rm -rf * &&
|
||||||
git cherry-pick initial &&
|
git cherry-pick initial &&
|
||||||
git diff --quiet initial &&
|
git diff --quiet initial &&
|
||||||
! test_cmp_rev initial HEAD
|
test_cmp_rev ! initial HEAD
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'cherry-pick "-" to pick from previous branch' '
|
test_expect_success 'cherry-pick "-" to pick from previous branch' '
|
||||||
|
|
|
@ -5,7 +5,7 @@ test_description='test cherry-picking many commits'
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
check_head_differs_from() {
|
check_head_differs_from() {
|
||||||
! test_cmp_rev HEAD "$1"
|
test_cmp_rev ! HEAD "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_head_equals() {
|
check_head_equals() {
|
||||||
|
|
|
@ -1012,19 +1012,30 @@ test_must_be_empty () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Tests that its two parameters refer to the same revision
|
# Tests that its two parameters refer to the same revision, or if '!' is
|
||||||
|
# provided first, that its other two parameters refer to different
|
||||||
|
# revisions.
|
||||||
test_cmp_rev () {
|
test_cmp_rev () {
|
||||||
|
local op='=' wrong_result=different
|
||||||
|
|
||||||
|
if test $# -ge 1 && test "x$1" = 'x!'
|
||||||
|
then
|
||||||
|
op='!='
|
||||||
|
wrong_result='the same'
|
||||||
|
shift
|
||||||
|
fi
|
||||||
if test $# != 2
|
if test $# != 2
|
||||||
then
|
then
|
||||||
error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
|
error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
|
||||||
else
|
else
|
||||||
local r1 r2
|
local r1 r2
|
||||||
r1=$(git rev-parse --verify "$1") &&
|
r1=$(git rev-parse --verify "$1") &&
|
||||||
r2=$(git rev-parse --verify "$2") &&
|
r2=$(git rev-parse --verify "$2") || return 1
|
||||||
if test "$r1" != "$r2"
|
|
||||||
|
if ! test "$r1" "$op" "$r2"
|
||||||
then
|
then
|
||||||
cat >&4 <<-EOF
|
cat >&4 <<-EOF
|
||||||
error: two revisions point to different objects:
|
error: two revisions point to $wrong_result objects:
|
||||||
'$1': $r1
|
'$1': $r1
|
||||||
'$2': $r2
|
'$2': $r2
|
||||||
EOF
|
EOF
|
||||||
|
|
Загрузка…
Ссылка в новой задаче