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

[PATCH] dwim_ref: fix dangling symref warning

From
Jeff King <peff@peff.net>
Date
Feb 16, 2010, 07:03 UTC
Message-ID
<20100216070315.GE2169@coredump.intra.peff.net>
In-Reply-To
<20100216064753.GD2169@coredump.intra.peff.net>

If we encounter a symref that is dangling, in most cases we will warn about it. The one exception is a dangling HEAD, as that indicates a branch yet to be born.

However, the check in dwim_ref was not quite right. If we were fed something like "HEAD^0" we would try to resolve "HEAD", see that it is dangling, and then check whether the _original_ string we got was "HEAD" (which it wasn't in this case). And that makes no sense; the dangling thing we found was not "HEAD^0" but rather "HEAD".

Fixing this squelches a scary warning from "submodule summary HEAD" (and consequently "git status" with status.submodulesummary set) in an empty repo, as the submodule script calls "git rev-parse -q --verify HEAD^0".

Signed-off-by: Jeff King <peff@peff.net>
---
 sha1_name.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 7729925..43884c6 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -280,8 +280,7 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
 				*ref = xstrdup(r);
 			if (!warn_ambiguous_refs)
 				break;
-		} else if ((flag & REF_ISSYMREF) &&
-			   (len != 4 || strcmp(str, "HEAD")))
+		} else if ((flag & REF_ISSYMREF) && strcmp(fullref, "HEAD"))
 			warning("ignoring dangling symref %s.", fullref);
 	}
 	free(last_branch);
-- 
1.7.0.25.g1cf14
Previous: Jeff KingNext: Jeff King
Message 5 of 8 in “Fatal error running status in new repo”
  1. Jacob HelwigFeb 16, 2010
  2. Jeff KingFeb 16, 2010
  3. Jacob HelwigFeb 16, 2010
  4. Jeff KingFeb 16, 2010
  5. dwim_ref: fix dangling symref warningJeff King, Feb 16, 2010
  6. Jeff KingFeb 16, 2010
  7. submodule summary: Don't barf when invoked in an empty repoJohan Herland, Feb 16, 2010
  8. Jeff KingFeb 17, 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.