git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 5, 2007, 19:02 UTC
Message-ID
<Pine.LNX.4.64.0712051902300.27959@racer.site>
In-Reply-To
<Pine.LNX.4.64.0712051858270.27959@racer.site>
This adds special handling for mirror remotes.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	This fixes a real bug in git-remote, which I tried to fix in the
	perl script, failing.
 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 41ac4a1..142eb97 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -367,12 +367,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 d343a96..2376e0a 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -131,4 +131,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.3.7.2157.g9598e
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 11 of 14 in “builtin-remote”
  1. 0/6 builtin-remoteJohannes Schindelin, Dec 5, 2007
  2. (unknown)Johannes Schindelin, Dec 5, 2007
  3. Johannes SchindelinDec 5, 2007
  4. 1/6 path-list: add functions to work with unsorted listsJohannes Schindelin, Dec 5, 2007
  5. 2/6 parseopt: add flag to stop on first non optionJohannes Schindelin, Dec 5, 2007
  6. 3/6 Test "git remote show" and "git remote prune"Johannes Schindelin, Dec 5, 2007
  7. René ScharfeDec 5, 2007
  8. Johannes SchindelinDec 5, 2007
  9. 4/6 Make git-remote a builtinJohannes Schindelin, Dec 5, 2007
  10. 7/6 builtin-remote: guard remote->url accesses by remote->url_nr checkJohannes Schindelin, Dec 5, 2007
  11. 5/6 builtin-remote: prune remotes correctly that were added with --mirrorJohannes Schindelin, Dec 5, 2007
  12. 6/6 DWIM "git add remote ..."Johannes Schindelin, Dec 5, 2007
  13. Linus TorvaldsDec 5, 2007
  14. Johannes SchindelinDec 5, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.