Subject: Re: `.git` symlink makes `git submodule add` fail

From: Vít Novotný <[email-masked]>
Date: Sat, 13 Feb 2016 05:20:09 +0100

On Fri, Feb 12, 2016 at 01:27:33PM -0500, Jeff King wrote:
> On Fri, Feb 12, 2016 at 10:19:38AM -0800, Junio C Hamano wrote:
> 
> > >> Is this a bug, or is the ability to symlink `.git` just a happy coincidence?
> > >
> > > It has never been supported.
> > 
> > Oops, hit "send" too early.
> > 
> > We have support for a "gitdir:" facility that would work even on a
> > filesystem that cannot do symlinks (see gitrepository-layout(5)),
> > and both the higher-level submodule Porcelain and the more recent
> > "worktree" experimental code do use it.
> 
> And the way to convince git to make the link for you is with clone's
> "--separate-git-dir" option.
> 
> -Peff

What's curious is that this doesn't really work either, so the issue
doesn't seem to be the lack of symlink support, but rather the lack of
willingness on the part of Git to resolve a path recursively.

The following works flawlessly:

  $ mkdir repos
  $ git init
  $ mv .git repos/repoA
  $ printf 'gitdir: repos/repoA\n' >.git
  $ git submodule add https://github.com/witiko/git-parallel

There is, however, a minor pain, which makes the repository unportable:

  $ cat git-parallel/.git
  gitdir: /tmp/foobar/repos/repoA/modules/git-parallel

When I change the gitdir symlink to a relative path, everything works
fine as long as I don't make Git go over two gitdir symlinks:

  $ sed -i 's#^/tmp/foobar#..#' git-parallel/.git
  $ git status
  [works]
  $ sed -i 's#repos/repoA#.git#' git-parallel/.git
  $ git status
  fatal: Not a git repository: git-parallel/../.git/modules/git-parallel

Clearly, Git resolves the first gitdir symlink:

  git-parallel/.git => git-parallel/../.git/modules/git-parallel

but refuses to resolve recursively:

  git-parallel/../.git/modules/git-parallel =>
  git-parallel/../repos/repoA/modules/git-parallel