Search code examples
gitgit-submodulesgit-subtree

Why does git subtree prevent init-ing embedded submodules?


I have a git repository that I keep my vim configuration in. This tree includes a number of git submodules that refer to other people's repos which contain plugins.

As I'm interested in setting up a proper dotfiles repo with GNU stow, I thought the best way to integrate the vim repo was to just subtree it into the dotfiles repo. As my vim config is forked from someone else, I figured this way I could easily merge in changes made upstream while preserving my own plugins and config.

I've succesfully added the subtree to my repo, using git subtree add -P vim/.vim-files https:\\xx master --squash. The resulting tree looks like this:

dotfiles/
├── .git
└── vim/
    ├── .vimrc
    └── .vim-files/   <= THE SUBTREE
        ├── .gitmodules
        └── plugins/
            └── submodule1/

When I perform git submodule init from dotfiles/ after that, it fails with fatal: No url found for submodule path 'vim/.vim-files/plugins/submodule1' in .gitmodules. Even though the URL is there and the subtree repo has no problems with submodules when used standalone.

The stranger part is, when I cd into .vim-files and run the command there, the error looks like this: fatal: No url found for submodule path 'vim/.vim-files/vim/.vim-files/plugins/submodule1' in .gitmodules.

Can anyone explain what causes this behaviour? Are subtrees and submodules incompatible or have I stumbled upon a bug?


Solution

  • I got the same error. Seems that it is caused by submodule with full paths when git expects them to be relative. See the warning comment in my dotfiles repo for refference: https://github.com/palavrov/config#warning