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

Re: [PATCH 4/6] remote prune: warn dangling symrefs

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 11, 2009, 17:30 UTC
Message-ID
<7vhc30g9ub.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20090209191526.GC27037@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 25 quoted lines
> On Mon, Feb 09, 2009 at 01:09:23AM -0800, Junio C Hamano wrote:
>
>> If you prune from the remote "frotz" that deleted the ref your tracking
>> branch remotes/frotz/HEAD points at, the symbolic ref will become
>> dangling.  We used to detect this as an error condition and issued a
>> message every time refs are enumerated.
>> 
>> This stops the error message, but moves the warning to "remote prune".
>
> Very nice. As a bonus, this fixes certain (admittedly unlikely) renames,
> too (which don't need to pass the BROKEN flag, since ref_rename uses
> get_loose_refs directly):
>
>   # without this patch
>   $ git symbolic-ref refs/heads/foo/bar refs/heads/nonexistant
>   $ git branch -m master foo
>   error: refs/heads/foo/bar points nowhere!
>   error: there are still refs under 'refs/heads/foo'
>   error: unable to lock refs/heads/foo for update
>   fatal: Branch rename failed
>
>   # with this patch
>   $ git branch -m master foo
>   error: 'refs/heads/foo/bar' exists; cannot create 'refs/heads/foo'
>   fatal: Branch rename failed

As a bonus, this issues unwarranted warning when creating the initial commit in an empty repository.

The following fixes it.
-- >8 --
Subject: [PATCH] Squelch overzealous "ignoring dangling symref" in an empty repository

057e713 (Warn use of "origin" when remotes/origin/HEAD is dangling, 2009-02-08) tried to warn dangling refs/remotes/origin/HEAD only when "origin" was used to refer to it. There was one corner case a symref is expected to be dangling and this warning is unwarranted: HEAD in an empty repository.

This squelches the warning for this special case.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 sha1_name.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 3bd2ef0..2f75179 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -278,7 +278,8 @@ 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)
+		} else if ((flag & REF_ISSYMREF) &&
+			   (len != 4 || strcmp(str, "HEAD")))
 			warning("ignoring dangling symref %s.", fullref);
 	}
 	free(last_branch);
-- 
1.6.2.rc0.55.g7a105
Previous: Jeff KingNext: Jeff King
Message 16 of 29 in “Deleting the "current" branch in remote bare repositories”
  1. Jan KrügerFeb 7, 2009
  2. Felipe ContrerasFeb 7, 2009
  3. Jan KrügerFeb 8, 2009
  4. Jeff KingFeb 8, 2009
  5. Junio C HamanoFeb 8, 2009
  6. Jeff KingFeb 8, 2009
  7. Junio C HamanoFeb 8, 2009
  8. 0/6 Deleting the "current" branch in a remote repositoryJunio C Hamano, Feb 9, 2009
  9. 1/6 builtin-receive-pack.c: do not initialize statics to 0Junio C Hamano, Feb 9, 2009
  10. 2/6 t5400: allow individual tests to failJunio C Hamano, Feb 9, 2009
  11. 3/6 receive-pack: receive.denyDeleteCurrentJunio C Hamano, Feb 9, 2009
  12. 4/6 remote prune: warn dangling symrefsJunio C Hamano, Feb 9, 2009
  13. 5/6 Warn use of "origin" when remotes/origin/HEAD is danglingJunio C Hamano, Feb 9, 2009
  14. 6/6 receive-pack: default receive.denyDeleteCurrent to refuseJunio C Hamano, Feb 9, 2009
  15. Jeff KingFeb 9, 2009
  16. Junio C HamanoFeb 11, 2009
  17. Jeff KingFeb 11, 2009
  18. Jeff KingFeb 11, 2009
  19. Jeff KingFeb 9, 2009
  20. Jeff KingFeb 9, 2009
  21. Junio C HamanoFeb 9, 2009
  22. Jeff KingFeb 10, 2009
  23. Junio C HamanoFeb 10, 2009
  24. Jeff KingFeb 9, 2009
  25. Junio C HamanoFeb 9, 2009
  26. Junio C HamanoFeb 9, 2009
  27. Jeff KingFeb 10, 2009
  28. Jeff KingFeb 9, 2009
  29. Jeff KingFeb 9, 2009

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.