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

Re: Detached checkout will clobber branch head when using symlink HEAD

From
Jeff King <peff@peff.net>
Date
Oct 19, 2008, 13:00 UTC
Message-ID
<20081019130050.GA1822@coredump.intra.peff.net>
In-Reply-To
<7vfxmuhlad.fsf@gitster.siamese.dyndns.org>
On Fri, Oct 17, 2008 at 04:08:42PM -0700, Junio C Hamano wrote:
Show 20 quoted lines
> I do not think that is a correct approach.
> 
> The offending callchain is:
> 
>   update_ref(..., "HEAD", REF_NODEREF, ...);
>   -> lock_any_ref_for_update("HEAD", ..., REF_NODEREF);
>    -> lock_ref_sha1_basic("HEAD", ..., REF_NODEREF, ...);
>       . calls resolve_ref() to read HEAD to arrive at
>         refs/heads/master
>       . however, it notices REF_NODEREF and adjusts the ref to be updated
>         back to "HEAD";
>     -> hold_lock_file_for_update(..., "HEAD", 1);
>      -> lock_file(..., "HEAD");
>         . resolves symlink "HEAD" to "refs/heads/master", and
>           locks it!  This creates "refs/heads/master.lock", that is
>           then renamed to "refs/heads/master" when unlocked.
> 
> In other words, the breakage is in lock_file() and not in resolve_ref().
> The latter gives the same output to the caller whether the HEAD is
> symbolic link or textual symref -- at least it should.

To be fair, my patch fixed the problem in lock_ref_sha1_basic, not resolve_ref. It merely asked resolve_ref to annotate the resolution to show whether a symlink was found, since it already had that information.

But if I am reading your patch right, you are actually enabling detached HEAD in this instance, which is much better. Unfortunately, I had quite a few conflicts in applying your patches on top of master (with or without the patch from "checkout --track -b broken"), and when I thought I had fixed up the result, the test actually still failed.

So I will take your word that it actually works, and that I screwed up resolving the conflicts.

-Peff

PS If you are rebasing or resolving anyway, as I suspect you will have to, there is a typo in the test: s/detch/detach/

Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 15 in “Detached checkout will clobber branch head when using symlink HEAD”
  1. Matt DraiseyOct 15, 2008
  2. Jeff KingOct 16, 2008
  3. Matt DraiseyOct 16, 2008
  4. Nicolas PitreOct 16, 2008
  5. Jeff KingOct 16, 2008
  6. Nicolas PitreOct 16, 2008
  7. Matt DraiseyOct 16, 2008
  8. Nicolas PitreOct 16, 2008
  9. Jeff KingOct 16, 2008
  10. Junio C HamanoOct 17, 2008
  11. 1/3 demonstrate breakage of detached checkout with symbolic link HEADJunio C Hamano, Oct 17, 2008
  12. 2/3 Enhance hold_lock_file_for_{update,append}() APIJunio C Hamano, Oct 17, 2008
  13. 3/3 Fix checkout not to clobber the branch when using symlinked HEAD upon detachingJunio C Hamano, Oct 17, 2008
  14. Jeff KingOct 19, 2008
  15. Junio C HamanoOct 19, 2008

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.