FalcoGer
FalcoGer

Reputation: 2457

Add submodule to repository which is in existing submodule

I wish to save my configuration in a git repository to deploy my configuration files on different machines easily.

One of the configuration files I wish to save is zsh. I use oh-my-zsh, which is in ~/.oh-my-zsh in my home directory. This directory is a git repository. oh-my-zsh uses git to update itself. I added it as a git submodule, which is fine.

Inside ~/.oh-my-zsh/custom/plugins/ and ~/.oh-my-zsh/custom/themes/ are custom plugins and themes that are installed after the fact. Those directories are in the oh-my-zsh gitignore file. The plugins and themes I added are also git repositories.

I use a git bare repository in ~/repositories/dotfiles/ and an alias that sets the working directory for git to the home directory, so I can add all files that I want to the configuration.

alias config="git --work-tree=$HOME --git-dir=$HOME/repositories/dotfiles/'

The problem now is that I can not add the git repositories in ~/.oh-my-zsh/custom/ as submodules to the git repository which has the working directory set to ~ because

~/.oh-my-zsh/custom/themes/powerlevel10k$ config submodule add $HOME/.oh-my-zsh/custom/themes/powerlevel10k
The following path is ignored by one of your .gitignore files:
.oh-my-zsh/custom/themes/powerlevel10k
Use -f if you really want to add it.                                                                                                                                  

/.oh-my-zsh/custom/themes/powerlevel10k$ config submodule add -f $HOME/.oh-my-zsh/custom/themes/powerlevel10k
Adding existing repo at '.oh-my-zsh/custom/themes/powerlevel10k' to the index
fatal: Pathspec '.oh-my-zsh/custom/themes/powerlevel10k' is in submodule '.oh-my-zsh'
Failed to add submodule '.oh-my-zsh/custom/themes/powerlevel10k'

if I try the same command in ~ then it will "clone the repository" to ~/powerlevel10k and it will then add that as the submodule.

What can be done? I was thinking about moving the directories and then adding them as submodules in those new directories and then creating symlinks in oh-my-zsh. But I was hoping for something that could be done with a simple git clone and no additional setup to make it work.

Upvotes: 1

Views: 273

Answers (1)

sean
sean

Reputation: 26

I hit the same issue with oh-my-zsh custom plugins. I found the answer in oh-my-zsh's wiki.

In your .zshrc, you can specify the custom directory with an environment variable: ZSH_CUSTOM=$HOME/my_customizations

Upvotes: 1

Related Questions