From: Michael Schubert <mschub@elegosoft•com>
To: git@vger•kernel.org, Junio C Hamano <gitster@pobox•com>,
Kacper Kornet <draenog@pld-linux•org>
Subject: [PATCH v2] ls-remote: optionally return non-zero on non-existing refs
Date: Wed, 18 May 2011 22:06:00 +0200 [thread overview]
Message-ID: <4DD426A8.3010402@elegosoft.com> (raw)
In-Reply-To: <7v7h9ndfs9.fsf@alter.siamese.dyndns.org>
On 05/18/2011 08:28 PM, Junio C Hamano wrote:
> Michael Schubert <mschub@elegosoft•com> writes:
>
>> @@ -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;
Sure, got confused. Fixed.
-- >8 --
Subject: [PATCH] ls-remote: optionally return non-zero on non-existing refs
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>
---
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..01e362f 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 status = 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)) {
+ status = 2;
+ 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);
+ status = 0;
}
- return 0;
+
+ return status;
}
--
1.7.5.1
next prev parent reply other threads:[~2011-05-18 20:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-12 12:05 Exit code of git-ls-remote Kacper Kornet
2011-05-12 16:21 ` Junio C Hamano
2011-05-12 16:41 ` Junio C Hamano
2011-05-18 14:15 ` [RFC/PATCH] ls-remote: optionally return non-zero on non-existing refs Michael Schubert
2011-05-18 16:59 ` Thiago Farina
2011-05-18 18:28 ` Junio C Hamano
2011-05-18 20:06 ` Michael Schubert [this message]
2011-05-18 21:19 ` [PATCH v2] " Andreas Schwab
2011-05-18 21:38 ` Junio C Hamano
2011-05-18 21:53 ` Michael Schubert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DD426A8.3010402@elegosoft.com \
--to=mschub@elegosoft$(echo .)com \
--cc=draenog@pld-linux$(echo .)org \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox