Before this patch, when "git rev-parse --verify" was passed at least one
good rev and then anything, it would output something for the good rev
even if it would latter exit on error.
With this patch, we only output something if everything is ok.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
static int abbrev;
static int output_sq;
static int abbrev;
static int output_sq;
-static int revs_count;
-
/*
* Some arguments are relevant "revision" arguments,
* others are about output format or other details.
/*
* Some arguments are relevant "revision" arguments,
* others are about output format or other details.
if (!(filter & DO_REVS))
return;
def = NULL;
if (!(filter & DO_REVS))
return;
def = NULL;
if (type != show_type)
putchar('^');
if (type != show_type)
putchar('^');
-static void show_default(void)
+static int show_default(void)
def = NULL;
if (!get_sha1(s, sha1)) {
show_rev(NORMAL, sha1, s);
def = NULL;
if (!get_sha1(s, sha1)) {
show_rev(NORMAL, sha1, s);
}
static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
}
static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
int cmd_rev_parse(int argc, const char **argv, const char *prefix)
{
int cmd_rev_parse(int argc, const char **argv, const char *prefix)
{
- int i, as_is = 0, verify = 0, quiet = 0;
+ int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
+ const char *name = NULL;
if (argc > 1 && !strcmp("--parseopt", argv[1]))
return cmd_parseopt(argc - 1, argv + 1, prefix);
if (argc > 1 && !strcmp("--parseopt", argv[1]))
return cmd_parseopt(argc - 1, argv + 1, prefix);
/* Not a flag argument */
if (try_difference(arg))
continue;
/* Not a flag argument */
if (try_difference(arg))
continue;
- if (!get_sha1(arg, sha1)) {
- show_rev(NORMAL, sha1, arg);
- continue;
+ name = arg;
+ type = NORMAL;
+ if (*arg == '^') {
+ name++;
+ type = REVERSED;
- if (*arg == '^' && !get_sha1(arg+1, sha1)) {
- show_rev(REVERSED, sha1, arg+1);
+ if (!get_sha1(name, sha1)) {
+ if (verify)
+ revs_count++;
+ else
+ show_rev(type, sha1, name);
continue;
verify_filename(prefix, arg);
}
continue;
verify_filename(prefix, arg);
}
- if (verify && revs_count == 1)
- return 0;
- show_default();
- if (verify && revs_count != 1)
+ if (verify) {
+ if (revs_count == 1) {
+ show_rev(type, sha1, name);
+ return 0;
+ } else if (revs_count == 0 && show_default())
+ return 0;
die_no_single_rev(quiet);
die_no_single_rev(quiet);
+ } else
+ show_default();
-test_expect_success '1 no stdout output on error' '
+test_expect_success 'no stdout output on error' '
test -z "$(git rev-parse --verify)" &&
test -z "$(git rev-parse --verify foo)" &&
test -z "$(git rev-parse --verify)" &&
test -z "$(git rev-parse --verify foo)" &&
- test -z "$(git rev-parse --verify baz HEAD)"
-'
-
-test_expect_failure '2 no stdout output on error' '
- test -z "$(git rev-parse --verify HEAD bar)"
-'
-
-test_expect_failure '3 no stdout output on error' '
+ test -z "$(git rev-parse --verify baz HEAD)" &&
+ test -z "$(git rev-parse --verify HEAD bar)" &&
test -z "$(git rev-parse --verify $HASH2 HEAD)"
'
test -z "$(git rev-parse --verify $HASH2 HEAD)"
'