• J
    init: don't set core.worktree when initializing /.git · 84ccad8d
    Jeff King 提交于
    If you create a git repository in the root directory with
    "git init /", we erroneously write a core.worktree entry.
    This isn't _wrong_, in the sense that it's OK to set
    core.worktree when we don't need to. But it is unnecessarily
    surprising if you later move the .git directory to another
    path (which usually moves the relative working tree, but is
    foiled if there is an explicit worktree set).
    
    The problem is that we check whether core.worktree is
    necessary by seeing if we can make the git_dir by
    concatenating "/.git" onto the working tree. That would lead
    to "//.git" in this instance, but we actually have "/.git"
    (without the doubled slash).
    
    We can fix this by special-casing the root directory. I also
    split the logic out into its own function to make the
    conditional a bit more readable (and used skip_prefix, which
    I think makes it a little more obvious what is going on).
    
    No tests, as we would need to be able to write to "/" to do
    so. I did manually confirm that:
    
      sudo git init /
      cd /
      git rev-parse --show-toplevel
      git config core.worktree
    
    still finds the top-level correctly (as "/"), and does not
    set any core.worktree variable.
    Signed-off-by: NJeff King <peff@peff.net>
    Reviewed-by: NJonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    84ccad8d
init-db.c 16.2 KB