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

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>

Olivier Marin committed Jun 10, 2008 at 16:51 UTC 0ecfcb3b700e7e3097a55f015894ad75f1097090
3 files changed +41 -22
Documentation/git-remote.txt
+1 -1
@@ -12,7 +12,7 @@ SYNOPSIS
12 'git-remote' [-v | --verbose]
13 'git-remote' add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>
14 'git-remote' rm <name>
15 -'git-remote' show <name>
15 +'git-remote' show [-n] <name>
16 'git-remote' prune <name>
17 'git-remote' update [group]
18
builtin-remote.c
+23 -21
@@ -421,10 +421,10 @@ static void show_list(const char *title, struct path_list *list)
421
422 static int show_or_prune(int argc, const char **argv, int prune)
423 {
424 - int dry_run = 0, result = 0;
424 + int no_query = 0, result = 0;
425 struct option options[] = {
426 OPT_GROUP("show specific options"),
427 - OPT__DRY_RUN(&dry_run),
427 + OPT_BOOLEAN('n', NULL, &no_query, "do not query remotes"),
428 OPT_END()
429 };
430 struct ref_states states;
@@ -442,21 +442,23 @@ static int show_or_prune(int argc, const char **argv, int prune)
442 struct transport *transport;
443 const struct ref *ref;
444 struct strbuf buf;
445 - int i, got_states;
445 + int i;
446
447 states.remote = remote_get(*argv);
448 if (!states.remote)
449 return error("No such remote: %s", *argv);
450 - transport = transport_get(NULL, states.remote->url_nr > 0 ?
451 - states.remote->url[0] : NULL);
452 - ref = transport_get_remote_refs(transport);
453 - transport_disconnect(transport);
450
451 read_branches();
456 - got_states = get_ref_states(ref, &states);
457 - if (got_states)
458 - result = error("Error getting local info for '%s'",
459 - states.remote->name);
452 +
453 + if (!no_query) {
454 + transport = transport_get(NULL,
455 + states.remote->url_nr > 0 ?
456 + states.remote->url[0] : NULL);
457 + ref = transport_get_remote_refs(transport);
458 + transport_disconnect(transport);
459 +
460 + get_ref_states(ref, &states);
461 + }
462
463 if (prune) {
464 for (i = 0; i < states.stale.nr; i++) {
@@ -486,17 +488,17 @@ static int show_or_prune(int argc, const char **argv, int prune)
488 printf("\n");
489 }
490
489 - if (got_states)
490 - continue;
491 - strbuf_init(&buf, 0);
492 - strbuf_addf(&buf, " New remote branch%%s (next fetch will "
493 - "store in remotes/%s)", states.remote->name);
494 - show_list(buf.buf, &states.new);
495 - strbuf_release(&buf);
496 - show_list(" Stale tracking branch%s (use 'git remote prune')",
497 - &states.stale);
498 - show_list(" Tracked remote branch%s",
491 + if (!no_query) {
492 + strbuf_init(&buf, 0);
493 + strbuf_addf(&buf, " New remote branch%%s (next fetch "
494 + "will store in remotes/%s)", states.remote->name);
495 + show_list(buf.buf, &states.new);
496 + strbuf_release(&buf);
497 + show_list(" Stale tracking branch%s (use 'git remote "
498 + "prune')", &states.stale);
499 + show_list(" Tracked remote branch%s",
500 &states.tracked);
501 + }
502
503 if (states.remote->push_refspec_nr) {
504 printf(" Local branch%s pushed with 'git push'\n ",
t/t5505-remote.sh
+17
@@ -138,6 +138,23 @@ test_expect_success 'show' '
138 test_cmp expect output)
139 '
140
141 +cat > test/expect << EOF
142 +* remote origin
143 + URL: $(pwd)/one/.git
144 + Remote branch merged with 'git pull' while on branch master
145 + master
146 + Local branches pushed with 'git push'
147 + master:upstream +refs/tags/lastbackup
148 +EOF
149 +
150 +test_expect_success 'show -n' '
151 + (mv one one.unreachable &&
152 + cd test &&
153 + git remote show -n origin > output &&
154 + mv ../one.unreachable ../one &&
155 + test_cmp expect output)
156 +'
157 +
158 test_expect_success 'prune' '
159 (cd one &&
160 git branch -m side side2) &&