summaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2018-06-14 17:31:07 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-06-14 21:02:23 (GMT)
commit5fc84755f1478ea8c0f05b8d7be67a3c96a24bff (patch)
tree5562bbacdfc79557d555b829a93f7f89f25a1d61 /submodule.c
parent68372c88794aba15f853542008cda39def768372 (diff)
downloadgit-5fc84755f1478ea8c0f05b8d7be67a3c96a24bff.zip
git-5fc84755f1478ea8c0f05b8d7be67a3c96a24bff.tar.gz
git-5fc84755f1478ea8c0f05b8d7be67a3c96a24bff.tar.bz2
submodule: fix NULL correctness in renamed broken submodules
When fetching with recursing into submodules, the fetch logic inspects the superproject which submodules actually need to be fetched. This is tricky for submodules that were renamed in the fetched range of commits. This was implemented in c68f8375760 (implement fetching of moved submodules, 2017-10-16), and this patch fixes a mistake in the logic there. When the warning is printed, the `name` might be NULL as default_name_or_path can return NULL, so fix the warning to use the path as obtained from the diff machinery, as that is not NULL. While at it, make sure we only attempt to load the submodule if a git directory of the submodule is found as default_name_or_path will return NULL in case the git directory cannot be found. Note that passing NULL to submodule_from_name is just a semantic error, as submodule_from_name accepts NULL as a value, but then the return value is not the submodule that was asked for, but some arbitrary other submodule. (Cf. 'config_from' in submodule-config.c: "If any parameter except the cache is a NULL pointer just return the first submodule. Can be used to check whether there are any submodules parsed.") Reported-by: Duy Nguyen <pclouds@gmail.com> Helped-by: Duy Nguyen <pclouds@gmail.com> Helped-by: Heiko Voigt <hvoigt@hvoigt.net> Signed-off-by: Stefan Beller <sbeller@google.com> Acked-by: Heiko Voigt <hvoigt@hvoigt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/submodule.c b/submodule.c
index 939d687..0998ea2 100644
--- a/submodule.c
+++ b/submodule.c
@@ -740,12 +740,14 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
else {
name = default_name_or_path(p->two->path);
/* make sure name does not collide with existing one */
- submodule = submodule_from_name(the_repository, commit_oid, name);
+ if (name)
+ submodule = submodule_from_name(the_repository,
+ commit_oid, name);
if (submodule) {
warning("Submodule in commit %s at path: "
"'%s' collides with a submodule named "
"the same. Skipping it.",
- oid_to_hex(commit_oid), name);
+ oid_to_hex(commit_oid), p->two->path);
name = NULL;
}
}