From: Junio C Hamano Date: Wed, 18 May 2011 18:28:38 GMT Subject: Re: [RFC/PATCH] ls-remote: optionally return non-zero on non-existing refs Message-ID: <7v7h9ndfs9.fsf@alter.siamese.dyndns.org> In-Reply-To: <4DD3D490.1090503@elegosoft.com> Michael Schubert writes: > git ls-remote returns zero no matter if the given references were found > or not. Teach ls-remote an option --exit-status to make it optionally > returning a non-zero status. > > Signed-off-by: Michael Schubert > --- > > If there is just one existing ref in a list of non-exising refs, this will > return zero though - as "git show-ref" does. That's Ok, but... > @@ -35,6 +35,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) > ... > + int exit_code = 0; > ... > @@ -74,6 +75,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) > ... > + if (!strcmp("--exit-code", arg) || !strcmp("-e", arg)) { > + exit_code = 1; > + continue; > ... > @@ -115,12 +120,15 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) > ... > + return (exit_code) ? 2 : 0; > } What is this insanity? Wouldn't it be a lot more straightforward to write it like this? int status = 0; ... if (!strcmp("--exit-code", arg)) { /* when we do not find any, return this value */ status = 2; continue; } ... return status;