]> git.ipfire.org Git - thirdparty/git.git/commit - submodule.c
allow do_submodule_path to work even if submodule isn't checked out
authorJacob Keller <jacob.keller@gmail.com>
Wed, 31 Aug 2016 23:27:22 +0000 (16:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Sep 2016 01:07:10 +0000 (18:07 -0700)
commit99b43a61f2daf5fe183056e5bf2a75a8a81a28bf
tree1d1b35c5f3f04c9b60c37e26ca165769ba1d922e
parent61cfbc054d8341c3276efbf1380a2be0ee435dba
allow do_submodule_path to work even if submodule isn't checked out

Currently, do_submodule_path will attempt locating the .git directory by
using read_gitfile on <path>/.git. If this fails it just assumes the
<path>/.git is actually a git directory.

This is good because it allows for handling submodules which were cloned
in a regular manner first before being added to the superproject.

Unfortunately this fails if the <path> is not actually checked out any
longer, such as by removing the directory.

Fix this by checking if the directory we found is actually a gitdir. In
the case it is not, attempt to lookup the submodule configuration and
find the name of where it is stored in the .git/modules/ directory of
the superproject.

If we can't locate the submodule configuration, this might occur because
for example a submodule gitlink was added but the corresponding
.gitmodules file was not properly updated.  A die() here would not be
pleasant to the users of submodule diff formats, so instead, modify
do_submodule_path() to return an error code:

 - git_pathdup_submodule() returns NULL when we fail to find a path.
 - strbuf_git_path_submodule() propagates the error code to the caller.

Modify the callers of these functions to check the error code and fail
properly. This ensures we don't attempt to use a bad path that doesn't
match the corresponding submodule.

Because this change fixes add_submodule_odb() to work even if the
submodule is not checked out, update the wording of the submodule log
diff format to correctly display that the submodule is "not initialized"
instead of "not checked out"

Add tests to ensure this change works as expected.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
path.c
refs/files-backend.c
submodule.c
t/t4059-diff-submodule-not-initialized.sh [new file with mode: 0755]