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 ce125d431a
(submodule: extract path to submodule gitdir func, 2021-09-15) and used
in other locations across the source tree.
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
seen
parent
e5ab6b3e5a
commit
03bd61652d
|
|
@ -3193,13 +3193,13 @@ static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path)
|
||||||
|
|
||||||
static int add_submodule(const struct add_data *add_data)
|
static int add_submodule(const struct add_data *add_data)
|
||||||
{
|
{
|
||||||
char *submod_gitdir_path;
|
|
||||||
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
|
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
|
||||||
struct string_list reference = STRING_LIST_INIT_NODUP;
|
struct string_list reference = STRING_LIST_INIT_NODUP;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
/* perhaps the path already exists and is already a git repo, else clone it */
|
/* perhaps the path already exists and is already a git repo, else clone it */
|
||||||
if (is_directory(add_data->sm_path)) {
|
if (is_directory(add_data->sm_path)) {
|
||||||
|
char *submod_gitdir_path;
|
||||||
struct strbuf sm_path = STRBUF_INIT;
|
struct strbuf sm_path = STRBUF_INIT;
|
||||||
strbuf_addstr(&sm_path, add_data->sm_path);
|
strbuf_addstr(&sm_path, add_data->sm_path);
|
||||||
submod_gitdir_path = xstrfmt("%s/.git", add_data->sm_path);
|
submod_gitdir_path = xstrfmt("%s/.git", add_data->sm_path);
|
||||||
|
|
@ -3213,10 +3213,11 @@ static int add_submodule(const struct add_data *add_data)
|
||||||
free(submod_gitdir_path);
|
free(submod_gitdir_path);
|
||||||
} else {
|
} else {
|
||||||
struct child_process cp = CHILD_PROCESS_INIT;
|
struct child_process cp = CHILD_PROCESS_INIT;
|
||||||
|
struct strbuf submod_gitdir = STRBUF_INIT;
|
||||||
|
|
||||||
submod_gitdir_path = xstrfmt(".git/modules/%s", add_data->sm_name);
|
submodule_name_to_gitdir(&submod_gitdir, the_repository, add_data->sm_name);
|
||||||
|
|
||||||
if (is_directory(submod_gitdir_path)) {
|
if (is_directory(submod_gitdir.buf)) {
|
||||||
if (!add_data->force) {
|
if (!add_data->force) {
|
||||||
struct strbuf msg = STRBUF_INIT;
|
struct strbuf msg = STRBUF_INIT;
|
||||||
char *die_msg;
|
char *die_msg;
|
||||||
|
|
@ -3225,8 +3226,8 @@ static int add_submodule(const struct add_data *add_data)
|
||||||
"locally with remote(s):\n"),
|
"locally with remote(s):\n"),
|
||||||
add_data->sm_name);
|
add_data->sm_name);
|
||||||
|
|
||||||
append_fetch_remotes(&msg, submod_gitdir_path);
|
append_fetch_remotes(&msg, submod_gitdir.buf);
|
||||||
free(submod_gitdir_path);
|
strbuf_release(&submod_gitdir);
|
||||||
|
|
||||||
strbuf_addf(&msg, _("If you want to reuse this local git "
|
strbuf_addf(&msg, _("If you want to reuse this local git "
|
||||||
"directory instead of cloning again from\n"
|
"directory instead of cloning again from\n"
|
||||||
|
|
@ -3244,7 +3245,7 @@ static int add_submodule(const struct add_data *add_data)
|
||||||
"submodule '%s'\n"), add_data->sm_name);
|
"submodule '%s'\n"), add_data->sm_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(submod_gitdir_path);
|
strbuf_release(&submod_gitdir);
|
||||||
|
|
||||||
clone_data.prefix = add_data->prefix;
|
clone_data.prefix = add_data->prefix;
|
||||||
clone_data.path = add_data->sm_path;
|
clone_data.path = add_data->sm_path;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue