aboutsummaryrefslogtreecommitdiff
path: root/builtin/submodule--helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/submodule--helper.c')
-rw-r--r--builtin/submodule--helper.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index d537ab087a..b180a24091 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -112,6 +112,43 @@ static int get_default_remote_submodule(const char *module_path, char **default_
return 0;
}
+static int module_get_default_remote(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
+{
+ const char *path;
+ char *resolved_path = NULL;
+ char *default_remote = NULL;
+ int code;
+ struct option options[] = {
+ OPT_END()
+ };
+ const char *const usage[] = {
+ N_("git submodule--helper get-default-remote <path>"),
+ NULL
+ };
+
+ argc = parse_options(argc, argv, prefix, options, usage, 0);
+ if (argc != 1)
+ usage_with_options(usage, options);
+
+ path = argv[0];
+ if (prefix && *prefix && !is_absolute_path(path)) {
+ resolved_path = xstrfmt("%s%s", prefix, path);
+ path = resolved_path;
+ }
+
+ code = get_default_remote_submodule(path, &default_remote);
+ if (code) {
+ free(resolved_path);
+ return code;
+ }
+
+ printf("%s\n", default_remote);
+ free(default_remote);
+ free(resolved_path);
+ return 0;
+}
+
/* the result should be freed by the caller. */
static char *get_submodule_displaypath(const char *path, const char *prefix,
const char *super_prefix)
@@ -3608,6 +3645,7 @@ int cmd_submodule__helper(int argc,
OPT_SUBCOMMAND("set-url", &fn, module_set_url),
OPT_SUBCOMMAND("set-branch", &fn, module_set_branch),
OPT_SUBCOMMAND("create-branch", &fn, module_create_branch),
+ OPT_SUBCOMMAND("get-default-remote", &fn, module_get_default_remote),
OPT_END()
};
argc = parse_options(argc, argv, prefix, options, usage, 0);