rev-parse: fix using "--default" with "--verify"

Before this patch, something like:

$ git rev-parse --verify HEAD --default master

did not work, while:

$ git rev-parse --default master --verify HEAD

worked.

This patch fixes that, so that they both work (assuming
HEAD and master can be parsed).

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Christian Couder 2008-05-11 18:27:36 +02:00 committed by Junio C Hamano
parent 921df15f1d
commit 28bfa145e4
2 changed files with 7 additions and 6 deletions

View File

@ -583,6 +583,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue;
verify_filename(prefix, arg);
}
if (verify && revs_count == 1)
return 0;
show_default();
if (verify && revs_count != 1)
die_no_single_rev(quiet);

View File

@ -97,18 +97,17 @@ test_expect_failure '3 no stdout output on error' '
test -z "$(git rev-parse --verify $HASH2 HEAD)"
'
test_expect_success '1 with --default' '
test_expect_success 'use --default' '
git rev-parse --verify --default master &&
git rev-parse --verify --default master HEAD &&
git rev-parse --default master --verify &&
git rev-parse --default master --verify HEAD &&
git rev-parse --verify HEAD --default master &&
test_must_fail git rev-parse --verify foo --default master &&
test_must_fail git rev-parse --default HEAD --verify bar &&
test_must_fail git rev-parse --verify --default HEAD baz
'
test_expect_failure '2 with --default' '
git rev-parse --verify HEAD --default master
test_must_fail git rev-parse --verify --default HEAD baz &&
test_must_fail git rev-parse --default foo --verify &&
test_must_fail git rev-parse --verify --default bar
'
test_done