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

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

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 29, 2008, 01:46 UTC
Message-ID
<alpine.LSU.1.00.0802290145550.22527@racer.site>
In-Reply-To
<alpine.LSU.1.00.0802290144130.22527@racer.site>
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
Previous: Johannes SchindelinNext: Junio C Hamano
Message 18 of 29 in “Builtin "git remote"”
  1. 0/5 Builtin "git remote"Johannes Schindelin, Feb 29, 2008
  2. 1/5 path-list: add functions to work with unsorted listsJohannes Schindelin, Feb 29, 2008
  3. Junio C HamanoFeb 29, 2008
  4. Johannes SchindelinFeb 29, 2008
  5. 0/6 Builtin remote, v2Johannes Schindelin, Mar 1, 2008
  6. 1/6 Rename path_list to string_listJohannes Schindelin, Mar 1, 2008
  7. David KågedalMar 11, 2008
  8. Johannes SchindelinMar 11, 2008
  9. David KågedalMar 11, 2008
  10. 2/6 string-list: add functions to work with unsorted listsJohannes Schindelin, Mar 1, 2008
  11. 3/6 parseopt: add flag to stop on first non optionJohannes Schindelin, Mar 1, 2008
  12. 4/6 Test "git remote show" and "git remote prune"Johannes Schindelin, Mar 1, 2008
  13. 5/6 Make git-remote a builtinJohannes Schindelin, Mar 1, 2008
  14. 6/6 builtin-remote: prune remotes correctly that were added with --mirrorJohannes Schindelin, Mar 1, 2008
  15. 2/5 parseopt: add flag to stop on first non optionJohannes Schindelin, Feb 29, 2008
  16. 3/5 Test "git remote show" and "git remote prune"Johannes Schindelin, Feb 29, 2008
  17. 4/5 Make git-remote a builtinJohannes Schindelin, Feb 29, 2008
  18. 5/5 builtin-remote: prune remotes correctly that were added with --mirrorJohannes Schindelin, Feb 29, 2008
  19. Junio C HamanoFeb 29, 2008
  20. Johannes SchindelinFeb 29, 2008
  21. Daniel BarkalowFeb 29, 2008
  22. Johannes SchindelinFeb 29, 2008
  23. Johannes SchindelinMar 2, 2008
  24. Johannes SchindelinMar 2, 2008
  25. 0/2 format-patch --cover-letter improvementsJohannes Schindelin, Mar 2, 2008
  26. 1/2 format-patch: use the diff options for the cover letter, tooJohannes Schindelin, Mar 2, 2008
  27. 2/2 format-patch: wrap cover-letter's shortlog sensiblyJohannes Schindelin, Mar 2, 2008
  28. Junio C HamanoMar 2, 2008
  29. Johannes SchindelinMar 2, 2008

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.