1819
1820
void submodule_unset_core_worktree(const struct submodule *sub)
1821
{
1822
- char *config_path = xstrfmt("%s/modules/%s/config",
1823
- get_git_dir(), sub->name);
1822
+ struct strbuf config_path = STRBUF_INIT;
1823
1825
- if (git_config_set_in_file_gently(config_path, "core.worktree", NULL))
1824
+ submodule_name_to_gitdir(&config_path, the_repository, sub->name);
1825
+ strbuf_addstr(&config_path, "/config");
1826
+
1827
+ if (git_config_set_in_file_gently(config_path.buf, "core.worktree", NULL))
1828
warning(_("Could not unset core.worktree setting in submodule '%s'"),
1829
sub->path);
1830
1829
- free(config_path);
1831
+ strbuf_release(&config_path);
1832
}
1833
1834
static const char *get_super_prefix_or_empty(void)
1924
absorb_git_dir_into_superproject(path,
1925
ABSORB_GITDIR_RECURSE_SUBMODULES);
1926
} else {
1925
- char *gitdir = xstrfmt("%s/modules/%s",
1926
- get_git_dir(), sub->name);
1927
- connect_work_tree_and_git_dir(path, gitdir, 0);
1928
- free(gitdir);
1927
+ struct strbuf gitdir = STRBUF_INIT;
1928
+ submodule_name_to_gitdir(&gitdir, the_repository,
1929
+ sub->name);
1930
+ connect_work_tree_and_git_dir(path, gitdir.buf, 0);
1931
+ strbuf_release(&gitdir);
1932
1933
/* make sure the index is clean as well */
1934
submodule_reset_index(path);
1935
}
1936
1937
if (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE)) {
1935
- char *gitdir = xstrfmt("%s/modules/%s",
1936
- get_git_dir(), sub->name);
1937
- connect_work_tree_and_git_dir(path, gitdir, 1);
1938
- free(gitdir);
1938
+ struct strbuf gitdir = STRBUF_INIT;
1939
+ submodule_name_to_gitdir(&gitdir, the_repository,
1940
+ sub->name);
1941
+ connect_work_tree_and_git_dir(path, gitdir.buf, 1);
1942
+ strbuf_release(&gitdir);
1943
}
1944
}
1945
2054
static void relocate_single_git_dir_into_superproject(const char *path)
2055
{
2056
char *old_git_dir = NULL, *real_old_git_dir = NULL, *real_new_git_dir = NULL;
2053
- char *new_git_dir;
2057
+ struct strbuf new_gitdir = STRBUF_INIT;
2058
const struct submodule *sub;
2059
2060
if (submodule_uses_worktrees(path))
2072
if (!sub)
2073
die(_("could not lookup name for submodule '%s'"), path);
2074
2071
- new_git_dir = git_pathdup("modules/%s", sub->name);
2072
- if (validate_submodule_git_dir(new_git_dir, sub->name) < 0)
2075
+ submodule_name_to_gitdir(&new_gitdir, the_repository, sub->name);
2076
+ if (validate_submodule_git_dir(new_gitdir.buf, sub->name) < 0)
2077
die(_("refusing to move '%s' into an existing git dir"),
2078
real_old_git_dir);
2075
- if (safe_create_leading_directories_const(new_git_dir) < 0)
2076
- die(_("could not create directory '%s'"), new_git_dir);
2077
- real_new_git_dir = real_pathdup(new_git_dir, 1);
2078
- free(new_git_dir);
2079
+ if (safe_create_leading_directories_const(new_gitdir.buf) < 0)
2080
+ die(_("could not create directory '%s'"), new_gitdir.buf);
2081
+ real_new_git_dir = real_pathdup(new_gitdir.buf, 1);
2082
2083
fprintf(stderr, _("Migrating git directory of '%s%s' from\n'%s' to\n'%s'\n"),
2084
get_super_prefix_or_empty(), path,
2089
free(old_git_dir);
2090
free(real_old_git_dir);
2091
free(real_new_git_dir);
2092
+ strbuf_release(&new_gitdir);
2093
}
2094
2095
/*
2109
/* Not populated? */
2110
if (!sub_git_dir) {
2111
const struct submodule *sub;
2112
+ struct strbuf sub_gitdir = STRBUF_INIT;
2113
2114
if (err_code == READ_GITFILE_ERR_STAT_FAILED) {
2115
/* unpopulated as expected */
2131
sub = submodule_from_path(the_repository, null_oid(), path);
2132
if (!sub)
2133
die(_("could not lookup name for submodule '%s'"), path);
2129
- connect_work_tree_and_git_dir(path,
2130
- git_path("modules/%s", sub->name), 0);
2134
+ submodule_name_to_gitdir(&sub_gitdir, the_repository, sub->name);
2135
+ connect_work_tree_and_git_dir(path, sub_gitdir.buf, 0);
2136
+ strbuf_release(&sub_gitdir);
2137
} else {
2138
/* Is it already absorbed into the superprojects git dir? */
2139
char *real_sub_git_dir = real_pathdup(sub_git_dir, 1);
2284
goto cleanup;
2285
}
2286
strbuf_reset(buf);
2281
- strbuf_git_path(buf, "%s/%s", "modules", sub->name);
2287
+ submodule_name_to_gitdir(buf, the_repository, sub->name);
2288
}
2289
2290
cleanup:
2291
return ret;
2292
}
2293
+
2294
+void submodule_name_to_gitdir(struct strbuf *buf, struct repository *r,
2295
+ const char *submodule_name)
2296
+{
2297
+ /*
2298
+ * NEEDSWORK: The current way of mapping a submodule's name to
2299
+ * its location in .git/modules/ has problems with some naming
2300
+ * schemes. For example, if a submodule is named "foo" and
2301
+ * another is named "foo/bar" (whether present in the same
2302
+ * superproject commit or not - the problem will arise if both
2303
+ * superproject commits have been checked out at any point in
2304
+ * time), or if two submodule names only have different cases in
2305
+ * a case-insensitive filesystem.
2306
+ *
2307
+ * There are several solutions, including encoding the path in
2308
+ * some way, introducing a submodule.<name>.gitdir config in
2309
+ * .git/config (not .gitmodules) that allows overriding what the
2310
+ * gitdir of a submodule would be (and teach Git, upon noticing
2311
+ * a clash, to automatically determine a non-clashing name and
2312
+ * to write such a config), or introducing a
2313
+ * submodule.<name>.gitdir config in .gitmodules that repo
2314
+ * administrators can explicitly set. Nothing has been decided,
2315
+ * so for now, just append the name at the end of the path.
2316
+ */
2317
+ strbuf_repo_git_path(buf, r, "modules/");
2318
+ strbuf_addstr(buf, submodule_name);
2319
+}