{"thread":{"id":"41593","subject":"bug: git submodule add in of nested submodule handles relative path wrong","startedAt":"2016-03-02T16:52:40Z","lastAt":"2016-03-02T21:47:16Z","messageCount":2,"participants":["Joey Hess","Stefan Beller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"280068","messageId":"20160302165240.GA17654@kitenet.net","threadId":"41593","inReplyTo":null,"subject":"bug: git submodule add in of nested submodule handles relative path wrong","fromName":"Joey Hess","fromEmail":"id@joeyh.name","sentAt":"2016-03-02T16:52:40Z","receivedAt":"2016-03-02T16:52:40Z","isPatch":false,"sender":{"key":"id@joeyh.name","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"joey@darkstar:/tmp/empty>git init sub1\nInitialized empty Git repository in /tmp/empty/sub1/.git/\njoey@darkstar:/tmp/empty>git init sub2\nInitialized empty Git repository in /tmp/empty/sub2/.git/\njoey@darkstar:/tmp/empty>cd sub1\njoey@darkstar:/tmp/empty/sub1>date > f1 ; git add f1; git commit -m add -q\njoey@darkstar:/tmp/empty/sub1>cd ..\njoey@darkstar:/tmp/empty>cd sub2\njoey@darkstar:/tmp/empty/sub2>date > f2 ; git add f2; git commit -m add -q\njoey@darkstar:/tmp/empty/sub2>cd ..\njoey@darkstar:/tmp/empty>git init repo\nInitialized empty Git repository in /tmp/empty/repo/.git/\njoey@darkstar:/tmp/empty>cd repo\njoey@darkstar:/tmp/empty/repo>git submodule add ../sub1 1\nCloning into '1'...\ndone.\njoey@darkstar:/tmp/empty/repo>cd 1\njoey@darkstar:/tmp/empty/repo/1>ls\nf1\njoey@darkstar:/tmp/empty/repo/1>git submodule add ../../sub2 2\nfatal: repository '/tmp/sub2' does not exist\nfatal: clone of '/tmp/sub2' into submodule path '2' failed\n\nLike the bug I filed yesterday, this is caused by git submodule add's\nchdir into .git/modules.\n\nWorkaround is to pass absolute paths to git submodule add.\n\nNote that this could be an exploitable security hole under some unusual\ncircumstances. In the example above, any other local user could create a\n/tmp/sub2 containing something nasty, and git would check it out\naccidentially.\n\ngit version 2.7.0\n\n-- \nsee shy jo\n"},{"id":"280095","messageId":"CAGZ79kYJKyriLy8KMeAiG9E9u=LrQgXdO4wH1ERX3HsqZ2uVYQ@mail.gmail.com","threadId":"41593","inReplyTo":"20160302165240.GA17654@kitenet.net","subject":"Re: bug: git submodule add in of nested submodule handles relative path wrong","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-03-02T21:47:16Z","receivedAt":"2016-03-02T21:47:16Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"I'll add Jens, who has deep knowledge of submodules.\n\nOn Wed, Mar 2, 2016 at 8:52 AM, Joey Hess <id@joeyh.name> wrote:\n> joey@darkstar:/tmp/empty>git init sub1\n> Initialized empty Git repository in /tmp/empty/sub1/.git/\n> joey@darkstar:/tmp/empty>git init sub2\n> Initialized empty Git repository in /tmp/empty/sub2/.git/\n> joey@darkstar:/tmp/empty>cd sub1\n> joey@darkstar:/tmp/empty/sub1>date > f1 ; git add f1; git commit -m add -q\n> joey@darkstar:/tmp/empty/sub1>cd ..\n> joey@darkstar:/tmp/empty>cd sub2\n> joey@darkstar:/tmp/empty/sub2>date > f2 ; git add f2; git commit -m add -q\n> joey@darkstar:/tmp/empty/sub2>cd ..\n> joey@darkstar:/tmp/empty>git init repo\n> Initialized empty Git repository in /tmp/empty/repo/.git/\n> joey@darkstar:/tmp/empty>cd repo\n> joey@darkstar:/tmp/empty/repo>git submodule add ../sub1 1\n> Cloning into '1'...\n> done.\n> joey@darkstar:/tmp/empty/repo>cd 1\n> joey@darkstar:/tmp/empty/repo/1>ls\n> f1\n> joey@darkstar:/tmp/empty/repo/1>git submodule add ../../sub2 2\n> fatal: repository '/tmp/sub2' does not exist\n> fatal: clone of '/tmp/sub2' into submodule path '2' failed\n\nThis happens because inside \"git submodule add\" as in\nany git submodule command you cd to the top level of the superproject\nand then there is no proper way to describe where you came from.\n\nCompare to [1], where I poke around with submodules as well.\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/287620\n\n>\n> Like the bug I filed yesterday, this is caused by git submodule add's\n> chdir into .git/modules.\n\nI wonder if we want to take note of \"these small annoyances\"\nin the submodule wiki[2].\n\n[2] https://github.com/jlehmann/git-submod-enhancements/wiki#submodule-related-bugs-to-fix\n  I consider Jens wiki one of the best sources for a high level overview\n  of what needs to be done, and what is already solved for submodules.\n  I linked to this thread from there. (I did not know I had write permission)\n\nThanks,\nStefan\n\n>\n> Workaround is to pass absolute paths to git submodule add.\n>\n> Note that this could be an exploitable security hole under some unusual\n> circumstances. In the example above, any other local user could create a\n> /tmp/sub2 containing something nasty, and git would check it out\n> accidentially.\n>\n> git version 2.7.0\n>\n> --\n> see shy jo\n"}]}