aboutsummaryrefslogtreecommitdiff
path: root/refs
diff options
context:
space:
mode:
authorJacob Keller <jacob.keller@gmail.com>2016-08-31 16:27:22 -0700
committerJunio C Hamano <gitster@pobox.com>2016-08-31 18:07:10 -0700
commit99b43a61f2daf5fe183056e5bf2a75a8a81a28bf (patch)
tree1d1b35c5f3f04c9b60c37e26ca165769ba1d922e /refs
parent61cfbc054d8341c3276efbf1380a2be0ee435dba (diff)
downloadgit-99b43a61f2daf5fe183056e5bf2a75a8a81a28bf.tar.gz
git-99b43a61f2daf5fe183056e5bf2a75a8a81a28bf.tar.xz
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>
Diffstat (limited to 'refs')
-rw-r--r--refs/files-backend.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 12290d249..1f34b444a 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1225,13 +1225,19 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
struct strbuf refname;
struct strbuf path = STRBUF_INIT;
size_t path_baselen;
+ int err = 0;
if (*refs->name)
- strbuf_git_path_submodule(&path, refs->name, "%s", dirname);
+ err = strbuf_git_path_submodule(&path, refs->name, "%s", dirname);
else
strbuf_git_path(&path, "%s", dirname);
path_baselen = path.len;
+ if (err) {
+ strbuf_release(&path);
+ return;
+ }
+
d = opendir(path.buf);
if (!d) {
strbuf_release(&path);