git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Fwd: Submodules & worktree

From
OPOle Pinto <olepinto@gmail.com>
Date
Feb 1, 2019, 14:00 UTC
Message-ID
<CAKQS2dqx9Nux11ot7a-Wxd2qpcdAAWw-e7Li+X3bw7TxJS=Kyw@mail.gmail.com>
In-Reply-To
<CAKQS2drF+CQTiKtXD6Kx1ZbH9ZTekWmbfiiHTCJV_BrT5-gAFQ@mail.gmail.com>
Adding a worktree from a working copy with submodules doesn't work.
In the config file I have
    [submodule]
        recurse = true
It that's not present, I don't find the problem.
# Preparation

$ git --version git version 2.20.1

$ cd /tmp/

$ git init main_repo Initialized empty Git repository in /tmp/main_repo/.git/

$ git init repo_submod Initialized empty Git repository in /tmp/repo_submod/.git/

$ cd repo_submod
$ echo Some text > file.txt
$ git add file.txt
$ git ci -m "First commit in subrepo"
[master (root-commit) ebc9325] First commit in subrepo
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt
$ cd ../main_repo/

$ git submodule add /tmp/repo_submod submod Cloning into '/tmp/main_repo/submod'... done.

$ git ci -am "First commit, add submodule"
[master (root-commit) 695b3a1] First commit, add submodule
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 submod
# Problem 1 (can't run worktree add)

$ git worktree add ../wt -b new_branch Preparing worktree (new branch 'new_branch') fatal: exec '--super-prefix=submod/': cd to 'submod' failed: No such file or directory error: Submodule 'submod' could not be updated. error: Submodule 'submod' cannot checkout new HEAD. fatal: Could not reset index file to revision 'HEAD'.

The new directory (../wt) is created and removed (seen with strace). The new branch is created and not removed.

# Problem 2 (submodule status seems not to detect some cases)

$ pwd /tmp/main_repo

$ git submodule status
 ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod (heads/master)
$ rm submod/file.txt submod/.git
$ git submodule status
 ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod

So, I have a plain, empty directory where the submodule should be. Not having any 'first char', I'd expect it to be checked out and up to date. Is this expected?

Thanks a lot for the work!
Next: Mateusz Loskot
Message 1 of 5 in “Fwd: Submodules & worktree”
  1. Ole PintoFeb 1, 2019
  2. Mateusz LoskotFeb 1, 2019
  3. Philippe BlainJan 28, 2020
  4. Philippe BlainJan 28, 2020
  5. Philippe BlainJan 28, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.