Recently while setting up my vimfiles for version control I encountered a problem with git submodules. The plugins are included as git submodules and loaded up with pathogen. For those interested in details on how this works, there is a Vimcast available on this topic. Some of the plugins need to generate helptags or other files that will mark the working tree dirty. There is a very simple way to prevent this, but it is a little tricky to find out what is needed to make it work, that’s why I decided to write a blog post about how to do this.
In my opinion one should not change anything within submodules but rather change it in the original repository and then update the submodule. So we are going to ignore dirty and untracked files within all our submodules.
One method is to provide a flag to
git status, telling it what you want it to ignore in submodules. The command
git help status reveals how to do this:
--ignore-submodules[=<when>] Ignore changes to submodules when looking for changes. <when> can be either "untracked", "dirty" or "all", which is the default. When "untracked" is used submodules are not considered dirty when they only contain untracked content (but they are still scanned for modified content). Using "dirty" ignores all changes to the work tree of submodules, only changes to the commits stored in the superproject are shown (this was the behavior before 1.7.0). Using "all" hides all changes to submodules (and suppresses the output of submodule summaries when the config option status.submodulesummary is set).
I find typing in the flag very annoying. Of course you can create an alias for this, but I don’t like that either. There must be a better way. And there is. Once you added a submodule there will be a file named
.gitmodules in the root of your repository. The entries in this file look basically like this:
[submodule "bundle/fugitive"] path = bundle/fugitive url = git://github.com/tpope/vim-fugitive.git
Just add a single line to it and be happy:
[submodule "bundle/fugitive"] path = bundle/fugitive url = git://github.com/tpope/vim-fugitive.git ignore = dirty
Does not work? Did not work for me at first either. It took me about half an hour to figure out my git version is to old. Ubuntu 10.04 comes with git 18.104.22.168 or something. I just downloaded and compiled 22.214.171.124 as described here (I chose the 3rd way) and suddenly it worked like intended.
Hint: If you want the manpages for git to be installed as well you have to run
sudo make install-man. They are necessary to be able to use
git help <command>. This may require the additional packages
docbook2x, you can just install them with
sudo apt-get install asciidoc docbook2x.