Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does adding an existing repo as a submodule modify .git/config?

If I add a submodule that does not currently exist, no submodule information is added to .git/config.

$ mkdir testing
$ cd testing
$ git init
$ git submodule add [email protected]:submodule.git
$ cat .git/config 
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true

However, if I add a repo that currently exists as a submodule, the url is added to .git/config:

$ mkdir testing
$ cd testing
$ git init
$ git clone [email protected]:submodule.git
$ git submodule add [email protected]:submodule.git
$ cat .git/config 
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
[submodule "submodule"]
    url = [email protected]:submodule.git

I would have assumed that in both cases, git submodule add would have only modified .gitmodules, and that git submodule init would have updated the project's .git/config.

Why is .git/config modified in the second case but not the first? Can somebody explain the rational for this behavior?

like image 312
cdwilson Avatar asked May 21 '11 17:05

cdwilson


2 Answers

This does seem strange. That behaviour was introduced in this commit:

commit c2f939170c65173076bbd752bb3c764536b3b09b
Author: Mark Levedahl <[email protected]>
Date:   Wed Jul 9 21:05:41 2008 -0400

    git-submodule - register submodule URL if adding in place

    When adding a new submodule in place, meaning the user created the
    submodule as a git repo in the superproject's tree first, we don't go
    through "git submodule init" to register the module.  Thus, the
    submodule's origin repository URL is not stored in .git/config, and no
    subsequent submodule operation will ever do so.  In this case, assume the
    URL the user supplies to "submodule add" is the one that should be
    registered, and do so.

    Signed-off-by: Mark Levedahl <[email protected]>
    Signed-off-by: Junio C Hamano <[email protected]>

Update: you've pointed out in the comments below that my original interpretation of this commit message didn't make any sense, so I've removed that text now to avoid confusion for others.

As mentioned in the comments below, cdwilson posted to the git mailing list to ask about this inconsistency, and as a result Jens Lehman is working on a fix - that thread can be found here:

  • http://git.661346.n2.nabble.com/Why-does-adding-an-existing-repo-as-a-submodule-modify-git-config-td6392263.html
like image 73
Mark Longair Avatar answered Oct 05 '22 23:10

Mark Longair


This issue was fixed in https://github.com/git/git/commit/2cd9de3e18183422cd7ec3cd81cebc656068ea42

like image 42
cdwilson Avatar answered Oct 05 '22 22:10

cdwilson