Re: [RFC/PATCH] ls-remote: optionally return non-zero on non-existing refs
Michael Schubert <mschub@elegosoft.com> writes:
Show 9 quoted lines
> 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 <mschub@elegosoft.com>
> ---
>
> If there is just one existing ref in a list of non-exising refs, this will
> return zero though - as "git show-ref" does.
Show 14 quoted lines
> @@ -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;