@@ -1204,6 +1204,22 @@ static int module_summary(int argc, const char **argv, const char *prefix,
12041204 return ret ;
12051205}
12061206
1207+ static int module_gitdir (int argc , const char * * argv , const char * prefix UNUSED ,
1208+ struct repository * repo )
1209+ {
1210+ struct strbuf gitdir = STRBUF_INIT ;
1211+
1212+ if (argc != 2 )
1213+ usage (_ ("git submodule--helper gitdir <name>" ));
1214+
1215+ submodule_name_to_gitdir (& gitdir , repo , argv [1 ]);
1216+
1217+ printf ("%s\n" , gitdir .buf );
1218+
1219+ strbuf_release (& gitdir );
1220+ return 0 ;
1221+ }
1222+
12071223struct sync_cb {
12081224 const char * prefix ;
12091225 const char * super_prefix ;
@@ -3183,13 +3199,13 @@ static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path)
31833199
31843200static int add_submodule (const struct add_data * add_data )
31853201{
3186- char * submod_gitdir_path ;
31873202 struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT ;
31883203 struct string_list reference = STRING_LIST_INIT_NODUP ;
31893204 int ret = -1 ;
31903205
31913206 /* perhaps the path already exists and is already a git repo, else clone it */
31923207 if (is_directory (add_data -> sm_path )) {
3208+ char * submod_gitdir_path ;
31933209 struct strbuf sm_path = STRBUF_INIT ;
31943210 strbuf_addstr (& sm_path , add_data -> sm_path );
31953211 submod_gitdir_path = xstrfmt ("%s/.git" , add_data -> sm_path );
@@ -3203,10 +3219,11 @@ static int add_submodule(const struct add_data *add_data)
32033219 free (submod_gitdir_path );
32043220 } else {
32053221 struct child_process cp = CHILD_PROCESS_INIT ;
3222+ struct strbuf submod_gitdir = STRBUF_INIT ;
32063223
3207- submod_gitdir_path = xstrfmt ( ".git/modules/%s" , add_data -> sm_name );
3224+ submodule_name_to_gitdir ( & submod_gitdir , the_repository , add_data -> sm_name );
32083225
3209- if (is_directory (submod_gitdir_path )) {
3226+ if (is_directory (submod_gitdir . buf )) {
32103227 if (!add_data -> force ) {
32113228 struct strbuf msg = STRBUF_INIT ;
32123229 char * die_msg ;
@@ -3215,8 +3232,8 @@ static int add_submodule(const struct add_data *add_data)
32153232 "locally with remote(s):\n" ),
32163233 add_data -> sm_name );
32173234
3218- append_fetch_remotes (& msg , submod_gitdir_path );
3219- free ( submod_gitdir_path );
3235+ append_fetch_remotes (& msg , submod_gitdir . buf );
3236+ strbuf_release ( & submod_gitdir );
32203237
32213238 strbuf_addf (& msg , _ ("If you want to reuse this local git "
32223239 "directory instead of cloning again from\n"
@@ -3234,7 +3251,7 @@ static int add_submodule(const struct add_data *add_data)
32343251 "submodule '%s'\n" ), add_data -> sm_name );
32353252 }
32363253 }
3237- free ( submod_gitdir_path );
3254+ strbuf_release ( & submod_gitdir );
32383255
32393256 clone_data .prefix = add_data -> prefix ;
32403257 clone_data .path = add_data -> sm_path ;
@@ -3586,6 +3603,7 @@ int cmd_submodule__helper(int argc,
35863603 NULL
35873604 };
35883605 struct option options [] = {
3606+ OPT_SUBCOMMAND ("gitdir" , & fn , module_gitdir ),
35893607 OPT_SUBCOMMAND ("clone" , & fn , module_clone ),
35903608 OPT_SUBCOMMAND ("add" , & fn , module_add ),
35913609 OPT_SUBCOMMAND ("update" , & fn , module_update ),
0 commit comments