Search code examples
gitgit-submodules

git failing to find the index when in submodule ("index file open failed: not a directory")


On a fresh git repo, after adding a submodule and changing to the submodule directory most git commands fail when run within the submodule with the error:

fatal: index file open failed: Not a directory

The full set of commands to reproduce the issue:

>  git init .
Initialized empty Git repository in /Users/drh/code/personal/Experiments/git-test/.git/
>  git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
>  git submodule add [email protected]:mitsuhiko/flask.git thirdparty/flask
Cloning into 'thirdparty/flask'...
remote: Reusing existing pack: 9959, done.
remote: Total 9959 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (9959/9959), 5.17 MiB | 1.11 MiB/s, done.
Resolving deltas: 100% (5617/5617), done.
Checking connectivity... done.
>  cd thirdparty/flask
>  git status
fatal: index file open failed: Not a directory
>  cat .git
gitdir: ../../.git/modules/thirdparty/flask

git version 1.8.5.2 running on Mavericks


Solution

  • That is because there isn't a commit yet in the parent repo (meaning no HEAD, and no master branch).
    As you have detected, the GIT_DIR for the parent repo might be set too late for the submodule to use.
    That would be a good bug to report if none of the git submodule tests cover that scenario.

    Or, as the OP user3184153 commented:

    I think that some other application (I suspecting virtualenv, though can't reproduce) was setting GIT_DIR.