Search code examples
gitgit-submodulesgit-config

Git config "bad config file line" in a submodule


I use git on Windows and Linux, and I have recently ran into a strange issue that manifests only on Windows... Let's say I have two projects. Both are versioned in git, and each has a submodule.


Project 1

the submodule config is located in C:\Projects\project1\.git\modules\plugins\tasks\config and looks like this:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    worktree = ..\..\..\..\plugins\tasks
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    url = ssh://domain/repo/path
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

Project 2

The submodule configuration is located in C:\Projects\project2\.git\modules\doc\preamble\config, and I also provide it below:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    worktree = ../../../../doc/preamble
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    url = ssh://domain/another/repo/path
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

To sum up, the only real difference between the configuration files is the / and \ in paths to working directory.


Issue

I operate in Git Bash. When I do git status (and some other simple commands) in Project 1 and its submodule:

/c/Projects/project1 (devel) $ git status
fatal: bad config file line 6 in c:/Projects/project1/.git/modules/plugins/tasks/config
fatal: 'git status --porcelain' failed in submodule plugins/tasks

/c/Projects/project1/plugins/tasks $ git status
fatal: bad config file line 6 in d:/Projects/project1/.git/modules/plugins/tasks/config

/c/Projects/project1 (devel) $ git submodule sync -- plugins/tasks/
Synchronizing submodule url for 'plugins/tasks'
fatal: bad config file line 6 in c:/Projects/project1/.git/modules/plugins/tasks/config

Also, git submodule init or update or update --init give no output, and don't improve the situation.

While, when I use git in Project 2, everything is ok.

You'd think that the naive solution is to substitute the slashes in the submodule config by hand, more elaborate solution would be to write a script that does that in all affected submodules.

Unfortunately, actually, changing the path in 1st config from:

worktree = ..\..\..\..\plugins\tasks

to:

worktree = ../../../../plugins/tasks

results in a different error:

/c/Projects/project1/plugins/tasks $ git status
fatal: bad object HEAD

and when I look into the file c/Projects/project1/.git/modules/plugins/tasks/refs/master something is wrong there, as the SHA1 inside is:

0000000000000000000000000000000000000000

At this point, after I did git reset --hard origin/master (in the submodule) the repository of the submodule was restored to usable state.

But, what went wrong there in the first place?

If possible, I would like to know why did this issue even occur? Does this have anything to do with the original platform of the project? Does it matter how I initialize the submodule? I would like to track down the reason of the issue to avoid it in the future.


Solution

    1. Despite being in Windows, git thinks like a UNIX program so forward slashes are the right thing. See http://gitbyexample.org/ for some examples of using forward slashes in Windows git.
    2. Something is broke in your repo. I'm not sure what, but before fighting with it too much, can you reclone? Rename the old top directory from project1 to project1.fubar and redo git clone foo://project1 and your directories should end up correct.