{"thread":{"id":"40319","subject":"git submodule ignores --git-dir","startedAt":"2015-09-10T20:06:03Z","lastAt":"2015-09-14T13:25:46Z","messageCount":4,"participants":["Filip Gospodinov","Jens Lehmann","John Keeping"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"269732","messageId":"55F1E2AB.3020507@monetas.net","threadId":"40319","inReplyTo":null,"subject":"git submodule ignores --git-dir","fromName":"Filip Gospodinov","fromEmail":"filip.gospodinov@monetas.net","sentAt":"2015-09-10T20:06:03Z","receivedAt":"2015-09-10T20:06:03Z","isPatch":false,"sender":{"key":"filip.gospodinov@monetas.net","avatar":null},"body":"Hi!\n\nI use the `--git-dir` flag in some scripts such that I don't need to `cd` back\nand forth. Recently, I've discovered that `--git-dir` does not seem to work\ncorrectly for `git submodule`. Here is a short snippet to reproduce that behavior:\n\nmkdir repo1 subm\n(cd subm; git init; git commit -m 1 --allow-empty)\n(cd repo1; git init; git submodule add ../subm subm; git commit -m \"add subm\")\ngit clone repo1 repo2\ngit --git-dir=$PWD/repo2/.git submodule update --init\n\n\nwhich errors with the following output:\n\nNo submodule mapping found in .gitmodules for path 'subm'\n\nBut this works:\ncd repo2; git --git-dir=$PWD/.git submodule update --init\n\n\nI know that for this particular use case I can just use `git clone --recursive`\nand that other use cases can be worked around by using `cd`. Still, I wonder if\nthe behavior I discovered is a bug or if it's expected.\n\ngit --version\ngit version 2.5.1\n\nThanks you!\nFilip\n"},{"id":"269768","messageId":"55F2F028.7070505@web.de","threadId":"40319","inReplyTo":"55F1E2AB.3020507@monetas.net","subject":"Re: git submodule ignores --git-dir","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2015-09-11T15:15:52Z","receivedAt":"2015-09-11T15:15:52Z","isPatch":false,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 10.09.2015 um 22:06 schrieb Filip Gospodinov:\n> Hi!\n>\n> I use the `--git-dir` flag in some scripts such that I don't need to `cd` back\n> and forth. Recently, I've discovered that `--git-dir` does not seem to work\n> correctly for `git submodule`. Here is a short snippet to reproduce that behavior:\n>\n> mkdir repo1 subm\n> (cd subm; git init; git commit -m 1 --allow-empty)\n> (cd repo1; git init; git submodule add ../subm subm; git commit -m \"add subm\")\n> git clone repo1 repo2\n> git --git-dir=$PWD/repo2/.git submodule update --init\n>\n>\n> which errors with the following output:\n>\n> No submodule mapping found in .gitmodules for path 'subm'\n>\n> But this works:\n> cd repo2; git --git-dir=$PWD/.git submodule update --init\n\nThanks for your report containing a nice recipe to reproduce your issue!\n\n> I know that for this particular use case I can just use `git clone --recursive`\n> and that other use cases can be worked around by using `cd`. Still, I wonder if\n> the behavior I discovered is a bug or if it's expected.\n\nI don't think this is a bug. The git submodule command needs a work tree\nto read the .gitmodules file from, that's while it fails when using\n--git-dir from outside the work tree. But I admit that the error message\n\"No submodule mapping found in .gitmodules for path ...\" could be improved\nto clearly state that the .gitmodules file wasn't found.\n\nUnfortunately trying to show git the right work tree:\n\n$ git --git-dir=$PWD/repo2/.git --work-tree=$PWD/repo2 submodule update --init\n\nDidn't work as I expected it to either:\n\nfatal: /home/Sledge/libexec/git-core/git-submodule cannot be used without a working tree.\n\nSo you'll have to cd into the repo for now.\n"},{"id":"269771","messageId":"20150911152807.GA17201@serenity.lan","threadId":"40319","inReplyTo":"55F2F028.7070505@web.de","subject":"Re: git submodule ignores --git-dir","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2015-09-11T15:28:07Z","receivedAt":"2015-09-11T15:28:07Z","isPatch":false,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Fri, Sep 11, 2015 at 05:15:52PM +0200, Jens Lehmann wrote:\n> Am 10.09.2015 um 22:06 schrieb Filip Gospodinov:\n> > I know that for this particular use case I can just use `git clone --recursive`\n> > and that other use cases can be worked around by using `cd`. Still, I wonder if\n> > the behavior I discovered is a bug or if it's expected.\n> \n> I don't think this is a bug. The git submodule command needs a work tree\n> to read the .gitmodules file from, that's while it fails when using\n> --git-dir from outside the work tree. But I admit that the error message\n> \"No submodule mapping found in .gitmodules for path ...\" could be improved\n> to clearly state that the .gitmodules file wasn't found.\n> \n> Unfortunately trying to show git the right work tree:\n> \n> $ git --git-dir=$PWD/repo2/.git --work-tree=$PWD/repo2 submodule update --init\n> \n> Didn't work as I expected it to either:\n> \n> fatal: /home/Sledge/libexec/git-core/git-submodule cannot be used without a working tree.\n> \n> So you'll have to cd into the repo for now.\n\nThere's also \"git -C /path/to/repo\" which avoids the need for a separate\n\"cd\".\n"},{"id":"269921","messageId":"55F6CADA.9000100@monetas.net","threadId":"40319","inReplyTo":"20150911152807.GA17201@serenity.lan","subject":"Re: git submodule ignores --git-dir","fromName":"Filip Gospodinov","fromEmail":"filip.gospodinov@monetas.net","sentAt":"2015-09-14T13:25:46Z","receivedAt":"2015-09-14T13:25:46Z","isPatch":false,"sender":{"key":"filip.gospodinov@monetas.net","avatar":null},"body":"On 11.09.2015 17:15, Jens Lehmann wrote:\n> Unfortunately trying to show git the right work tree:\n>\n> $ git --git-dir=$PWD/repo2/.git --work-tree=$PWD/repo2 submodule update --init\n>\n> Didn't work as I expected it to either:\n>\n> fatal: /home/Sledge/libexec/git-core/git-submodule cannot be used without a\n> working tree.\n\nYes, that's confusing. I'm not sure how other commands use the --work-tree flag\nand if having the git-submodule script `cd` into the work tree would be\nacceptable. What do you think?\n\nOn 11.09.2015 17:28, John Keeping wrote:\n> There's also \"git -C /path/to/repo\" which avoids the need for a separate\n> \"cd\".\n> \n\nThank you, that works!\n"}]}