Merge branch 'rc/ls-remote-default'

* rc/ls-remote-default:
  ls-remote: print URL when no repo is specified
This commit is contained in:
Junio C Hamano 2010-06-18 11:16:54 -07:00
commit 199d4c0d43
2 changed files with 29 additions and 5 deletions

View file

@ -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;

View file

@ -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' '
#
@ -78,10 +90,14 @@ 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
'