[PATCH 4/4] remote show: list tracked remote branches with -n

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Junio C Hamano <gitster@...>
Cc: Johannes Schindelin <Johannes.Schindelin@...>, Shawn O. Pearce <spearce@...>, <git@...>, Olivier Marin <dkr@...>
Date: Tuesday, June 10, 2008 - 10:51 am

From: Olivier Marin <dkr@freesurf.fr>

Signed-off-by: Olivier Marin <dkr@freesurf.fr>
---
 builtin-remote.c  |   25 +++++++++++++++++++++++--
 t/t5505-remote.sh |    3 ++-
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/builtin-remote.c b/builtin-remote.c
index 851bdde..de4a4f2 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -444,6 +444,25 @@ static int get_remote_ref_states(const char *name,
 	return 0;
 }
 
+static int append_ref_to_tracked_list(const char *refname,
+	const unsigned char *sha1, int flags, void *cb_data)
+{
+	struct ref_states *states = cb_data;
+	struct strbuf buf;
+
+	strbuf_init(&buf, 0);
+	strbuf_addf(&buf, "%s/", states->remote->name);
+	if (strncmp(buf.buf, refname, buf.len)) {
+		strbuf_release(&buf);
+		return 0;
+	}
+
+	path_list_append(skip_prefix(refname, strbuf_detach(&buf, NULL)),
+		&states->tracked);
+
+	return 0;
+}
+
 static int show(int argc, const char **argv)
 {
 	int no_query = 0, result = 0;
@@ -494,10 +513,12 @@ static int show(int argc, const char **argv)
 			strbuf_release(&buf);
 			show_list("  Stale tracking branch%s (use 'git remote "
 				"prune')", &states.stale);
-			show_list("  Tracked remote branch%s",
-				&states.tracked);
 		}
 
+		if (no_query)
+			for_each_remote_ref(append_ref_to_tracked_list, &states);
+		show_list("  Tracked remote branch%s", &states.tracked);
+
 		if (states.remote->push_refspec_nr) {
 			printf("  Local branch%s pushed with 'git push'\n   ",
 				states.remote->push_refspec_nr > 1 ?
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index c27cfad..ec5ea54 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -137,12 +137,13 @@ test_expect_success 'show' '
 	 git remote show origin > 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
+  Tracked remote branch
+    side
   Local branches pushed with 'git push'
     master:upstream +refs/tags/lastbackup
 EOF
-- 
1.5.6.rc2.160.gd660c

--
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 4/4] remote show: list tracked remote branches with -n, Olivier Marin, (Tue Jun 10, 10:51 am)
[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)