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

From: Christopher Wilson <[email-masked]>
Date: Tue, 24 May 2011 00:06:01 -0700

On 5/23/11 6:19 PM, Mark Levedahl wrote:
> On 05/23/2011 02:43 PM, Jens Lehmann wrote:
>> Am 22.05.2011 22:02, schrieb Christopher Wilson:
>>
>> Hmm, this looks like an inconsistency to me too. It would be great
>> to hear about the background, so I added Mark to the CC, maybe he
>> can shed some light.
>>
> I think the comment in c2f939170c651 describes the reasoning well
> enough. (You may disagree with the reasoning, but that is a different
> matter :^).
> 
> Mark

Mark, thanks for the reply.  Maybe I'm a bit daft, but I'm still a
little confused by your comment in the commit :)

I've included your commit message below with my questions interlaced.

C: "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."

Q: Why don't we go through "git submodule init" to register the
submodule?  Isn't that the whole point of having a separate "submodule
init" command, to register the module in .git/config?

C: "Thus, the submodule's origin repository URL is not stored in
.git/config, and no subsequent submodule operation will ever do so."

I'm not sure this is true.  For example:

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

# At this point, I opened up .git/config in an editor and removed the
entire submodule section.

$ cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
$ git submodule init
$ cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
[submodule "submodule"]
    url = [email-masked]:submodule.git

Q: As far as I can tell, a subsequent submodule operation (git submodule
init) has stored the submodule's origin repository URL in .git/config.
Can you elaborate on what you meant by the statement "no subsequent
submodule operation will ever do so"?

C: "In this case, assume the URL the user supplies to "submodule add" is
the one that should be registered, and do so."

Q: Can you elaborate on why a 2 step "git submodule add" + "git
submodule init" wasn't sufficient?  What is the reason for adding this
functionality into the "git submodule add" command, when "git submodule
init" does the same job?

Again, sorry if I'm asking dumb questions... :)  Just want to understand
the context for your commit.