[PATCH 5/5] builtin-remote: prune remotes correctly that were added with --mirror

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Johannes Schindelin
Date: Thursday, February 28, 2008 - 6:46 pm

This adds special handling for mirror remotes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin-remote.c  |   16 +++++++++++++---
 t/t5505-remote.sh |   16 ++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/builtin-remote.c b/builtin-remote.c
index d229919..3954926 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -396,12 +396,22 @@ static int show_or_prune(int argc, const char **argv, int prune)
 
 		if (prune) {
 			struct strbuf buf;
+			int prefix_len;
 
 			strbuf_init(&buf, 0);
+			if (states.remote->fetch_refspec_nr == 1 &&
+					states.remote->fetch->pattern &&
+					!strcmp(states.remote->fetch->src,
+						states.remote->fetch->dst))
+				/* handle --mirror remote */
+				strbuf_addstr(&buf, "refs/heads/");
+			else
+				strbuf_addf(&buf, "refs/remotes/%s/", *argv);
+			prefix_len = buf.len;
+
 			for (i = 0; i < states.stale.nr; i++) {
-				strbuf_reset(&buf);
-				strbuf_addf(&buf, "refs/remotes/%s/%s", *argv,
-						states.stale.items[i].path);
+				strbuf_setlen(&buf, prefix_len);
+				strbuf_addstr(&buf, states.stale.items[i].path);
 				result |= delete_ref(buf.buf, NULL);
 			}
 
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 5986982..0a25c8b 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -128,4 +128,20 @@ test_expect_success 'prune' '
 	 ! git rev-parse refs/remotes/origin/side)
 '
 
+test_expect_success 'add --mirror && prune' '
+	(mkdir mirror &&
+	 cd mirror &&
+	 git init &&
+	 git remote add --mirror -f origin ../one) &&
+	(cd one &&
+	 git branch -m side2 side) &&
+	(cd mirror &&
+	 git rev-parse --verify refs/heads/side2 &&
+	 ! git rev-parse --verify refs/heads/side &&
+	 git fetch origin &&
+	 git remote prune origin &&
+	 ! git rev-parse --verify refs/heads/side2 &&
+	 git rev-parse --verify refs/heads/side)
+'
+
 test_done
-- 
1.5.4.3.431.g066fa


--
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:
[PATCH 0/5] Builtin &quot;git remote&quot;, Johannes Schindelin, (Thu Feb 28, 6:44 pm)
[PATCH 1/5] path-list: add functions to work with unsorted ..., Johannes Schindelin, (Thu Feb 28, 6:44 pm)
[PATCH 2/5] parseopt: add flag to stop on first non option, Johannes Schindelin, (Thu Feb 28, 6:45 pm)
[PATCH 4/5] Make git-remote a builtin, Johannes Schindelin, (Thu Feb 28, 6:45 pm)
[PATCH 5/5] builtin-remote: prune remotes correctly that w ..., Johannes Schindelin, (Thu Feb 28, 6:46 pm)
Re: [PATCH 0/5] Builtin &quot;git remote&quot;, Junio C Hamano, (Thu Feb 28, 6:56 pm)
Re: [PATCH 0/5] Builtin &quot;git remote&quot;, Johannes Schindelin, (Thu Feb 28, 7:13 pm)
Re: [PATCH 1/5] path-list: add functions to work with unso ..., Johannes Schindelin, (Thu Feb 28, 7:15 pm)
Re: [PATCH 0/5] Builtin &quot;git remote&quot;, Daniel Barkalow, (Thu Feb 28, 7:17 pm)
Re: [PATCH 0/5] Builtin &quot;git remote&quot;, Johannes Schindelin, (Fri Feb 29, 4:21 am)
[PATCH 0/6] Builtin remote, v2, Johannes Schindelin, (Sat Mar 1, 6:14 am)
[PATCH 1/6] Rename path_list to string_list, Johannes Schindelin, (Sat Mar 1, 6:15 am)
[PATCH 2/6] string-list: add functions to work with unsort ..., Johannes Schindelin, (Sat Mar 1, 6:15 am)
[PATCH 3/6] parseopt: add flag to stop on first non option, Johannes Schindelin, (Sat Mar 1, 6:16 am)
[PATCH 5/6] Make git-remote a builtin, Johannes Schindelin, (Sat Mar 1, 6:16 am)
[PATCH 6/6] builtin-remote: prune remotes correctly that w ..., Johannes Schindelin, (Sat Mar 1, 6:17 am)
Re: [PATCH 0/5] Builtin &quot;git remote&quot;, Johannes Schindelin, (Sun Mar 2, 8:15 am)
Re: [PATCH 0/5] Builtin &quot;git remote&quot;, Johannes Schindelin, (Sun Mar 2, 8:40 am)
[PATCH 0/2] format-patch --cover-letter improvements, Johannes Schindelin, (Sun Mar 2, 8:52 am)
[PATCH 1/2] format-patch: use the diff options for the cov ..., Johannes Schindelin, (Sun Mar 2, 8:53 am)
[PATCH 2/2] format-patch: wrap cover-letter's shortlog sen ..., Johannes Schindelin, (Sun Mar 2, 8:53 am)
Re: [PATCH 2/2] format-patch: wrap cover-letter's shortlog ..., Johannes Schindelin, (Sun Mar 2, 10:38 am)