]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/submodule--helper.c
shortlog: change "author" variables to "ident"
[thirdparty/git.git] / builtin / submodule--helper.c
index 46c03d2a12671e15296b34d5e194fa837a12cdfb..a1c75607c72e190a10cc7af0184a41b04f5e77b5 100644 (file)
@@ -1981,7 +1981,7 @@ static const char *remote_submodule_branch(const char *path)
        free(key);
 
        if (!branch)
-               return "master";
+               return "HEAD";
 
        if (!strcmp(branch, ".")) {
                const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
@@ -2277,6 +2277,49 @@ static int module_set_url(int argc, const char **argv, const char *prefix)
        return 0;
 }
 
+static int module_set_branch(int argc, const char **argv, const char *prefix)
+{
+       int opt_default = 0, ret;
+       const char *opt_branch = NULL;
+       const char *path;
+       char *config_name;
+
+       /*
+        * We accept the `quiet` option for uniformity across subcommands,
+        * though there is nothing to make less verbose in this subcommand.
+        */
+       struct option options[] = {
+               OPT_NOOP_NOARG('q', "quiet"),
+               OPT_BOOL('d', "default", &opt_default,
+                       N_("set the default tracking branch to master")),
+               OPT_STRING('b', "branch", &opt_branch, N_("branch"),
+                       N_("set the default tracking branch")),
+               OPT_END()
+       };
+       const char *const usage[] = {
+               N_("git submodule--helper set-branch [-q|--quiet] (-d|--default) <path>"),
+               N_("git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>"),
+               NULL
+       };
+
+       argc = parse_options(argc, argv, prefix, options, usage, 0);
+
+       if (!opt_branch && !opt_default)
+               die(_("--branch or --default required"));
+
+       if (opt_branch && opt_default)
+               die(_("--branch and --default are mutually exclusive"));
+
+       if (argc != 1 || !(path = argv[0]))
+               usage_with_options(usage, options);
+
+       config_name = xstrfmt("submodule.%s.branch", path);
+       ret = config_set_in_gitmodules_file_gently(config_name, opt_branch);
+
+       free(config_name);
+       return !!ret;
+}
+
 #define SUPPORT_SUPER_PREFIX (1<<0)
 
 struct cmd_struct {
@@ -2308,6 +2351,7 @@ static struct cmd_struct commands[] = {
        {"check-name", check_name, 0},
        {"config", module_config, 0},
        {"set-url", module_set_url, 0},
+       {"set-branch", module_set_branch, 0},
 };
 
 int cmd_submodule__helper(int argc, const char **argv, const char *prefix)