]> git.ipfire.org Git - thirdparty/git.git/commit - git-submodule.sh
submodule add: Fail when .git/modules/<name> already exists unless forced
authorJens Lehmann <Jens.Lehmann@web.de>
Sun, 30 Sep 2012 21:01:29 +0000 (23:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 30 Sep 2012 23:53:57 +0000 (16:53 -0700)
commit4b7c286ec74c7bb88e9e7ac2d283d86f64b6b0ea
tree6825a9ffe4b1467939ea77c1b513dd368abdfd8a
parent73b0898d0d04d432525f9d56e29bf70fc7bf6ea9
submodule add: Fail when .git/modules/<name> already exists unless forced

When adding a new submodule it can happen that .git/modules/<name> already
contains a submodule repo, e.g. when a submodule is removed from the work
tree and another submodule is added at the same path. But then the work
tree of the submodule will be populated using the existing repository and
not the one the user provided, which results in an incorrect work tree. On
the other hand the user might reactivate a submodule removed earlier, then
reusing that .git directory is the Right Thing to do.

As git can't decide what is the case, error out and tell the user she
should use either use a different name for the submodule with the "--name"
option or can reuse the .git directory for the newly added submodule by
providing the --force option (which only makes sense when the upstream
matches, so the error message lists all remotes of .git/modules/<name>).

In one test in t7406 the --force option had to be added to "git submodule
add", as that test re-adds a formerly removed submodule.

Reported-by: Jonathan Johnson <me@jondavidjohn.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-submodule.sh
t/t7400-submodule-basic.sh
t/t7406-submodule-update.sh