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

Re: [BUG] Incosistent repository state when trying to rename HEAD in the middle of a rebase

From
Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Date
Nov 2, 2017, 05:33 UTC
Message-ID
<1509600814.9254.6.camel@gmail.com>
In-Reply-To
<1509209933.2256.4.camel@gmail.com>
I was able to spare some time to dig into this and found a few things.

First, it seems that the issue is more generic and the BUG kicks in whenever HEAD is not a symbolic ref. I noticed that because when HEAD is a symbolic ref there was a change in the error message shown by git. In (2.11.0) I get this error message,

    error: refname refs/heads/HEAD not found
    fatal: Branch rename failed

while in the version build from 'next', I get the following error message,

    error: refname HEAD is a symbolic ref, renaming it is not supported
    fatal: Branch rename failed
    That made me suspicious and I wanted to find where the error message
    got changed and bisected this which pointed to,
    9416812db (branch: forbid refs/heads/HEAD, 2017-10-13)
    This is the same commit which also causes the bug of allowing HEAD to
    be renamed when it is not a symbolic ref. I found a way to fix this but
    am not so sure if it's the right way to do this. (the diff patch is
    found at the end of this mail).
    One more observation I made was that without the patch at the end it is
    NOT possible to rename a branch named "HEAD" created using the older
    version!
    On Sat, 2017-10-28 at 22:28 +0530, Kaartic Sivaraam wrote:
    >     git rebase-i HEAD~
> 
Small correction here. Now you could replace that with the simpler,
    git checkout HEAD^
diff --git a/sha1_name.c b/sha1_name.c
index c7c5ab376..4345e14c9 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1334,7 +1334,13 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
        strbuf_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
        if (name[0] == '-')
                return -1;
+
        strbuf_splice(sb, 0, 0, "refs/heads/", 11);
+
+       /* HEAD is not to be used as a branch name */
+       if(!strcmp(sb->buf, "refs/heads/HEAD"))
+               return -1;
+
        return check_refname_format(sb->buf, 0);
 }
 

HTH,
Kaartic
Previous: Kaartic SivaraamNext: Junio C Hamano
Message 2 of 4 in “[BUG] Incosistent repository state when trying to rename HEAD in the middle of a rebase”
  1. Kaartic SivaraamOct 28, 2017
  2. Kaartic SivaraamNov 2, 2017
  3. Junio C HamanoNov 2, 2017
  4. Kaartic SivaraamNov 3, 2017

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.