@@ -1208,6 +1208,22 @@ static int module_summary(int argc, const char **argv, const char *prefix,
1208
1208
return ret ;
1209
1209
}
1210
1210
1211
+ static int module_gitdir (int argc , const char * * argv , const char * prefix UNUSED ,
1212
+ struct repository * repo )
1213
+ {
1214
+ struct strbuf gitdir = STRBUF_INIT ;
1215
+
1216
+ if (argc != 2 )
1217
+ usage (_ ("git submodule--helper gitdir <name>" ));
1218
+
1219
+ submodule_name_to_gitdir (& gitdir , repo , argv [1 ]);
1220
+
1221
+ printf ("%s\n" , gitdir .buf );
1222
+
1223
+ strbuf_release (& gitdir );
1224
+ return 0 ;
1225
+ }
1226
+
1211
1227
struct sync_cb {
1212
1228
const char * prefix ;
1213
1229
const char * super_prefix ;
@@ -3187,13 +3203,13 @@ static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path)
3187
3203
3188
3204
static int add_submodule (const struct add_data * add_data )
3189
3205
{
3190
- char * submod_gitdir_path ;
3191
3206
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT ;
3192
3207
struct string_list reference = STRING_LIST_INIT_NODUP ;
3193
3208
int ret = -1 ;
3194
3209
3195
3210
/* perhaps the path already exists and is already a git repo, else clone it */
3196
3211
if (is_directory (add_data -> sm_path )) {
3212
+ char * submod_gitdir_path ;
3197
3213
struct strbuf sm_path = STRBUF_INIT ;
3198
3214
strbuf_addstr (& sm_path , add_data -> sm_path );
3199
3215
submod_gitdir_path = xstrfmt ("%s/.git" , add_data -> sm_path );
@@ -3207,10 +3223,11 @@ static int add_submodule(const struct add_data *add_data)
3207
3223
free (submod_gitdir_path );
3208
3224
} else {
3209
3225
struct child_process cp = CHILD_PROCESS_INIT ;
3226
+ struct strbuf submod_gitdir = STRBUF_INIT ;
3210
3227
3211
- submod_gitdir_path = xstrfmt ( ".git/modules/%s" , add_data -> sm_name );
3228
+ submodule_name_to_gitdir ( & submod_gitdir , the_repository , add_data -> sm_name );
3212
3229
3213
- if (is_directory (submod_gitdir_path )) {
3230
+ if (is_directory (submod_gitdir . buf )) {
3214
3231
if (!add_data -> force ) {
3215
3232
struct strbuf msg = STRBUF_INIT ;
3216
3233
char * die_msg ;
@@ -3219,8 +3236,8 @@ static int add_submodule(const struct add_data *add_data)
3219
3236
"locally with remote(s):\n" ),
3220
3237
add_data -> sm_name );
3221
3238
3222
- append_fetch_remotes (& msg , submod_gitdir_path );
3223
- free ( submod_gitdir_path );
3239
+ append_fetch_remotes (& msg , submod_gitdir . buf );
3240
+ strbuf_release ( & submod_gitdir );
3224
3241
3225
3242
strbuf_addf (& msg , _ ("If you want to reuse this local git "
3226
3243
"directory instead of cloning again from\n"
@@ -3238,7 +3255,7 @@ static int add_submodule(const struct add_data *add_data)
3238
3255
"submodule '%s'\n" ), add_data -> sm_name );
3239
3256
}
3240
3257
}
3241
- free ( submod_gitdir_path );
3258
+ strbuf_release ( & submod_gitdir );
3242
3259
3243
3260
clone_data .prefix = add_data -> prefix ;
3244
3261
clone_data .path = add_data -> sm_path ;
@@ -3590,6 +3607,7 @@ int cmd_submodule__helper(int argc,
3590
3607
NULL
3591
3608
};
3592
3609
struct option options [] = {
3610
+ OPT_SUBCOMMAND ("gitdir" , & fn , module_gitdir ),
3593
3611
OPT_SUBCOMMAND ("clone" , & fn , module_clone ),
3594
3612
OPT_SUBCOMMAND ("add" , & fn , module_add ),
3595
3613
OPT_SUBCOMMAND ("update" , & fn , module_update ),
0 commit comments