Re: [RFC/PATCH] ls-remote: optionally return non-zero on non-existing refs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 18, 2011 at 11:15 AM, Michael Schubert <mschub@xxxxxxxxxxxxx> wrote:
> 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@xxxxxxxxxxxxx>
> ---
>
> If there is just one existing ref in a list of non-exising refs, this will
> return zero though - as "git show-ref" does.
>
>
> ÂDocumentation/git-ls-remote.txt | Â Â7 ++++++-
> Âbuiltin/ls-remote.c       |  12 ++++++++++--
> Â2 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
> index c3df8c0..26cf705 100644
> --- a/Documentation/git-ls-remote.txt
> +++ b/Documentation/git-ls-remote.txt
> @@ -10,7 +10,7 @@ SYNOPSIS
> Â--------
> Â[verse]
> Â'git ls-remote' [--heads] [--tags] Â[-u <exec> | --upload-pack <exec>]
> - Â Â Â Â Â Â <repository> [<refs>...]
> + Â Â Â Â Â Â [-e|--exit-code] <repository> [<refs>...]
>
> ÂDESCRIPTION
> Â-----------
> @@ -36,6 +36,11 @@ OPTIONS
> Â Â Â ÂSSH and where the SSH daemon does not use the PATH configured by the
> Â Â Â Âuser.
>
> +-e::
> +--exit-code::
> + Â Â Â Exit with a non-zero status code when the specified references don't
> + Â Â Â exist.
> +
> Â<repository>::
> Â Â Â ÂLocation of the repository. ÂThe shorthand defined in
> Â Â Â Â$GIT_DIR/branches/ can be used. Use "." (dot) to list references in
> diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
> index 1a1ff87..99fcf6b 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 <exec> | --upload-pack <exec>]\n"
> -" Â Â Â Â Â Â Â Â Â Â [-q|--quiet] [<repository> [<refs>...]]";
> +" Â Â Â Â Â Â Â Â Â Â [-q|--quiet] [-e|--exit-code] [<repository> [<refs>...]]";
>
> Â/*
> Â* 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 exit_code = 0;
> Â Â Â Âconst char *uploadpack = NULL;
> Â Â Â Âconst char **pattern = NULL;
>
> @@ -74,6 +75,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âget_url = 1;
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âcontinue;
> Â Â Â Â Â Â Â Â Â Â Â Â}
> + Â Â Â Â Â Â Â Â Â Â Â if (!strcmp("--exit-code", arg) || !strcmp("-e", arg)) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â exit_code = 1;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
> + Â Â Â Â Â Â Â Â Â Â Â }
> Â Â Â Â Â Â Â Â Â Â Â Âusage(ls_remote_usage);
> Â Â Â Â Â Â Â Â}
> Â Â Â Â Â Â Â Âdest = arg;
> @@ -115,12 +120,15 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>
> Â Â Â Âif (!dest && !quiet)
> Â Â Â Â Â Â Â Âfprintf(stderr, "From %s\n", *remote->url);
> +
> Â Â Â Âfor ( ; ref; ref = ref->next) {
> Â Â Â Â Â Â Â Âif (!check_ref_type(ref, flags))
> Â Â Â Â Â Â Â Â Â Â Â Âcontinue;
> Â Â Â Â Â Â Â Âif (!tail_match(pattern, ref->name))
> Â Â Â Â Â Â Â Â Â Â Â Âcontinue;
>        Âprintf("%s   Â%s\n", sha1_to_hex(ref->old_sha1), ref->name);
> + Â Â Â Â Â Â Â exit_code = 0;
> Â Â Â Â}
> - Â Â Â return 0;
> +
> + Â Â Â return (exit_code) ? 2 : 0;

We know, just a small nitpick. The parentheses around exit_code are unnecessary.

> Â}
> --
> 1.7.5.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]