Why does adding an existing repo as a submodule change .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 git@git.server :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 git@git.server :submodule.git $ git submodule add git@git.server :submodule.git $ cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true [submodule "submodule"] url = git@git.server :submodule.git 

I would suggest that in both cases, git submodule add will only change .gitmodules , and that git submodule init updated the .git/config project.

Why is .git/config changed in the second case, but not the first? Can anyone explain the rationality of this behavior?

+6
source share
2 answers

That seems weird. This behavior was introduced in this commit :

 commit c2f939170c65173076bbd752bb3c764536b3b09b Author: Mark Levedahl < mlevedahl@gmail.com > 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 tree first, we don't go through "git submodule init" to register the module. Thus, the submodule 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 < mlevedahl@gmail.com > Signed-off-by: Junio C Hamano < gitster@pobox.com > 

Update: You indicated in the comments below that my initial interpretation of this commit post does not make any sense, so I deleted this text to avoid confusion for others.

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

+4
source

Source: https://habr.com/ru/post/888713/


All Articles