Skip to content

Commit 199d4c0

Browse files
committed
Merge branch 'rc/ls-remote-default'
* rc/ls-remote-default: ls-remote: print URL when no repo is specified
2 parents 6c6f878 + cefb2a5 commit 199d4c0

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

builtin/ls-remote.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
static const char ls_remote_usage[] =
77
"git ls-remote [--heads] [--tags] [-u <exec> | --upload-pack <exec>]\n"
8-
" [<repository> [<refs>...]]";
8+
" [-q|--quiet] [<repository> [<refs>...]]";
99

1010
/*
1111
* 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)
3434
const char *dest = NULL;
3535
int nongit;
3636
unsigned flags = 0;
37+
int quiet = 0;
3738
const char *uploadpack = NULL;
3839
const char **pattern = NULL;
3940

@@ -67,6 +68,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
6768
flags |= REF_NORMAL;
6869
continue;
6970
}
71+
if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
72+
quiet = 1;
73+
continue;
74+
}
7075
usage(ls_remote_usage);
7176
}
7277
dest = arg;
@@ -99,6 +104,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
99104
ref = transport_get_remote_refs(transport);
100105
if (transport_disconnect(transport))
101106
return 1;
107+
108+
if (!dest && !quiet)
109+
fprintf(stderr, "From %s\n", *remote->url);
102110
for ( ; ref; ref = ref->next) {
103111
if (!check_ref_type(ref, flags))
104112
continue;

t/t5512-ls-remote.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,24 @@ test_expect_success 'dies when no remote specified and no default remotes found'
5757

5858
test_expect_success 'use "origin" when no remote specified' '
5959
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 &&
6267
test_cmp expected.all actual
6368
6469
'
6570

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+
6678
test_expect_success 'use branch.<name>.remote if possible' '
6779
6880
#
@@ -78,10 +90,14 @@ test_expect_success 'use branch.<name>.remote if possible' '
7890
git show-ref | sed -e "s/ / /"
7991
) >exp &&
8092
81-
git remote add other other.git &&
93+
URL="other.git" &&
94+
echo "From $URL" >exp_err &&
95+
96+
git remote add other $URL &&
8297
git config branch.master.remote other &&
8398
84-
git ls-remote >actual &&
99+
git ls-remote 2>actual_err >actual &&
100+
test_cmp exp_err actual_err &&
85101
test_cmp exp actual
86102
87103
'

0 commit comments

Comments
 (0)