Skip to content

Commit 03bd616

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 name-based path leading to test failures, so convert it to the common helper function introduced by commit ce125d4 (submodule: extract path to submodule gitdir func, 2021-09-15) and used in other locations across the source tree. Signed-off-by: Adrian Ratiu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e5ab6b3 commit 03bd616

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
@@ -3193,13 +3193,13 @@ static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path)
31933193

31943194
static int add_submodule(const struct add_data *add_data)
31953195
{
3196-
char *submod_gitdir_path;
31973196
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
31983197
struct string_list reference = STRING_LIST_INIT_NODUP;
31993198
int ret = -1;
32003199

32013200
/* perhaps the path already exists and is already a git repo, else clone it */
32023201
if (is_directory(add_data->sm_path)) {
3202+
char *submod_gitdir_path;
32033203
struct strbuf sm_path = STRBUF_INIT;
32043204
strbuf_addstr(&sm_path, add_data->sm_path);
32053205
submod_gitdir_path = xstrfmt("%s/.git", add_data->sm_path);
@@ -3213,10 +3213,11 @@ static int add_submodule(const struct add_data *add_data)
32133213
free(submod_gitdir_path);
32143214
} else {
32153215
struct child_process cp = CHILD_PROCESS_INIT;
3216+
struct strbuf submod_gitdir = STRBUF_INIT;
32163217

3217-
submod_gitdir_path = xstrfmt(".git/modules/%s", add_data->sm_name);
3218+
submodule_name_to_gitdir(&submod_gitdir, the_repository, add_data->sm_name);
32183219

3219-
if (is_directory(submod_gitdir_path)) {
3220+
if (is_directory(submod_gitdir.buf)) {
32203221
if (!add_data->force) {
32213222
struct strbuf msg = STRBUF_INIT;
32223223
char *die_msg;
@@ -3225,8 +3226,8 @@ static int add_submodule(const struct add_data *add_data)
32253226
"locally with remote(s):\n"),
32263227
add_data->sm_name);
32273228

3228-
append_fetch_remotes(&msg, submod_gitdir_path);
3229-
free(submod_gitdir_path);
3229+
append_fetch_remotes(&msg, submod_gitdir.buf);
3230+
strbuf_release(&submod_gitdir);
32303231

32313232
strbuf_addf(&msg, _("If you want to reuse this local git "
32323233
"directory instead of cloning again from\n"
@@ -3244,7 +3245,7 @@ static int add_submodule(const struct add_data *add_data)
32443245
"submodule '%s'\n"), add_data->sm_name);
32453246
}
32463247
}
3247-
free(submod_gitdir_path);
3248+
strbuf_release(&submod_gitdir);
32483249

32493250
clone_data.prefix = add_data->prefix;
32503251
clone_data.path = add_data->sm_path;

0 commit comments

Comments
 (0)