Skip to content

Commit 9e8ed17

Browse files
committed
Merge branch 'ss/submodule-set-url-in-c'
Rewriting various parts of "git submodule" in C continues. * ss/submodule-set-url-in-c: submodule: port subcommand 'set-url' from shell to C
2 parents 2e72299 + 6417cf9 commit 9e8ed17

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

builtin/submodule--helper.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,37 @@ static int module_config(int argc, const char **argv, const char *prefix)
22462246
usage_with_options(git_submodule_helper_usage, module_config_options);
22472247
}
22482248

2249+
static int module_set_url(int argc, const char **argv, const char *prefix)
2250+
{
2251+
int quiet = 0;
2252+
const char *newurl;
2253+
const char *path;
2254+
char *config_name;
2255+
2256+
struct option options[] = {
2257+
OPT__QUIET(&quiet, N_("Suppress output for setting url of a submodule")),
2258+
OPT_END()
2259+
};
2260+
const char *const usage[] = {
2261+
N_("git submodule--helper set-url [--quiet] <path> <newurl>"),
2262+
NULL
2263+
};
2264+
2265+
argc = parse_options(argc, argv, prefix, options, usage, 0);
2266+
2267+
if (argc != 2 || !(path = argv[0]) || !(newurl = argv[1]))
2268+
usage_with_options(usage, options);
2269+
2270+
config_name = xstrfmt("submodule.%s.url", path);
2271+
2272+
config_set_in_gitmodules_file_gently(config_name, newurl);
2273+
sync_submodule(path, prefix, quiet ? OPT_QUIET : 0);
2274+
2275+
free(config_name);
2276+
2277+
return 0;
2278+
}
2279+
22492280
#define SUPPORT_SUPER_PREFIX (1<<0)
22502281

22512282
struct cmd_struct {
@@ -2276,6 +2307,7 @@ static struct cmd_struct commands[] = {
22762307
{"is-active", is_active, 0},
22772308
{"check-name", check_name, 0},
22782309
{"config", module_config, 0},
2310+
{"set-url", module_set_url, 0},
22792311
};
22802312

22812313
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)

git-submodule.sh

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -805,27 +805,7 @@ cmd_set_url() {
805805
shift
806806
done
807807

808-
if test $# -ne 2
809-
then
810-
usage
811-
fi
812-
813-
# we can't use `git submodule--helper name` here because internally, it
814-
# hashes the path so a trailing slash could lead to an unintentional no match
815-
name="$(git submodule--helper list "$1" | cut -f2)"
816-
if test -z "$name"
817-
then
818-
exit 1
819-
fi
820-
821-
url="$2"
822-
if test -z "$url"
823-
then
824-
exit 1
825-
fi
826-
827-
git submodule--helper config submodule."$name".url "$url"
828-
git submodule--helper sync ${GIT_QUIET:+--quiet} "$name"
808+
git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@"
829809
}
830810

831811
#

0 commit comments

Comments
 (0)