[PATCH v2] remote show: fix the -n option

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Junio C Hamano <gitster@...>
Cc: Johannes Schindelin <Johannes.Schindelin@...>, <git@...>
Date: Monday, June 9, 2008 - 11:58 am

From: Olivier Marin <dkr@freesurf.fr>

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>
---
 builtin-remote.c  |   44 +++++++++++++++++++++++---------------------
 t/t5505-remote.sh |   17 +++++++++++++++++
 2 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/builtin-remote.c b/builtin-remote.c
index c49f00f..efe74c7 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -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)
 {
-	int dry_run = 0, result = 0;
+	int no_query = 0, result = 0;
 	struct option options[] = {
 		OPT_GROUP("show specific options"),
-		OPT__DRY_RUN(&dry_run),
+		OPT_BOOLEAN('n', NULL, &no_query, "do not query remotes"),
 		OPT_END()
 	};
 	struct ref_states states;
@@ -442,21 +442,23 @@ static int show_or_prune(int argc, const char **argv, int prune)
 		struct transport *transport;
 		const struct ref *ref;
 		struct strbuf buf;
-		int i, got_states;
+		int i;
 
 		states.remote = remote_get(*argv);
 		if (!states.remote)
 			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();
-		got_states = get_ref_states(ref, &states);
-		if (got_states)
-			result = error("Error getting local info for '%s'",
-					states.remote->name);
+
+		if (!no_query) {
+			transport = transport_get(NULL,
+				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) {
 			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");
 		}
 
-		if (got_states)
-			continue;
-		strbuf_init(&buf, 0);
-		strbuf_addf(&buf, "  New remote branch%%s (next fetch will "
-			"store in remotes/%s)", states.remote->name);
-		show_list(buf.buf, &states.new);
-		strbuf_release(&buf);
-		show_list("  Stale tracking branch%s (use 'git remote prune')",
-				&states.stale);
-		show_list("  Tracked remote branch%s",
+		if (!no_query) {
+			strbuf_init(&buf, 0);
+			strbuf_addf(&buf, "  New remote branch%%s (next fetch "
+				"will store in remotes/%s)", states.remote->name);
+			show_list(buf.buf, &states.new);
+			strbuf_release(&buf);
+			show_list("  Stale tracking branch%s (use 'git remote "
+				"prune')", &states.stale);
+			show_list("  Tracked remote branch%s",
 				&states.tracked);
+		}
 
 		if (states.remote->push_refspec_nr) {
 			printf("  Local branch%s pushed with 'git push'\n   ",
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 0d7ed1f..c6a7bfb 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -138,6 +138,23 @@ test_expect_success 'show' '
 	 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' '
 	(cd one &&
 	 git branch -m side side2) &&
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
remote show/prune: strange -n(--dry-run) option., Olivier Marin, (Sat Jun 7, 8:54 pm)
[PATCH] remote show: fix the -n option, Olivier Marin, (Sun Jun 8, 8:48 pm)
[PATCH v2] remote show: fix the -n option, Olivier Marin, (Mon Jun 9, 11:58 am)
Re: [PATCH v2] remote show: fix the -n option, Johannes Schindelin, (Mon Jun 9, 12:35 pm)
Re: [PATCH v2] remote show: fix the -n option, Junio C Hamano, (Mon Jun 9, 9:10 pm)
[PATCH 0/4] remote show/prune improvement, Olivier Marin, (Tue Jun 10, 10:50 am)
Re: [PATCH 0/4] remote show/prune improvement, Jakub Narebski, (Tue Jun 10, 11:09 am)
Re: [PATCH 0/4] remote show/prune improvement, Olivier Marin, (Tue Jun 10, 12:10 pm)
Re: [PATCH 0/4] remote show/prune improvement, Jakub Narebski, (Tue Jun 10, 1:11 pm)
[PATCH 1/4] remote show: fix the -n option, Olivier Marin, (Tue Jun 10, 10:51 am)
Re: [PATCH v2] remote show: fix the -n option, Shawn O. Pearce, (Mon Jun 9, 9:19 pm)
Re: [PATCH v2] remote show: fix the -n option, Johannes Schindelin, (Mon Jun 9, 10:39 pm)
Re: [PATCH v2] remote show: fix the -n option, Olivier Marin, (Mon Jun 9, 12:58 pm)
Re: [PATCH v2] remote show: fix the -n option, Johannes Schindelin, (Mon Jun 9, 1:56 pm)
Re: [PATCH v2] remote show: fix the -n option, Olivier Marin, (Mon Jun 9, 2:37 pm)
[PATCH] builtin-remote: make reuse of code easier by not die..., Johannes Schindelin, (Mon Jun 9, 4:11 pm)
Re: [PATCH] remote show: fix the -n option, Johannes Schindelin, (Sun Jun 8, 9:16 pm)
Re: [PATCH] remote show: fix the -n option, Olivier Marin, (Sun Jun 8, 10:06 pm)
Re: [PATCH] remote show: fix the -n option, Johannes Schindelin, (Sun Jun 8, 10:35 pm)
Re: [PATCH] remote show: fix the -n option, Olivier Marin, (Mon Jun 9, 12:16 am)
Re: [PATCH] remote show: fix the -n option, Johannes Schindelin, (Mon Jun 9, 12:53 am)
Re: [PATCH] remote show: fix the -n option, Olivier Marin, (Mon Jun 9, 10:22 am)
Re: [PATCH] remote show: fix the -n option, Olivier Marin, (Mon Jun 9, 11:43 am)
Re: [PATCH] remote show: fix the -n option, Johannes Schindelin, (Mon Jun 9, 12:31 pm)