summaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2018-06-12 23:58:23 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-06-14 21:13:46 (GMT)
commit4fa4f90ccd85842e1187e5a5daf4633dceaab779 (patch)
treeee43fe2b82b49e9488c87f2462acf322791058cd /submodule.c
parent68372c88794aba15f853542008cda39def768372 (diff)
downloadgit-4fa4f90ccd85842e1187e5a5daf4633dceaab779.zip
git-4fa4f90ccd85842e1187e5a5daf4633dceaab779.tar.gz
git-4fa4f90ccd85842e1187e5a5daf4633dceaab779.tar.bz2
submodule: unset core.worktree if no working tree is present
When a submodules work tree is removed, we should unset its core.worktree setting as the worktree is no longer present. This is not just in line with the conceptual view of submodules, but it fixes an inconvenience for looking at submodules that are not checked out: git clone --recurse-submodules git://github.com/git/git && cd git && git checkout --recurse-submodules v2.13.0 git -C .git/modules/sha1collisiondetection log fatal: cannot chdir to '../../../sha1collisiondetection': \ No such file or directory With this patch applied, the final call to git log works instead of dying in its setup, as the checkout will unset the core.worktree setting such that following log will be run in a bare repository. This patch covers all commands that are in the unpack machinery, i.e. checkout, read-tree, reset. A follow up patch will address "git submodule deinit", which will also make use of the new function submodule_unset_core_worktree(), which is why we expose it in this patch. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/submodule.c b/submodule.c
index 939d687..e127c07 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1532,6 +1532,18 @@ out:
return ret;
}
+void submodule_unset_core_worktree(const struct submodule *sub)
+{
+ char *config_path = xstrfmt("%s/modules/%s/config",
+ get_git_common_dir(), sub->name);
+
+ if (git_config_set_in_file_gently(config_path, "core.worktree", NULL))
+ warning(_("Could not unset core.worktree setting in submodule '%s'"),
+ sub->path);
+
+ free(config_path);
+}
+
static const char *get_super_prefix_or_empty(void)
{
const char *s = get_super_prefix();
@@ -1697,6 +1709,8 @@ int submodule_move_head(const char *path,
if (is_empty_dir(path))
rmdir_or_warn(path);
+
+ submodule_unset_core_worktree(sub);
}
}
out: