Skip to content

Commit 6327085

Browse files
heftiggitster
authored andcommitted
submodule--helper: use submodule_from_path in set-{url,branch}
The commands need a path to a submodule but treated it as the name when modifying the .gitmodules file, leading to confusion when a submodule's name does not match its path. Because calling submodule_from_path initializes the submodule cache, we need to manually trigger a reread before syncing, as the cache is missing the config change we just made. Signed-off-by: Jan Alexander Steffens (heftig) <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0e8084 commit 6327085

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

builtin/submodule--helper.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,19 +2901,26 @@ static int module_set_url(int argc, const char **argv, const char *prefix)
29012901
N_("git submodule set-url [--quiet] <path> <newurl>"),
29022902
NULL
29032903
};
2904+
const struct submodule *sub;
29042905

29052906
argc = parse_options(argc, argv, prefix, options, usage, 0);
29062907

29072908
if (argc != 2 || !(path = argv[0]) || !(newurl = argv[1]))
29082909
usage_with_options(usage, options);
29092910

2910-
config_name = xstrfmt("submodule.%s.url", path);
2911+
sub = submodule_from_path(the_repository, null_oid(), path);
29112912

2913+
if (!sub)
2914+
die(_("no submodule mapping found in .gitmodules for path '%s'"),
2915+
path);
2916+
2917+
config_name = xstrfmt("submodule.%s.url", sub->name);
29122918
config_set_in_gitmodules_file_gently(config_name, newurl);
2913-
sync_submodule(path, prefix, NULL, quiet ? OPT_QUIET : 0);
29142919

2915-
free(config_name);
2920+
repo_read_gitmodules (the_repository, 0);
2921+
sync_submodule(sub->path, prefix, NULL, quiet ? OPT_QUIET : 0);
29162922

2923+
free(config_name);
29172924
return 0;
29182925
}
29192926

@@ -2941,6 +2948,7 @@ static int module_set_branch(int argc, const char **argv, const char *prefix)
29412948
N_("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>"),
29422949
NULL
29432950
};
2951+
const struct submodule *sub;
29442952

29452953
argc = parse_options(argc, argv, prefix, options, usage, 0);
29462954

@@ -2953,7 +2961,13 @@ static int module_set_branch(int argc, const char **argv, const char *prefix)
29532961
if (argc != 1 || !(path = argv[0]))
29542962
usage_with_options(usage, options);
29552963

2956-
config_name = xstrfmt("submodule.%s.branch", path);
2964+
sub = submodule_from_path(the_repository, null_oid(), path);
2965+
2966+
if (!sub)
2967+
die(_("no submodule mapping found in .gitmodules for path '%s'"),
2968+
path);
2969+
2970+
config_name = xstrfmt("submodule.%s.branch", sub->name);
29572971
ret = config_set_in_gitmodules_file_gently(config_name, opt_branch);
29582972

29592973
free(config_name);

0 commit comments

Comments
 (0)