summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9c00de5)
raw | patch | inline | side by side (parent: 9c00de5)
author | Tay Ray Chuan <rctay89@gmail.com> | |
Tue, 11 May 2010 17:20:23 +0000 (01:20 +0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 12 May 2010 05:55:44 +0000 (22:55 -0700) |
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/ls-remote.c | patch | blob | history | |
t/t5512-ls-remote.sh | patch | blob | history |
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 8ee91eb547c2bafedd573045c977cc7d0469c95f..34480cfad6a8842d65ae61f6257c597a2a987b33 100644 (file)
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
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
const char *dest = NULL;
int nongit;
unsigned flags = 0;
+ int quiet = 0;
const char *uploadpack = NULL;
const char **pattern = NULL;
flags |= REF_NORMAL;
continue;
}
+ if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
+ quiet = 1;
+ continue;
+ }
usage(ls_remote_usage);
}
dest = arg;
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 3cf1b3da40a8d99631fabaa2cce4ff2b6d1b52ac..d1912351db7da4a7c457fd44895b5ea076c84e7e 100755 (executable)
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -57,12 +57,24 @@ 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" &&
+ echo "From $URL" >exp_err &&
+
+ git remote add origin "$URL" &&
+ git ls-remote 2>actual_err >actual &&
+
+ test_cmp exp_err 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 test_cmp exp_err actual_err
+
+'
+
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" &&
+ echo "From $URL" >exp_err &&
+
+ git remote add other $URL &&
git config branch.master.remote other &&
- git ls-remote >actual &&
+ git ls-remote 2>actual_err >actual &&
+ test_cmp exp_err actual_err &&
test_cmp exp actual
'