{"thread":{"id":"50378","subject":"Fwd: Submodules & worktree","startedAt":"2019-02-01T14:00:44Z","lastAt":"2020-01-28T04:03:20Z","messageCount":5,"participants":["Ole Pinto","Mateusz Loskot","Philippe Blain"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"368328","messageId":"CAKQS2dqx9Nux11ot7a-Wxd2qpcdAAWw-e7Li+X3bw7TxJS=Kyw@mail.gmail.com","threadId":"50378","inReplyTo":"CAKQS2drF+CQTiKtXD6Kx1ZbH9ZTekWmbfiiHTCJV_BrT5-gAFQ@mail.gmail.com","subject":"Fwd: Submodules & worktree","fromName":"Ole Pinto","fromEmail":"olepinto@gmail.com","sentAt":"2019-02-01T14:00:28Z","receivedAt":"2019-02-01T14:00:44Z","isPatch":false,"sender":{"key":"olepinto@gmail.com","avatar":null},"body":"Adding a worktree from a working copy with submodules doesn't work.\n\nIn the config file I have\n    [submodule]\n        recurse = true\n\nIt that's not present, I don't find the problem.\n\n# Preparation\n\n$ git --version\ngit version 2.20.1\n\n$ cd /tmp/\n\n$ git init main_repo\nInitialized empty Git repository in /tmp/main_repo/.git/\n\n$ git init repo_submod\nInitialized empty Git repository in /tmp/repo_submod/.git/\n\n$ cd repo_submod\n\n$ echo Some text > file.txt\n\n$ git add file.txt\n\n$ git ci -m \"First commit in subrepo\"\n[master (root-commit) ebc9325] First commit in subrepo\n 1 file changed, 1 insertion(+)\n create mode 100644 file.txt\n\n$ cd ../main_repo/\n\n$ git submodule add /tmp/repo_submod submod\nCloning into '/tmp/main_repo/submod'...\ndone.\n\n$ git ci -am \"First commit, add submodule\"\n[master (root-commit) 695b3a1] First commit, add submodule\n 2 files changed, 4 insertions(+)\n create mode 100644 .gitmodules\n create mode 160000 submod\n\n# Problem 1 (can't run worktree add)\n\n$ git worktree add ../wt -b new_branch\nPreparing worktree (new branch 'new_branch')\nfatal: exec '--super-prefix=submod/': cd to 'submod' failed: No such\nfile or directory\nerror: Submodule 'submod' could not be updated.\nerror: Submodule 'submod' cannot checkout new HEAD.\nfatal: Could not reset index file to revision 'HEAD'.\n\nThe new directory (../wt) is created and removed (seen with strace).\nThe new branch is created and not removed.\n\n# Problem 2 (submodule status seems not to detect some cases)\n\n$ pwd\n/tmp/main_repo\n\n$ git submodule status\n ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod (heads/master)\n\n$ rm submod/file.txt submod/.git\n\n$ git submodule status\n ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod\n\nSo, I have a plain, empty directory where the submodule should be. Not\nhaving any 'first char', I'd expect it to be checked out and up to\ndate. Is this expected?\n\nThanks a lot for the work!\n"},{"id":"368332","messageId":"CABUeae8=SLzSiT+UDdPeEbSUJNhU5xVF0-7hGK++v4sHsQWA8w@mail.gmail.com","threadId":"50378","inReplyTo":"CAKQS2dqx9Nux11ot7a-Wxd2qpcdAAWw-e7Li+X3bw7TxJS=Kyw@mail.gmail.com","subject":"Re: Submodules & worktree","fromName":"Mateusz Loskot","fromEmail":"mateusz@loskot.net","sentAt":"2019-02-01T15:04:26Z","receivedAt":"2019-02-01T15:04:56Z","isPatch":false,"sender":{"key":"mateusz@loskot.net","avatar":"https://gravatar.com/avatar/fe5a0ce8995d4986f5c46aad6353e21717808da58e4bc710da1a100e247be239?d=mp&s=160"},"body":"On Fri, 1 Feb 2019 at 15:00, Ole Pinto <olepinto@gmail.com> wrote:\n>\n> Adding a worktree from a working copy with submodules doesn't work.\n>\n> In the config file I have\n>     [submodule]\n>         recurse = true\n>\n\nFYI, https://git-scm.com/docs/git-worktree#_bugs\n\n\"Multiple checkout in general is still experimental, and the support\nfor submodules is incomplete.\nIt is NOT recommended to make multiple checkouts of a superproject.\"\n\nBest regards,\n-- \nMateusz Loskot, http://mateusz.loskot.net\n"},{"id":"390605","messageId":"EE184A05-60BD-4939-93E6-C156A0DB3DF8@gmail.com","threadId":"50378","inReplyTo":"CAKQS2dqx9Nux11ot7a-Wxd2qpcdAAWw-e7Li+X3bw7TxJS=Kyw@mail.gmail.com","subject":"Re: Submodules & worktree","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2020-01-28T04:01:36Z","receivedAt":"2020-01-28T04:01:43Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Ole,\n\n> Le 1 févr. 2019 à 09:00, Ole Pinto <olepinto@gmail.com> a écrit :\n> \n> Adding a worktree from a working copy with submodules doesn't work.\n> \n> In the config file I have\n>   [submodule]\n>       recurse = true\n> \n> It that's not present, I don't find the problem.\n\nI also stumbled upon this bug and fixed it in 4782cf2ab6 (worktree: teach \"add\" to ignore submodule.recurse config, 2019-10-27), which was merged in 05fc6471e3 (Merge branch 'pb/no-recursive-reset-hard-in-worktree-add', 2019-12-01) and made it to Git 2.25.\n`git worktree add` now works correctly in a project with submodules, and cd-ing to the new worktree directory and issuing `git submodule update` inits and clones the submodule(s) to .git/worktrees/<worktree-name>/modules/<submodule-name>, as it should.\n\nI must warn you however that I discovered another bug that can happen with the submodule.recurse config when using worktrees with projects that have submodules. In short, issuing `git checkout` (or `git reset` or `git read-tree`) in one of the worktrees will leave the .git file in the submodule incorrectly pointing to the repository of the submodule in the main worktree, i.e. .git/modules/<submodule-name> instead of .git/worktrees/<worktree-name>/modules/<submodule-name>. I also fixed this bug [1], my patch series for this is currently in next. \n\n[1] https://github.com/gitgitgadget/git/pull/523\n\n> # Problem 2 (submodule status seems not to detect some cases)\n> \n> $ pwd\n> /tmp/main_repo\n> \n> $ git submodule status\n> ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod (heads/master)\n> \n> $ rm submod/file.txt submod/.git\n> \n> $ git submodule status\n> ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod\n> \n> So, I have a plain, empty directory where the submodule should be. Not\n> having any 'first char', I'd expect it to be checked out and up to\n> date. Is this expected?\nThis is indeed not expected, and used to work correctly (the hash should be prefixed with a ‘-‘) in Git 2.12. This bevaviour regressed when `git submodule status` was ported to C in a9f8a37584 (submodule: port submodule subcommand 'status' from shell to C, 2017-10-06).\nAnother user reported this regression to the list recently and a patch series is in the works to fix it [2].\n\n[2] https://lore.kernel.org/git/xmqqv9owbw5o.fsf@gitster-ct.c.googlers.com/\n\nCheers,\nPhilippe.\n\n"},{"id":"390606","messageId":"2C0C3A4A-B185-4690-B76C-42E113A89687@gmail.com","threadId":"50378","inReplyTo":"CAKQS2dqx9Nux11ot7a-Wxd2qpcdAAWw-e7Li+X3bw7TxJS=Kyw@mail.gmail.com","subject":"Re: Submodules & worktree","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2020-01-28T04:01:37Z","receivedAt":"2020-01-28T04:01:45Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Ole,\n\n> Le 1 févr. 2019 à 09:00, Ole Pinto <olepinto@gmail.com> a écrit :\n> \n> Adding a worktree from a working copy with submodules doesn't work.\n> \n> In the config file I have\n>   [submodule]\n>       recurse = true\n> \n> It that's not present, I don't find the problem.\n\nI also stumbled upon this bug and fixed it in 4782cf2ab6 (worktree: teach \"add\" to ignore submodule.recurse config, 2019-10-27), which was merged in 05fc6471e3 (Merge branch 'pb/no-recursive-reset-hard-in-worktree-add', 2019-12-01) and made it to Git 2.25.\n`git worktree add` now works correctly in a project with submodules, and cd-ing to the new worktree directory and issuing `git submodule update` inits and clones the submodule(s) to .git/worktrees/<worktree-name>/modules/<submodule-name>, as it should.\n\nI must warn you however that I discovered another bug that can happen with the submodule.recurse config when using worktrees with projects that have submodules. In short, issuing `git checkout` (or `git reset` or `git read-tree`) in one of the worktrees will leave the .git file in the submodule incorrectly pointing to the repository of the submodule in the main worktree, i.e. .git/modules/<submodule-name> instead of .git/worktrees/<worktree-name>/modules/<submodule-name>. I also fixed this bug [1], my patch series for this is currently in next. \n\n[1] https://github.com/gitgitgadget/git/pull/523\n\n> # Problem 2 (submodule status seems not to detect some cases)\n> \n> $ pwd\n> /tmp/main_repo\n> \n> $ git submodule status\n> ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod (heads/master)\n> \n> $ rm submod/file.txt submod/.git\n> \n> $ git submodule status\n> ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod\n> \n> So, I have a plain, empty directory where the submodule should be. Not\n> having any 'first char', I'd expect it to be checked out and up to\n> date. Is this expected?\nThis is indeed not expected, and used to work correctly (the hash should be prefixed with a ‘-‘) in Git 2.12. This bevaviour regressed when `git submodule status` was ported to C in a9f8a37584 (submodule: port submodule subcommand 'status' from shell to C, 2017-10-06).\nAnother user reported this regression to the list recently and a patch series is in the works to fix it [2].\n\n[2] https://lore.kernel.org/git/xmqqv9owbw5o.fsf@gitster-ct.c.googlers.com/\n\nCheers,\nPhilippe.\n\n"},{"id":"390607","messageId":"746427B4-5B64-492F-A69E-908D6A1F5308@me.com","threadId":"50378","inReplyTo":"CAKQS2dqx9Nux11ot7a-Wxd2qpcdAAWw-e7Li+X3bw7TxJS=Kyw@mail.gmail.com","subject":"Re: Submodules & worktree","fromName":"Philippe Blain","fromEmail":"philippe.blain@me.com","sentAt":"2020-01-28T03:56:48Z","receivedAt":"2020-01-28T04:03:20Z","isPatch":false,"sender":{"key":"philippe.blain@me.com","avatar":null},"body":"Hi Ole,\n\n> Le 1 févr. 2019 à 09:00, Ole Pinto <olepinto@gmail.com> a écrit :\n> \n> Adding a worktree from a working copy with submodules doesn't work.\n> \n> In the config file I have\n>    [submodule]\n>        recurse = true\n> \n> It that's not present, I don't find the problem.\n\nI also stumbled upon this bug and fixed it in 4782cf2ab6 (worktree: teach \"add\" to ignore submodule.recurse config, 2019-10-27), which was merged in 05fc6471e3 (Merge branch 'pb/no-recursive-reset-hard-in-worktree-add', 2019-12-01) and made it to Git 2.25.\n`git worktree add` now works correctly in a project with submodules, and cd-ing to the new worktree directory and issuing `git submodule update` inits and clones the submodule(s) to .git/worktrees/<worktree-name>/modules/<submodule-name>, as it should.\n\nI must warn you however that I discovered another bug that can happen with the submodule.recurse config when using worktrees with projects that have submodules. In short, issuing `git checkout` (or `git reset` or `git read-tree`) in one of the worktrees will leave the .git file in the submodule incorrectly pointing to the repository of the submodule in the main worktree, i.e. .git/modules/<submodule-name> instead of .git/worktrees/<worktree-name>/modules/<submodule-name>. I also fixed this bug [1], my patch series for this is currently in next. \n\n[1] https://github.com/gitgitgadget/git/pull/523\n\n> # Problem 2 (submodule status seems not to detect some cases)\n> \n> $ pwd\n> /tmp/main_repo\n> \n> $ git submodule status\n> ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod (heads/master)\n> \n> $ rm submod/file.txt submod/.git\n> \n> $ git submodule status\n> ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod\n> \n> So, I have a plain, empty directory where the submodule should be. Not\n> having any 'first char', I'd expect it to be checked out and up to\n> date. Is this expected?\nThis is indeed not expected, and used to work correctly (the hash should be prefixed with a ‘-‘) in Git 2.12. This bevaviour regressed when `git submodule status` was ported to C in a9f8a37584 (submodule: port submodule subcommand 'status' from shell to C, 2017-10-06).\nAnother user reported this regression to the list recently and a patch series is in the works to fix it [2].\n\n[2] https://lore.kernel.org/git/xmqqv9owbw5o.fsf@gitster-ct.c.googlers.com/\n\nCheers,\nPhilippe.\n\n"}]}