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

Re: [BUG?] git fetch -p -t prunes all non-tag refs

From
Carlos Martín Nieto <cmn@elego.de>
Date
Sep 26, 2011, 23:11 UTC
Message-ID
<1317078667.5579.13.camel@centaur.lab.cmartin.tk>
In-Reply-To
<7vehz30wdy.fsf@alter.siamese.dyndns.org>
On Mon, 2011-09-26 at 15:30 -0700, Junio C Hamano wrote:
Show 13 quoted lines
> Ben Boeckel <mathstuf@gmail.com> writes:
> 
> > When the --prune and --tags options are given to git fetch together, all
> > non-tag refs are pruned because only tags are looked at and when pruning
> > it appears as if the branches have disappeared and are therefore deleted
> > locally.
> 
> I would call that a bug, and it is not limited to the use of "--tags". For
> example, I suspect that
> 
>     $ git fetch --prune origin refs/heads/master:refs/remotes/origin/master
> 
> would prune remote tracking branches for "origin" other than "master".

This should fix it (in a way). Let's agree that it's a bad idea and complain to the user. Looking at the surrounding code, I can't find anything obvious that would break, and `git fetch --prune --multiple a b` is allowed.

Patch on top of maint.
--- 8< ---
Subject: [PATCH] fetch: disallow --prune in combination with tags or refspecs

Pruning shouldn't be used when other options limit the references that should be taken into account. For example

    git fetch --prune --tags origin
    git fetch --prune origin refs/heads/*:refs/remotes/*

Both these commands would remove references which do still exist in the remote.

Print an error and exit if prune is selected at the same time as either tags are selected or a refspec is given.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
---
 builtin/fetch.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index e422ced..158b20a 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -967,6 +967,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 			if (!add_remote_or_group(argv[i], &list))
 				die(_("No such remote or remote group: %s"), argv[i]);
 		result = fetch_multiple(&list);
+	} else if (prune && (argc == 2 || tags != TAGS_DEFAULT)) {
+		/* The if (multiple) is above so we don't report multiple remotes as an error */
+		die(_("Pruning and limiting refs is not compatible"));
 	} else {
 		/* Single remote or group */
 		(void) add_remote_or_group(argv[0], &list);
-- 
1.7.5.2.354.g349bf
Previous: Ben BoeckelNext: Junio C Hamano
Message 4 of 14 in “[BUG?] git fetch -p -t prunes all non-tag refs”
  1. Ben BoeckelSep 26, 2011
  2. Junio C HamanoSep 26, 2011
  3. Ben BoeckelSep 26, 2011
  4. Carlos Martín NietoSep 26, 2011
  5. Junio C HamanoSep 26, 2011
  6. Carlos Martín NietoSep 26, 2011
  7. Jeff KingSep 27, 2011
  8. Carlos Martín NietoOct 4, 2011
  9. Jeff KingOct 4, 2011
  10. Carlos Martín NietoOct 4, 2011
  11. 0/2 Be more careful when prunningCarlos Martín Nieto, Oct 6, 2011
  12. 1/2 fetch: free all the additional refspecsCarlos Martín Nieto, Oct 6, 2011
  13. 2/2 fetch: honor the user-provided refspecs when pruning refsCarlos Martín Nieto, Oct 6, 2011
  14. Junio C HamanoOct 7, 2011

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.