@matheusbsbs / matheus-bagliano / commits / cefb2a5e39
Fork 0

ls-remote: print URL when no repo is specified

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>

Tay Ray Chuan committed May 12, 2010 at 01:20 UTC cefb2a5e39b165146aee3b093872721cc1155a87
2 files changed +29 -5
builtin/ls-remote.c
+9 -1
@@ -5,7 +5,7 @@
5
6 static const char ls_remote_usage[] =
7 "git ls-remote [--heads] [--tags] [-u <exec> | --upload-pack <exec>]\n"
8 -" [<repository> [<refs>...]]";
8 +" [-q|--quiet] [<repository> [<refs>...]]";
9
10 /*
11 * 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)
34 const char *dest = NULL;
35 int nongit;
36 unsigned flags = 0;
37 + int quiet = 0;
38 const char *uploadpack = NULL;
39 const char **pattern = NULL;
40
@@ -67,6 +68,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
68 flags |= REF_NORMAL;
69 continue;
70 }
71 + if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
72 + quiet = 1;
73 + continue;
74 + }
75 usage(ls_remote_usage);
76 }
77 dest = arg;
@@ -99,6 +104,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
104 ref = transport_get_remote_refs(transport);
105 if (transport_disconnect(transport))
106 return 1;
107 +
108 + if (!dest && !quiet)
109 + fprintf(stderr, "From %s\n", *remote->url);
110 for ( ; ref; ref = ref->next) {
111 if (!check_ref_type(ref, flags))
112 continue;
t/t5512-ls-remote.sh
+20 -4
@@ -57,12 +57,24 @@ test_expect_success 'dies when no remote specified and no default remotes found'
57
58 test_expect_success 'use "origin" when no remote specified' '
59
60 - git remote add origin "$(pwd)/.git" &&
61 - git ls-remote >actual &&
60 + URL="$(pwd)/.git" &&
61 + echo "From $URL" >exp_err &&
62 +
63 + git remote add origin "$URL" &&
64 + git ls-remote 2>actual_err >actual &&
65 +
66 + test_cmp exp_err actual_err &&
67 test_cmp expected.all actual
68
69 '
70
71 +test_expect_success 'suppress "From <url>" with -q' '
72 +
73 + git ls-remote -q 2>actual_err &&
74 + test_must_fail test_cmp exp_err actual_err
75 +
76 +'
77 +
78 test_expect_success 'use branch.<name>.remote if possible' '
79
80 #
@@ -78,10 +90,14 @@ test_expect_success 'use branch.<name>.remote if possible' '
90 git show-ref | sed -e "s/ / /"
91 ) >exp &&
92
81 - git remote add other other.git &&
93 + URL="other.git" &&
94 + echo "From $URL" >exp_err &&
95 +
96 + git remote add other $URL &&
97 git config branch.master.remote other &&
98
84 - git ls-remote >actual &&
99 + git ls-remote 2>actual_err >actual &&
100 + test_cmp exp_err actual_err &&
101 test_cmp exp actual
102
103 '