From a87247731e46255567ec58df940adb697e5b95a8 Mon Sep 17 00:00:00 2001 From: Michael Schubert Date: Wed, 18 May 2011 22:06:00 +0200 Subject: ls-remote: the --exit-code option reports "no matching refs" The "git ls-remote" uses its exit status to indicate if it successfully talked with the remote repository. A new option "--exit-code" makes the command exit with status "2" when there is no refs to be listed, even when the command successfully talked with the remote repository. This way, the caller can tell if we failed to contact the remote, or the remote did not have what we wanted to see. Of course, you can inspect the output from the command, which has been and will continue to be a valid way to check the same thing. Signed-off-by: Michael Schubert Signed-off-by: Junio C Hamano --- builtin/ls-remote.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'builtin/ls-remote.c') diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 1a1ff87e8f..10223092a9 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -5,7 +5,7 @@ static const char ls_remote_usage[] = "git ls-remote [--heads] [--tags] [-u | --upload-pack ]\n" -" [-q|--quiet] [ [...]]"; +" [-q|--quiet] [--exit-code] [ [...]]"; /* * Is there one among the list of patterns that match the tail part @@ -35,6 +35,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) unsigned flags = 0; int get_url = 0; int quiet = 0; + int status = 0; const char *uploadpack = NULL; const char **pattern = NULL; @@ -74,6 +75,11 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) get_url = 1; continue; } + if (!strcmp("--exit-code", arg)) { + /* return this code if no refs are reported */ + status = 2; + continue; + } usage(ls_remote_usage); } dest = arg; @@ -121,6 +127,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) if (!tail_match(pattern, ref->name)) continue; printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name); + status = 0; /* we found something */ } - return 0; + return status; } -- cgit v1.2.1