-1

Why is git telling me that the path for my submodule is ignored?

The following path is ignored by one of your .gitignore files:
multi/vim/.vim/bundle/powerline
Use -f if you really want to add it.

Here's what I'm doing:

$ git subaddvim git://github.com/Lokaltog/vim-powerline.git powerline
The following path is ignored by one of your .gitignore files:
multi/vim/.vim/bundle/powerline
Use -f if you really want to add it.
$ git help subaddvim
`git subaddvim' is aliased to `!f(){ [ $# -eq 2 ] && git submodule add $1 multi/vim/.vim/bundle/$2; };f'

Edit: Looks like it's the p in powerline:

$ git subaddvim git://github.com/Lokaltog/vim-powerline.git p
The following path is ignored by one of your .gitignore files:
multi/vim/.vim/bundle/p
Use -f if you really want to add it.
$ git subaddvim git://github.com/Lokaltog/vim-powerline.git owerline
Cloning into 'multi/vim/.vim/bundle/owerline'...

I don't understand why.

Edit 2: I found a file in the submodule clone destination:

multi/vim/.vim/bundle$ cat powerline/.git
gitdir: ../.git/modules/multi/vim/.vim/bundle/powerline

If I remove that and try again, I get a different error:

$ git subaddvim git://github.com/Lokaltog/vim-powerline.git powerline
fatal: Not a git repository: ../.git/modules/multi/vim/.vim/bundle/powerline
Unable to checkout submodule 'multi/vim/.vim/bundle/powerline'

Maybe there's some thing messed up with my .git? (I had cloned this repo yesterday and then reverted that change.)

Edit 3: I tried using git submodule directly (instead of my alias) and it worked! I can re-create the issue (sometimes) by doing git reset --hard after the clone. Seems like it's a combination of my alias not working the same as the git command git ignoring the .git file (or doing something magic that I don't understand). And maybe something to do with my .git/config having a reference to powerline.

Edit 4: My previous edit wasn't clear: Although using git submodule directly worked. It does not always work. I don't know why it worked in the first place.

I've narrowed it down to a reproducible case. It looks like the issue is caused by git assuming that submodules are in the root directory. Here's my test script.

if [ ! -d remote ] ; then
    echo
    echo Setup remote test repo 
    mkdir remote
    cd remote
    git init
    touch firstfile
    git add firstfile
    git ci -m'first'
    cd -
fi

# Pick one of these lines:
submodule=multi/plugin
# OR
submodule=plugin

echo
echo Setup test repo 
mkdir test
cd test
git init
touch firstfile
git add firstfile
git ci -m'first'

echo
echo submodule add
git submodule add ../remote $submodule
ls -ld $submodule/.git
cat $submodule/.git

echo
echo submodule remove
git reset --hard HEAD
ls -ld $submodule/.git
cat $submodule/.git
rm -r $submodule/

echo
echo submodule re-add
git submodule add ../remote $submodule
ls -ld $submodule/.git
cat $submodule/.git

Using submodule=multi/plugin will fail:

submodule re-add
fatal: Not a git repository: ../.git/modules/multi/plugin
Unable to checkout submodule 'multi/plugin'
-rw-r--r-- 1 pydave mkgroup 37 Aug  1 10:08 multi/plugin/.git
gitdir: ../.git/modules/multi/plugin

(After this, if you run git submodule add, you'll get the "following path is ignored" message.)

But submodule=plugin will succeed:

submodule re-add
-rw-r--r-- 1 pydave mkgroup 31 Aug  1 10:07 plugin/.git
gitdir: ../.git/modules/plugin

The relative paths are both using ../.git, which is only correct for the second option -- when the submodule is in the root of the git project.

I've rename this question to be more specific to my problem and re-asked the original question.

Community
  • 1
  • 1
idbrii
  • 10,975
  • 5
  • 66
  • 107
  • Do you have a global excludes file? what does `git config -l | grep exclude` say? – Jon Lin Jul 31 '12 at 21:52
  • @JonLin: `core.excludesfile=~/.gitignore` But that file doesn't have anything weird. I tried commenting out all lines and I had the same error. – idbrii Jul 31 '12 at 22:01
  • Anything in `.git/info/exclude`? – Christopher Aug 01 '12 at 02:37
  • @Christopher: exclude contains the default: All lines begin with `#` and explain how you could setup excludes. – idbrii Aug 01 '12 at 16:00
  • Alias parsing with arguments gets a little heady for [reasons linked in this answer.](http://superuser.com/a/435912/139684) Can you try reconfiguring your alias to execute with the `sh -c` syntax described there? Might have to kill the `[ $# -eq 2 ]` but would be useful for debugging. – Christopher Aug 01 '12 at 16:32

2 Answers2

1

I think the answer is that there's a bug in git when using submodules that are not in the top-level directory.

The solution is to delete the git repo for the submodule stored in .git/modules:

$ rm -fr multi/plugin/ .git/modules/multi/plugin/
$ git submodule add ../remote multi/plugin
Cloning into 'multi/plugin'...
done.
idbrii
  • 10,975
  • 5
  • 66
  • 107
0

I would stay away from git aliases for this reason and rely on bash history to remember what you have entered before. You can recall the complex one-liners with CTRL-R and other bash command line goodness. Seeing what you are doing helps keep conscious of what would be hidden by an alias. Walk over to another machine and you have a problem as you forgot what exactly you had in your alias!

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • Generally that's true, but only for commands that use the same text every time. My command only has segments that are the same and editing them to match is cumbersome and takes as long as writing the whole command. – idbrii Aug 01 '12 at 15:59