@@ -1819,14 +1819,16 @@ int bad_to_remove_submodule(const char *path, unsigned flags)
1819
1819
1820
1820
void submodule_unset_core_worktree (const struct submodule * sub )
1821
1821
{
1822
- char * config_path = xstrfmt ("%s/modules/%s/config" ,
1823
- get_git_dir (), sub -> name );
1822
+ struct strbuf config_path = STRBUF_INIT ;
1824
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 ))
1826
1828
warning (_ ("Could not unset core.worktree setting in submodule '%s'" ),
1827
1829
sub -> path );
1828
1830
1829
- free ( config_path );
1831
+ strbuf_release ( & config_path );
1830
1832
}
1831
1833
1832
1834
static const char * get_super_prefix_or_empty (void )
@@ -1922,20 +1924,22 @@ int submodule_move_head(const char *path,
1922
1924
absorb_git_dir_into_superproject (path ,
1923
1925
ABSORB_GITDIR_RECURSE_SUBMODULES );
1924
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 );
1929
1932
1930
1933
/* make sure the index is clean as well */
1931
1934
submodule_reset_index (path );
1932
1935
}
1933
1936
1934
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 );
1939
1943
}
1940
1944
}
1941
1945
@@ -2050,7 +2054,7 @@ int validate_submodule_git_dir(char *git_dir, const char *submodule_name)
2050
2054
static void relocate_single_git_dir_into_superproject (const char * path )
2051
2055
{
2052
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 ;
2054
2058
const struct submodule * sub ;
2055
2059
2056
2060
if (submodule_uses_worktrees (path ))
@@ -2068,14 +2072,13 @@ static void relocate_single_git_dir_into_superproject(const char *path)
2068
2072
if (!sub )
2069
2073
die (_ ("could not lookup name for submodule '%s'" ), path );
2070
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 )
2073
2077
die (_ ("refusing to move '%s' into an existing git dir" ),
2074
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 );
2079
2082
2080
2083
fprintf (stderr , _ ("Migrating git directory of '%s%s' from\n'%s' to\n'%s'\n" ),
2081
2084
get_super_prefix_or_empty (), path ,
@@ -2086,6 +2089,7 @@ static void relocate_single_git_dir_into_superproject(const char *path)
2086
2089
free (old_git_dir );
2087
2090
free (real_old_git_dir );
2088
2091
free (real_new_git_dir );
2092
+ strbuf_release (& new_gitdir );
2089
2093
}
2090
2094
2091
2095
/*
@@ -2105,6 +2109,7 @@ void absorb_git_dir_into_superproject(const char *path,
2105
2109
/* Not populated? */
2106
2110
if (!sub_git_dir ) {
2107
2111
const struct submodule * sub ;
2112
+ struct strbuf sub_gitdir = STRBUF_INIT ;
2108
2113
2109
2114
if (err_code == READ_GITFILE_ERR_STAT_FAILED ) {
2110
2115
/* unpopulated as expected */
@@ -2126,8 +2131,9 @@ void absorb_git_dir_into_superproject(const char *path,
2126
2131
sub = submodule_from_path (the_repository , null_oid (), path );
2127
2132
if (!sub )
2128
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 );
2131
2137
} else {
2132
2138
/* Is it already absorbed into the superprojects git dir? */
2133
2139
char * real_sub_git_dir = real_pathdup (sub_git_dir , 1 );
@@ -2278,9 +2284,36 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
2278
2284
goto cleanup ;
2279
2285
}
2280
2286
strbuf_reset (buf );
2281
- strbuf_git_path (buf , "%s/%s" , "modules" , sub -> name );
2287
+ submodule_name_to_gitdir (buf , the_repository , sub -> name );
2282
2288
}
2283
2289
2284
2290
cleanup :
2285
2291
return ret ;
2286
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
+ }
0 commit comments