Skip to content

Commit 003c6ab

Browse files
peffgitster
authored andcommitted
dwim_ref: fix dangling symref warning
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 460ccd0 commit 003c6ab

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

sha1_name.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
278278
*ref = xstrdup(r);
279279
if (!warn_ambiguous_refs)
280280
break;
281-
} else if ((flag & REF_ISSYMREF) &&
282-
(len != 4 || strcmp(str, "HEAD")))
281+
} else if ((flag & REF_ISSYMREF) && strcmp(fullref, "HEAD"))
283282
warning("ignoring dangling symref %s.", fullref);
284283
}
285284
free(last_branch);

0 commit comments

Comments
 (0)