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

[RFC/PATCH] ignoring a fetch that overwrites local symref

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 11, 2012, 19:46 UTC
Message-ID
<7v62488j8a.fsf_-_@alter.siamese.dyndns.org>
In-Reply-To
<1271714912-56659-1-git-send-email-jaysoffian@gmail.com>
This is a companion to an ancient thread
    http://thread.gmane.org/gmane.comp.version-control.git/145311/focus=145337

in which an error was dealt with while pushing into a "mirror" repository that has a symbolic reference refs/remotes/origin/HEAD pointing at refs/remotes/origin/master with "git push --mirror". The issue was that the receiving end was told to update origin/HEAD and origin/master separately; if origin/HEAD is updated, that would update origin/master at the same time, and then when attempting to update origin/master, it would notice that it no longer has the expected old value and barf. After the series, we started ignoring such pushes to HEAD on the receiving end.

But you can suffer from a similar issue transferring objects in the opposite direction. If you run "fetch --mirror" in to such a "mirror" repository, the other side would advertise both 'master' and 'HEAD' under refs/remotes/origin/ hierarchy, and refs/*:refs/* wildcard would try to grab both of them.

Work it around by noticing a wildcard match that attempts to update a local symbolic ref and ignoring it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * While I do not think it is sane to have symbolic refs in the
   receiving ref hierarchy (e.g. refs/remotes/origin/) that has a
   matching ref in the corresponding ref hierarchy in the sending
   side (e.g. the same, or refs/heads/ if you are doing a mirror) in
   the first place, we addressed the issue brought by such a setting
   on the push side, so it is probably a good idea to do it on the
   fetch side.
   This is marked RFC as it cheats by ignoring symrefs that were not
   explicitly asked, instead of doing the "is the underlying thing
   going to be updated with the same operation?" logic the old patch
   did in da3efdb (receive-pack: detect aliased updates which can
   occur with symrefs, 2010-04-19). I think this simpler logic is
   sufficient but there may be corner cases that merit the more
   elaborate one, hence RFC.
 remote.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff --git i/remote.c w/remote.c
index 6aa49c0..ca1f8f2 100644
--- i/remote.c
+++ w/remote.c
@@ -1370,6 +1370,16 @@ int branch_merge_matches(struct branch *branch,
 	return refname_match(branch->merge[i]->src, refname, ref_fetch_rules);
 }
 
+static int ignore_symref_update(const char *refname)
+{
+	unsigned char sha1[20];
+	int flag;
+
+	if (!resolve_ref_unsafe(refname, sha1, 0, &flag))
+		return 0; /* non-existing refs are OK */
+	return (flag & REF_ISSYMREF);
+}
+
 static struct ref *get_expanded_map(const struct ref *remote_refs,
 				    const struct refspec *refspec)
 {
@@ -1383,7 +1393,8 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
 		if (strchr(ref->name, '^'))
 			continue; /* a dereference item */
 		if (match_name_with_pattern(refspec->src, ref->name,
-					    refspec->dst, &expn_name)) {
+					    refspec->dst, &expn_name) &&
+		    !ignore_symref_update(expn_name)) {
 			struct ref *cpy = copy_ref(ref);
 
 			cpy->peer_ref = alloc_ref(expn_name);
Previous: Jay SoffianNext: Junio C Hamano
Message 11 of 17 in “receive-pack: switch global variable 'commands' to a parameter”
  1. 1/2 receive-pack: switch global variable 'commands' to a parameterJay Soffian, Apr 19, 2010
  2. 2/2 receive-pack: detect aliased updates which can occur with symrefsJay Soffian, Apr 19, 2010
  3. Jay SoffianApr 19, 2010
  4. 2/2 receive-pack: detect aliased updates which can occur with symrefsJay Soffian, Apr 19, 2010
  5. Junio C HamanoApr 19, 2010
  6. Jay SoffianApr 19, 2010
  7. 0/3 js/maint-receive-pack-symref-aliasJay Soffian, Apr 19, 2010
  8. 1/3 receive-pack: switch global variable 'commands' to a parameterJay Soffian, Apr 19, 2010
  9. 2/3 t5516-fetch-push.sh: style cleanupJay Soffian, Apr 19, 2010
  10. 3/3 receive-pack: detect aliased updates which can occur with symrefsJay Soffian, Apr 19, 2010
  11. ignoring a fetch that overwrites local symrefJunio C Hamano, Dec 11, 2012
  12. fetch: ignore wildcarded refspecs that update local symbolic refsJunio C Hamano, Dec 11, 2012
  13. Jay SoffianDec 12, 2012
  14. Shawn PearceDec 12, 2012
  15. Junio C HamanoDec 12, 2012
  16. 3/3 receive-pack: detect aliased updates which can occur with symrefsJay Soffian, Apr 19, 2010
  17. Ævar Arnfjörð BjarmasonJun 10, 2010

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.