From: Tay Ray Chuan <rctay89@gmail.com>
To: "Git Mailing List" <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
Jonathan Nieder <jrnieder@gmail.com>
Subject: [PATCH] ls-remote: print URL when no repo is specified
Date: Sun, 9 May 2010 22:42:20 +0800 [thread overview]
Message-ID: <1273416140-5044-1-git-send-email-rctay89@gmail.com> (raw)
After 9c00de5 (ls-remote: fall-back to default remotes when no remote
specified), when no repository is specified, ls-remote may use
the URL/remote in the config "branch.<name>.remote" or the remote
"origin"; it may not be immediately obvious to the user which was used.
In such cases, print a simple "From <URL>" line to indicate which
repository was used. This message is similar to git-fetch's, and is
printed to stderr to avoid breaking existing scripts that depend on
ls-remote's output behaviour.
It can also be disabled with -q/--quiet.
Modify tests related to falling back on default remotes to check for
this as well, and add a test to check for suppression of the message.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
This is a logical follow-up to the "optional repo" form of ls-remote
feature. Myself, I was using the "no-repo" form of ls-remote and
sometimes wondered where it was listing remotes from.
Johnathan, do you think the tests involved might have any cross-
platform issues?
builtin/ls-remote.c | 10 +++++++++-
t/t5512-ls-remote.sh | 19 +++++++++++++++----
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 8ee91eb..34480cf 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"
-" [<repository> [<refs>...]]";
+" [-q|--quiet] [<repository> [<refs>...]]";
/*
* Is there one among the list of patterns that match the tail part
@@ -34,6 +34,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
const char *dest = NULL;
int nongit;
unsigned flags = 0;
+ int quiet = 0;
const char *uploadpack = NULL;
const char **pattern = NULL;
@@ -67,6 +68,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
flags |= REF_NORMAL;
continue;
}
+ if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
+ quiet = 1;
+ continue;
+ }
usage(ls_remote_usage);
}
dest = arg;
@@ -99,6 +104,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
ref = transport_get_remote_refs(transport);
if (transport_disconnect(transport))
return 1;
+
+ if (!dest && !quiet)
+ fprintf(stderr, "From %s\n", *remote->url);
for ( ; ref; ref = ref->next) {
if (!check_ref_type(ref, flags))
continue;
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 3cf1b3d..8508df8 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -57,12 +57,21 @@ test_expect_success 'dies when no remote specified and no default remotes found'
test_expect_success 'use "origin" when no remote specified' '
- git remote add origin "$(pwd)/.git" &&
- git ls-remote >actual &&
+ URL="$(pwd)/.git" &&
+ git remote add origin "$URL" &&
+ git ls-remote 2>actual_err >actual &&
+ grep "From $URL" actual_err &&
test_cmp expected.all actual
'
+test_expect_success 'suppress "From <url>" with -q' '
+
+ git ls-remote -q 2>actual_err &&
+ test_must_fail grep "From $URL" actual_err
+
+'
+
test_expect_success 'use branch.<name>.remote if possible' '
#
@@ -78,10 +87,12 @@ test_expect_success 'use branch.<name>.remote if possible' '
git show-ref | sed -e "s/ / /"
) >exp &&
- git remote add other other.git &&
+ URL="other.git" &&
+ git remote add other $URL &&
git config branch.master.remote other &&
- git ls-remote >actual &&
+ git ls-remote 2>actual_err >actual &&
+ grep "From $URL" actual_err &&
test_cmp exp actual
'
--
1.7.1.189.g07419
next reply other threads:[~2010-05-09 14:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-09 14:42 Tay Ray Chuan [this message]
2010-05-09 22:01 ` [PATCH] ls-remote: print URL when no repo is specified Jonathan Nieder
2010-05-11 17:20 ` [PATCH v2] " Tay Ray Chuan
2010-05-12 5:50 ` Junio C Hamano
2010-05-14 3:07 ` Tay Ray Chuan
2010-05-14 16:17 ` Jonathan Nieder
2010-05-15 9:56 ` Tay Ray Chuan
2010-05-15 16:20 ` Jonathan Nieder
2010-05-20 13:27 ` Junio C Hamano
2010-05-16 2:14 ` Geert Bosch
2010-05-16 10:36 ` Sverre Rabbelier
2010-05-16 17:27 ` Geert Bosch
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=1273416140-5044-1-git-send-email-rctay89@gmail.com \
--to=rctay89@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).