{"thread":{"id":"41585","subject":"bug: git submodule add fails when .git is a symlink","startedAt":"2016-03-01T20:42:18Z","lastAt":"2016-04-20T17:31:47Z","messageCount":9,"participants":["Joey Hess","Stefan Beller","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"280004","messageId":"20160301204218.GA4083@kitenet.net","threadId":"41585","inReplyTo":null,"subject":"bug: git submodule add fails when .git is a symlink","fromName":"Joey Hess","fromEmail":"id@joeyh.name","sentAt":"2016-03-01T20:42:18Z","receivedAt":"2016-03-01T20:42:18Z","isPatch":false,"sender":{"key":"id@joeyh.name","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"        git init gitdir\n        mkdir worktree\n        cd worktree\n        ln -s ../gitdir/.git .git\n        git submodule add /any/git/repo sub\n\n        fatal: Could not chdir to '../../../sub': No such file or directory\n\nFairly sure this is a bug..\n\n-- \nsee shy jo\n"},{"id":"280007","messageId":"CAGZ79kY6Lf6u0=s8J_cqRNFsry4nu2SdL0GZ2gkFsu6gBrB65Q@mail.gmail.com","threadId":"41585","inReplyTo":"20160301204218.GA4083@kitenet.net","subject":"Re: bug: git submodule add fails when .git is a symlink","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-03-01T21:39:26Z","receivedAt":"2016-03-01T21:39:26Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Tue, Mar 1, 2016 at 12:42 PM, Joey Hess <id@joeyh.name> wrote:\n>         git init gitdir\n>         mkdir worktree\n>         cd worktree\n>         ln -s ../gitdir/.git .git\n>         git submodule add /any/git/repo sub\n>\n>         fatal: Could not chdir to '../../../sub': No such file or directory\n>\n> Fairly sure this is a bug..\n\nWhich version(s) of Git do you use?\n"},{"id":"280008","messageId":"CAGZ79kbV9y6nDuBgqLbzQ=xaroG_uF8RF6gqzk=unJ-9rrtvfw@mail.gmail.com","threadId":"41585","inReplyTo":"CAGZ79kY6Lf6u0=s8J_cqRNFsry4nu2SdL0GZ2gkFsu6gBrB65Q@mail.gmail.com","subject":"Re: bug: git submodule add fails when .git is a symlink","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-03-01T21:49:37Z","receivedAt":"2016-03-01T21:49:37Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Tue, Mar 1, 2016 at 1:39 PM, Stefan Beller <sbeller@google.com> wrote:\n> On Tue, Mar 1, 2016 at 12:42 PM, Joey Hess <id@joeyh.name> wrote:\n>>         git init gitdir\n>>         mkdir worktree\n>>         cd worktree\n>>         ln -s ../gitdir/.git .git\n>>         git submodule add /any/git/repo sub\n>>\n>>         fatal: Could not chdir to '../../../sub': No such file or directory\n>>\n>> Fairly sure this is a bug..\n>\n> Which version(s) of Git do you use?\n\nTo elaborate on that: Starting in 2.7 parts of the submodule stuff\nhas been rewritten in C, in 2.8 even more and there is more in flight for\n > 2.8.\n\nHowever your bug is also to be found in 2.6, which doesn't contain any\nrecent rewrites, so it is a rather long standing bug, I would presume.\n\nAs a workaround for now:\n\n    echo \"gitdir: ../gitdir/.git\" > .git\n\ninstead of the symbolic link in your example (works in 2.6 and also in\n2.8.0-rc0)\n\nThanks,\nStefan\n"},{"id":"280009","messageId":"xmqq8u217tqa.fsf@gitster.mtv.corp.google.com","threadId":"41585","inReplyTo":"CAGZ79kY6Lf6u0=s8J_cqRNFsry4nu2SdL0GZ2gkFsu6gBrB65Q@mail.gmail.com","subject":"Re: bug: git submodule add fails when .git is a symlink","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-01T21:50:53Z","receivedAt":"2016-03-01T21:50:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> On Tue, Mar 1, 2016 at 12:42 PM, Joey Hess <id@joeyh.name> wrote:\n>>         git init gitdir\n>>         mkdir worktree\n>>         cd worktree\n>>         ln -s ../gitdir/.git .git\n>>         git submodule add /any/git/repo sub\n>>\n>>         fatal: Could not chdir to '../../../sub': No such file or directory\n>>\n>> Fairly sure this is a bug..\n>\n> Which version(s) of Git do you use?\n\nA more pertinent question may be which version of Git did the above\never work, I guess.  We fairly liberally chdir around and I do not\nthink we deliberately avoid assuming that \"cd .git && cd ..\" might\nnot come back to the original directory, for example, so I wouldn't\nbe surprised if it never worked.\n"},{"id":"280017","messageId":"20160301231422.GA3731@kitenet.net","threadId":"41585","inReplyTo":"CAGZ79kbV9y6nDuBgqLbzQ=xaroG_uF8RF6gqzk=unJ-9rrtvfw@mail.gmail.com","subject":"Re: bug: git submodule add fails when .git is a symlink","fromName":"Joey Hess","fromEmail":"id@joeyh.name","sentAt":"2016-03-01T23:14:22Z","receivedAt":"2016-03-01T23:14:22Z","isPatch":false,"sender":{"key":"id@joeyh.name","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"Stefan Beller wrote:\n> To elaborate on that: Starting in 2.7 parts of the submodule stuff\n> has been rewritten in C, in 2.8 even more and there is more in flight for\n>  > 2.8.\n> \n> However your bug is also to be found in 2.6, which doesn't contain any\n> recent rewrites, so it is a rather long standing bug, I would presume.\n\nYes, I saw it with 2.7.0, but I think the user who reported it was on\n2.6.\n\n> As a workaround for now:\n> \n>     echo \"gitdir: ../gitdir/.git\" > .git\n\nNot an option in our particular situation, unfortunately.\n\nI wonder if the miscalculated ../../../somedir could cause git to access\nfiles outside the git repos?\n\n-- \nsee shy jo\n"},{"id":"280019","messageId":"20160301231720.GB3731@kitenet.net","threadId":"41585","inReplyTo":"xmqq8u217tqa.fsf@gitster.mtv.corp.google.com","subject":"Re: bug: git submodule add fails when .git is a symlink","fromName":"Joey Hess","fromEmail":"id@joeyh.name","sentAt":"2016-03-01T23:17:20Z","receivedAt":"2016-03-01T23:17:20Z","isPatch":false,"sender":{"key":"id@joeyh.name","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"Junio C Hamano wrote:\n> A more pertinent question may be which version of Git did the above\n> ever work, I guess.  We fairly liberally chdir around and I do not\n> think we deliberately avoid assuming that \"cd .git && cd ..\" might\n> not come back to the original directory, for example, so I wouldn't\n> be surprised if it never worked.\n\nIIRC git used symlinks for .git in submodules before version 1.7.8, so I\nguess that older versions supported that pretty well.\n\nThis one case is the only time I've seen a symlink for .git present a\nproblem so far.\n\n-- \nsee shy jo\n"},{"id":"280047","messageId":"20160302084904.GA30295@sigill.intra.peff.net","threadId":"41585","inReplyTo":"20160301231720.GB3731@kitenet.net","subject":"Re: bug: git submodule add fails when .git is a symlink","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-03-02T08:49:04Z","receivedAt":"2016-03-02T08:49:04Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Mar 01, 2016 at 07:17:20PM -0400, Joey Hess wrote:\n\n> Junio C Hamano wrote:\n> > A more pertinent question may be which version of Git did the above\n> > ever work, I guess.  We fairly liberally chdir around and I do not\n> > think we deliberately avoid assuming that \"cd .git && cd ..\" might\n> > not come back to the original directory, for example, so I wouldn't\n> > be surprised if it never worked.\n> \n> IIRC git used symlinks for .git in submodules before version 1.7.8, so I\n> guess that older versions supported that pretty well.\n> \n> This one case is the only time I've seen a symlink for .git present a\n> problem so far.\n\nFortunately you provided a simple reproduction case, so it is easy to\nbisect. It did work in v1.7.8, and broke in d75219b (submodules: always\nuse a relative path from gitdir to work tree, 2012-03-04). Not\nsurprising, I guess. It presumably worked before only because we were\nusing absolute paths.\n\n-Peff\n"},{"id":"283967","messageId":"CAGZ79kbpyu34kz7gRgro-HZqNvpmRoCsyQatZRbxP19bk1gkfg@mail.gmail.com","threadId":"41585","inReplyTo":"20160302084904.GA30295@sigill.intra.peff.net","subject":"Re: bug: git submodule add fails when .git is a symlink","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-04-20T16:41:52Z","receivedAt":"2016-04-20T16:41:52Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Mar 2, 2016 at 12:49 AM, Jeff King <peff@peff.net> wrote:\n> On Tue, Mar 01, 2016 at 07:17:20PM -0400, Joey Hess wrote:\n>\n>> Junio C Hamano wrote:\n>> > A more pertinent question may be which version of Git did the above\n>> > ever work, I guess.  We fairly liberally chdir around and I do not\n>> > think we deliberately avoid assuming that \"cd .git && cd ..\" might\n>> > not come back to the original directory, for example, so I wouldn't\n>> > be surprised if it never worked.\n>>\n>> IIRC git used symlinks for .git in submodules before version 1.7.8, so I\n>> guess that older versions supported that pretty well.\n>>\n>> This one case is the only time I've seen a symlink for .git present a\n>> problem so far.\n>\n> Fortunately you provided a simple reproduction case, so it is easy to\n> bisect. It did work in v1.7.8, and broke in d75219b (submodules: always\n> use a relative path from gitdir to work tree, 2012-03-04). Not\n> surprising, I guess. It presumably worked before only because we were\n> using absolute paths.\n\nSo I was looking into this bug again, as it was linked from another bug report.\n\nfatal: Could not chdir to '../../../sub': No such file or directory\n\nsounds like a path issue with the prefix thing.\n\nUsing the \" echo \"gitdir: ../gitdir/.git\" > .git\" workaround does still work,\nI'll see if there is another way to fix it with actual links.\n\n\n>\n> -Peff\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"283970","messageId":"CAGZ79kZ2A6c9H7C4xPXJ1Lmh1TaVy+VgcjxvKrgcJb0-4LRvhA@mail.gmail.com","threadId":"41585","inReplyTo":"CAGZ79kbpyu34kz7gRgro-HZqNvpmRoCsyQatZRbxP19bk1gkfg@mail.gmail.com","subject":"Re: bug: git submodule add fails when .git is a symlink","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-04-20T17:31:47Z","receivedAt":"2016-04-20T17:31:47Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Apr 20, 2016 at 9:41 AM, Stefan Beller <sbeller@google.com> wrote:\n> On Wed, Mar 2, 2016 at 12:49 AM, Jeff King <peff@peff.net> wrote:\n>> On Tue, Mar 01, 2016 at 07:17:20PM -0400, Joey Hess wrote:\n>>\n>>> Junio C Hamano wrote:\n>>> > A more pertinent question may be which version of Git did the above\n>>> > ever work, I guess.  We fairly liberally chdir around and I do not\n>>> > think we deliberately avoid assuming that \"cd .git && cd ..\" might\n>>> > not come back to the original directory, for example, so I wouldn't\n>>> > be surprised if it never worked.\n>>>\n>>> IIRC git used symlinks for .git in submodules before version 1.7.8, so I\n>>> guess that older versions supported that pretty well.\n>>>\n>>> This one case is the only time I've seen a symlink for .git present a\n>>> problem so far.\n>>\n>> Fortunately you provided a simple reproduction case, so it is easy to\n>> bisect. It did work in v1.7.8, and broke in d75219b (submodules: always\n>> use a relative path from gitdir to work tree, 2012-03-04). Not\n>> surprising, I guess. It presumably worked before only because we were\n>> using absolute paths.\n>\n> So I was looking into this bug again, as it was linked from another bug report.\n>\n> fatal: Could not chdir to '../../../sub': No such file or directory\n>\n> sounds like a path issue with the prefix thing.\n>\n> Using the \" echo \"gitdir: ../gitdir/.git\" > .git\" workaround does still work,\n> I'll see if there is another way to fix it with actual links.\n\nSo I debugged into that using a test case\n\ntest_expect_success 'submodules are not confused by linked gitdir' '\n        git init gitdir &&\n        mkdir worktree &&\n        (\n                cd worktree &&\n                #echo \"gitdir: ../gitdir/.git\" >.git &&\n                ln -s ../gitdir/.git .git &&\n                test_pause &&\n                git submodule add ../ sub &&\n                test_pause\n        ) &&\n        test_pause &&\n        git status\n'\n\nMy observation: the error comes up in `git submodule add`,\nwhich consists of 2 parts: the cloning and then the checkout.\nThe cloning works fine using the new \"submodule--helper update-clone\",\nthe checkout however breaks. So in your original test case you can go\ninto the submodule and run\n\n    git checkout -f -q\n\nand you'll get the error message\n\n    fatal: Could not chdir to '../../../sub': No such file or directory\n\nLooking at sub/.git:\n\n    $ cat .git\n    gitdir: ../.git/modules/sub\n    $ ls ../.git/modules/sub\n    HEAD  branches config description  hooks  info  logs objects\npacked-refs  ref\n\nso that gitlink of the submodule works just fine. The problem is `git checkout`\nor any other core command (I tested with `git status`) doesn't like\nthe gitlink pointing to a directory which is symlinked.\n\nI think the issue is a wrongly configured \"core.worktree\"\nin gitdir/.git/modules/sub/config which contains the \"../../../sub\".\n\nSo I think the fix needs to be in the vicinity of\nbuiltin/submodule--helper.c:module_clone\nnear the end of the function, where core.worktree is set.\n\nThanks,\nStefan\n\n\n>\n>\n>>\n>> -Peff\n>> --\n>> To unsubscribe from this list: send the line \"unsubscribe git\" in\n>> the body of a message to majordomo@vger.kernel.org\n>> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"}]}