git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Matt Draisey <matt@draisey.ca>, git@vger.kernel.org
Subject: Re: Detached checkout will clobber branch head when using symlink HEAD
Date: Fri, 17 Oct 2008 16:08:42 -0700	[thread overview]
Message-ID: <7vfxmuhlad.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 20081016203916.GB9487@coredump.intra.peff.net

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.

The behaviour of lock_file() to resolve symlink at this point in the code
comes from d58e8d3 (When locking in a symlinked repository, try to lock
the original, 2007-07-25), and as explained in the log message of that
commit, we cannot unconditionally remove it.

Three patches to fix this issue, that come on top of the fix to t7201
(--track from detached HEAD should fail) I sent out last night, will
follow.

  reply	other threads:[~2008-10-17 23:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-15 18:24 Detached checkout will clobber branch head when using symlink HEAD Matt Draisey
2008-10-16 19:17 ` Jeff King
2008-10-16 20:11   ` Matt Draisey
2008-10-16 20:20     ` Nicolas Pitre
2008-10-16 20:22       ` Jeff King
2008-10-16 20:30         ` Nicolas Pitre
2008-10-16 20:28       ` Matt Draisey
2008-10-16 20:47         ` Nicolas Pitre
2008-10-16 20:39     ` Jeff King
2008-10-17 23:08       ` Junio C Hamano [this message]
2008-10-17 23:10         ` [PATCH 1/3] demonstrate breakage of detached checkout with symbolic link HEAD Junio C Hamano
2008-10-17 23:10         ` [PATCH 2/3] Enhance hold_lock_file_for_{update,append}() API Junio C Hamano
2008-10-17 23:11         ` [PATCH 3/3] Fix checkout not to clobber the branch when using symlinked HEAD upon detaching Junio C Hamano
2008-10-19 13:00         ` Detached checkout will clobber branch head when using symlink HEAD Jeff King
2008-10-19 19:36           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vfxmuhlad.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=matt@draisey.ca \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).