Skip to content

Commit 69fe57e

Browse files
10ne1gitster
authored andcommitted
submodule--helper: use submodule_name_to_gitdir in add_submodule
While testing submodule gitdir path encoding, I noticed submodule--helper is still using a hardcoded modules gitdir path leading to test failures. Call the submodule_name_to_gitdir() helper instead, which was invented exactly for this purpose and is already used by all the other locations which work on gitdirs. Also narrow the scope of the submod_gitdir_path variable which is not used anymore in the updated "else" branch. Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4badef0 commit 69fe57e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

builtin/submodule--helper.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3187,13 +3187,13 @@ static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path)
31873187

31883188
static int add_submodule(const struct add_data *add_data)
31893189
{
3190-
char *submod_gitdir_path;
31913190
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
31923191
struct string_list reference = STRING_LIST_INIT_NODUP;
31933192
int ret = -1;
31943193

31953194
/* perhaps the path already exists and is already a git repo, else clone it */
31963195
if (is_directory(add_data->sm_path)) {
3196+
char *submod_gitdir_path;
31973197
struct strbuf sm_path = STRBUF_INIT;
31983198
strbuf_addstr(&sm_path, add_data->sm_path);
31993199
submod_gitdir_path = xstrfmt("%s/.git", add_data->sm_path);
@@ -3207,10 +3207,11 @@ static int add_submodule(const struct add_data *add_data)
32073207
free(submod_gitdir_path);
32083208
} else {
32093209
struct child_process cp = CHILD_PROCESS_INIT;
3210+
struct strbuf submod_gitdir = STRBUF_INIT;
32103211

3211-
submod_gitdir_path = xstrfmt(".git/modules/%s", add_data->sm_name);
3212+
submodule_name_to_gitdir(&submod_gitdir, the_repository, add_data->sm_name);
32123213

3213-
if (is_directory(submod_gitdir_path)) {
3214+
if (is_directory(submod_gitdir.buf)) {
32143215
if (!add_data->force) {
32153216
struct strbuf msg = STRBUF_INIT;
32163217
char *die_msg;
@@ -3219,8 +3220,8 @@ static int add_submodule(const struct add_data *add_data)
32193220
"locally with remote(s):\n"),
32203221
add_data->sm_name);
32213222

3222-
append_fetch_remotes(&msg, submod_gitdir_path);
3223-
free(submod_gitdir_path);
3223+
append_fetch_remotes(&msg, submod_gitdir.buf);
3224+
strbuf_release(&submod_gitdir);
32243225

32253226
strbuf_addf(&msg, _("If you want to reuse this local git "
32263227
"directory instead of cloning again from\n"
@@ -3238,7 +3239,7 @@ static int add_submodule(const struct add_data *add_data)
32383239
"submodule '%s'\n"), add_data->sm_name);
32393240
}
32403241
}
3241-
free(submod_gitdir_path);
3242+
strbuf_release(&submod_gitdir);
32423243

32433244
clone_data.prefix = add_data->prefix;
32443245
clone_data.path = add_data->sm_path;

0 commit comments

Comments
 (0)