{"thread":{"id":"41401","subject":"`.git` symlink makes `git submodule add` fail","startedAt":"2016-02-12T16:48:54Z","lastAt":"2016-02-13T18:52:52Z","messageCount":7,"participants":["Vít Novotný","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"278016","messageId":"20160212164853.GA6888@witiko","threadId":"41401","inReplyTo":null,"subject":"`.git` symlink makes `git submodule add` fail","fromName":"Vít Novotný","fromEmail":"witiko@gmail.com","sentAt":"2016-02-12T16:48:54Z","receivedAt":"2016-02-12T16:48:54Z","isPatch":false,"sender":{"key":"witiko@gmail.com","avatar":"https://gravatar.com/avatar/730ffcf9570c705f488d865576f9aec510d559e847d15a5b7f3d98140fba5bb4?d=mp&s=160"},"body":"Hi,\n\n\t$ uname -a\n\tLinux witiko 4.3.0-1-amd64 #1 SMP Debian 4.3.5-1 (2016-02-06) x86_64 GNU/Linux\n\t$ git --version\n\tgit version 2.7.0\n\nI tend to make `.git` a symlink, when I need to maintain several Git\nrepositories inside a single directory. This was always transparent to Git, but\nproblems arose, when working with submodules:\n\n\t$ mkdir -p .repos/repoA\n\t$ ln -s .repos/repoA .git\n\t$ git init\n\tInitialized empty Git repository in /tmp/tmp.q3hkme6nm4/.repos/repoA/\n\t$ git submodule add https://github.com/witiko/git-parallel\n\tCloning into 'git-parallel'...\n\tremote: Counting objects: 212, done.\n\tremote: Compressing objects: 100% (16/16), done.\n\tremote: Total 212 (delta 6), reused 1 (delta 1), pack-reused 195\n\tReceiving objects: 100% (212/212), 64.20 KiB | 0 bytes/s, done.\n\tResolving deltas: 100% (120/120), done.\n\tChecking connectivity... done.\n\tfatal: Could not chdir to '../../../git-parallel': No such file or directory\n\tUnable to checkout submodule 'git-parallel'\n\nIs this a bug, or is the ability to symlink `.git` just a happy coincidence?\n\nBest Regards,\nVít\n"},{"id":"278019","messageId":"xmqqio1tvlzu.fsf@gitster.mtv.corp.google.com","threadId":"41401","inReplyTo":"20160212164853.GA6888@witiko","subject":"Re: `.git` symlink makes `git submodule add` fail","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-02-12T18:09:41Z","receivedAt":"2016-02-12T18:09:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Vít Novotný <witiko@gmail.com> writes:\n\n> Is this a bug, or is the ability to symlink `.git` just a happy coincidence?\n\nIt has never been supported.\n"},{"id":"278021","messageId":"xmqq60xtvlj9.fsf@gitster.mtv.corp.google.com","threadId":"41401","inReplyTo":"xmqqio1tvlzu.fsf@gitster.mtv.corp.google.com","subject":"Re: `.git` symlink makes `git submodule add` fail","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-02-12T18:19:38Z","receivedAt":"2016-02-12T18:19:38Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Vít Novotný <witiko@gmail.com> writes:\n>\n>> Is this a bug, or is the ability to symlink `.git` just a happy coincidence?\n>\n> It has never been supported.\n\nOops, hit \"send\" too early.\n\nWe have support for a \"gitdir:\" facility that would work even on a\nfilesystem that cannot do symlinks (see gitrepository-layout(5)),\nand both the higher-level submodule Porcelain and the more recent\n\"worktree\" experimental code do use it.\n"},{"id":"278022","messageId":"20160212182733.GA19973@sigill.intra.peff.net","threadId":"41401","inReplyTo":"xmqq60xtvlj9.fsf@gitster.mtv.corp.google.com","subject":"Re: `.git` symlink makes `git submodule add` fail","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-02-12T18:27:33Z","receivedAt":"2016-02-12T18:27:33Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Feb 12, 2016 at 10:19:38AM -0800, Junio C Hamano wrote:\n\n> >> Is this a bug, or is the ability to symlink `.git` just a happy coincidence?\n> >\n> > It has never been supported.\n> \n> Oops, hit \"send\" too early.\n> \n> We have support for a \"gitdir:\" facility that would work even on a\n> filesystem that cannot do symlinks (see gitrepository-layout(5)),\n> and both the higher-level submodule Porcelain and the more recent\n> \"worktree\" experimental code do use it.\n\nAnd the way to convince git to make the link for you is with clone's\n\"--separate-git-dir\" option.\n\n-Peff\n"},{"id":"278024","messageId":"20160212183646.GA6261@witiko","threadId":"41401","inReplyTo":"xmqq60xtvlj9.fsf@gitster.mtv.corp.google.com","subject":"Re: `.git` symlink makes `git submodule add` fail","fromName":"Vít Novotný","fromEmail":"witiko@gmail.com","sentAt":"2016-02-12T18:36:47Z","receivedAt":"2016-02-12T18:36:47Z","isPatch":false,"sender":{"key":"witiko@gmail.com","avatar":"https://gravatar.com/avatar/730ffcf9570c705f488d865576f9aec510d559e847d15a5b7f3d98140fba5bb4?d=mp&s=160"},"body":"On Fri, Feb 12, 2016 at 10:19:38AM -0800, Junio C Hamano wrote:\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n> > Vít Novotný <witiko@gmail.com> writes:\n> >\n> >> Is this a bug, or is the ability to symlink `.git` just a happy coincidence?\n> >\n> > It has never been supported.\n> \n> Oops, hit \"send\" too early.\n> \n> We have support for a \"gitdir:\" facility that would work even on a\n> filesystem that cannot do symlinks (see gitrepository-layout(5)),\n> and both the higher-level submodule Porcelain and the more recent\n> \"worktree\" experimental code do use it.\n> \n\nThat sounds ideal, thank you for letting me know. Still, I believe that\nwell-behaved applications should be indifferent to symlinks, unless the\ndistinction is significant. Would there be any objections, if I\nsubmitted a patch / series of patches that would add proper symlink\nsupport?\n"},{"id":"278063","messageId":"20160213042008.GA26677@witiko","threadId":"41401","inReplyTo":"20160212182733.GA19973@sigill.intra.peff.net","subject":"Re: `.git` symlink makes `git submodule add` fail","fromName":"Vít Novotný","fromEmail":"witiko@gmail.com","sentAt":"2016-02-13T04:20:09Z","receivedAt":"2016-02-13T04:20:09Z","isPatch":false,"sender":{"key":"witiko@gmail.com","avatar":"https://gravatar.com/avatar/730ffcf9570c705f488d865576f9aec510d559e847d15a5b7f3d98140fba5bb4?d=mp&s=160"},"body":"On Fri, Feb 12, 2016 at 01:27:33PM -0500, Jeff King wrote:\n> On Fri, Feb 12, 2016 at 10:19:38AM -0800, Junio C Hamano wrote:\n> \n> > >> Is this a bug, or is the ability to symlink `.git` just a happy coincidence?\n> > >\n> > > It has never been supported.\n> > \n> > Oops, hit \"send\" too early.\n> > \n> > We have support for a \"gitdir:\" facility that would work even on a\n> > filesystem that cannot do symlinks (see gitrepository-layout(5)),\n> > and both the higher-level submodule Porcelain and the more recent\n> > \"worktree\" experimental code do use it.\n> \n> And the way to convince git to make the link for you is with clone's\n> \"--separate-git-dir\" option.\n> \n> -Peff\n\nWhat's curious is that this doesn't really work either, so the issue\ndoesn't seem to be the lack of symlink support, but rather the lack of\nwillingness on the part of Git to resolve a path recursively.\n\nThe following works flawlessly:\n\n  $ mkdir repos\n  $ git init\n  $ mv .git repos/repoA\n  $ printf 'gitdir: repos/repoA\\n' >.git\n  $ git submodule add https://github.com/witiko/git-parallel\n\nThere is, however, a minor pain, which makes the repository unportable:\n\n  $ cat git-parallel/.git\n  gitdir: /tmp/foobar/repos/repoA/modules/git-parallel\n\nWhen I change the gitdir symlink to a relative path, everything works\nfine as long as I don't make Git go over two gitdir symlinks:\n\n  $ sed -i 's#^/tmp/foobar#..#' git-parallel/.git\n  $ git status\n  [works]\n  $ sed -i 's#repos/repoA#.git#' git-parallel/.git\n  $ git status\n  fatal: Not a git repository: git-parallel/../.git/modules/git-parallel\n\nClearly, Git resolves the first gitdir symlink:\n\n  git-parallel/.git => git-parallel/../.git/modules/git-parallel\n\nbut refuses to resolve recursively:\n\n  git-parallel/../.git/modules/git-parallel =>\n  git-parallel/../repos/repoA/modules/git-parallel\n"},{"id":"278083","messageId":"20160213185252.GA10063@sigill.intra.peff.net","threadId":"41401","inReplyTo":"20160213042008.GA26677@witiko","subject":"Re: `.git` symlink makes `git submodule add` fail","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-02-13T18:52:52Z","receivedAt":"2016-02-13T18:52:52Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Feb 13, 2016 at 05:20:09AM +0100, Vít Novotný wrote:\n\n> On Fri, Feb 12, 2016 at 01:27:33PM -0500, Jeff King wrote:\n> > On Fri, Feb 12, 2016 at 10:19:38AM -0800, Junio C Hamano wrote:\n> > \n> > > >> Is this a bug, or is the ability to symlink `.git` just a happy coincidence?\n> > > >\n> > > > It has never been supported.\n> > > \n> > > Oops, hit \"send\" too early.\n> > > \n> > > We have support for a \"gitdir:\" facility that would work even on a\n> > > filesystem that cannot do symlinks (see gitrepository-layout(5)),\n> > > and both the higher-level submodule Porcelain and the more recent\n> > > \"worktree\" experimental code do use it.\n> > \n> > And the way to convince git to make the link for you is with clone's\n> > \"--separate-git-dir\" option.\n> \n> What's curious is that this doesn't really work either, so the issue\n> doesn't seem to be the lack of symlink support, but rather the lack of\n> willingness on the part of Git to resolve a path recursively.\n\nRight. The fundamental problem is that if git needs to construct a\nrelated path, symlinks mean it cannot do so textually. I'm sure there\nare spots where we use real_path() to get a canonical path for a\nparticular $GIT_DIR, but from your results, it's clear we don't do so\nconsistently.\n\nSo you can call that \"git doesn't support symlinks\", or you can call it\n\"git supports symlinks, but needs to do so more consistently\". :) I am\nnot sure whether the existing uses of real_path() are there\nintentionally to support the kind of path-munging that submodules do or\nnot. But either way, canonicalizing the paths before creating relative\nones is probably going to be the solution.\n\nI say all of that without having really looked at the code. You asked\nearlier if there would be any objects to a patch to implement better\nsymlink support. That is hard to answer without somebody digging in to\nsee what the fix would look like, and whether there would be any\ntradeoffs.\n\n-Peff\n"}]}