remote show: fix the -n option

The perl version accepted a -n flag, to show local informations only
without querying remote heads, that seems to have been lost in the C
revrite.

This restores the older behaviour and add a test case.

Signed-off-by: Olivier Marin <dkr@freesurf.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Olivier Marin 2008-06-10 16:51:08 +02:00 committed by Junio C Hamano
parent ea81e10ff4
commit 0ecfcb3b70
3 changed files with 41 additions and 22 deletions

View file

@ -12,7 +12,7 @@ SYNOPSIS
'git-remote' [-v | --verbose] 'git-remote' [-v | --verbose]
'git-remote' add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url> 'git-remote' add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>
'git-remote' rm <name> 'git-remote' rm <name>
'git-remote' show <name> 'git-remote' show [-n] <name>
'git-remote' prune <name> 'git-remote' prune <name>
'git-remote' update [group] 'git-remote' update [group]

View file

@ -421,10 +421,10 @@ static void show_list(const char *title, struct path_list *list)
static int show_or_prune(int argc, const char **argv, int prune) static int show_or_prune(int argc, const char **argv, int prune)
{ {
int dry_run = 0, result = 0; int no_query = 0, result = 0;
struct option options[] = { struct option options[] = {
OPT_GROUP("show specific options"), OPT_GROUP("show specific options"),
OPT__DRY_RUN(&dry_run), OPT_BOOLEAN('n', NULL, &no_query, "do not query remotes"),
OPT_END() OPT_END()
}; };
struct ref_states states; struct ref_states states;
@ -442,21 +442,23 @@ static int show_or_prune(int argc, const char **argv, int prune)
struct transport *transport; struct transport *transport;
const struct ref *ref; const struct ref *ref;
struct strbuf buf; struct strbuf buf;
int i, got_states; int i;
states.remote = remote_get(*argv); states.remote = remote_get(*argv);
if (!states.remote) if (!states.remote)
return error("No such remote: %s", *argv); return error("No such remote: %s", *argv);
transport = transport_get(NULL, states.remote->url_nr > 0 ?
states.remote->url[0] : NULL);
ref = transport_get_remote_refs(transport);
transport_disconnect(transport);
read_branches(); read_branches();
got_states = get_ref_states(ref, &states);
if (got_states) if (!no_query) {
result = error("Error getting local info for '%s'", transport = transport_get(NULL,
states.remote->name); states.remote->url_nr > 0 ?
states.remote->url[0] : NULL);
ref = transport_get_remote_refs(transport);
transport_disconnect(transport);
get_ref_states(ref, &states);
}
if (prune) { if (prune) {
for (i = 0; i < states.stale.nr; i++) { for (i = 0; i < states.stale.nr; i++) {
@ -486,17 +488,17 @@ static int show_or_prune(int argc, const char **argv, int prune)
printf("\n"); printf("\n");
} }
if (got_states) if (!no_query) {
continue; strbuf_init(&buf, 0);
strbuf_init(&buf, 0); strbuf_addf(&buf, " New remote branch%%s (next fetch "
strbuf_addf(&buf, " New remote branch%%s (next fetch will " "will store in remotes/%s)", states.remote->name);
"store in remotes/%s)", states.remote->name); show_list(buf.buf, &states.new);
show_list(buf.buf, &states.new); strbuf_release(&buf);
strbuf_release(&buf); show_list(" Stale tracking branch%s (use 'git remote "
show_list(" Stale tracking branch%s (use 'git remote prune')", "prune')", &states.stale);
&states.stale); show_list(" Tracked remote branch%s",
show_list(" Tracked remote branch%s",
&states.tracked); &states.tracked);
}
if (states.remote->push_refspec_nr) { if (states.remote->push_refspec_nr) {
printf(" Local branch%s pushed with 'git push'\n ", printf(" Local branch%s pushed with 'git push'\n ",

View file

@ -138,6 +138,23 @@ test_expect_success 'show' '
test_cmp expect output) test_cmp expect output)
' '
cat > test/expect << EOF
* remote origin
URL: $(pwd)/one/.git
Remote branch merged with 'git pull' while on branch master
master
Local branches pushed with 'git push'
master:upstream +refs/tags/lastbackup
EOF
test_expect_success 'show -n' '
(mv one one.unreachable &&
cd test &&
git remote show -n origin > output &&
mv ../one.unreachable ../one &&
test_cmp expect output)
'
test_expect_success 'prune' ' test_expect_success 'prune' '
(cd one && (cd one &&
git branch -m side side2) && git branch -m side side2) &&