aboutsummaryrefslogtreecommitdiffstats
path: root/refs.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-07-06 22:09:17 -0700
committerJunio C Hamano <gitster@pobox.com>2020-07-06 22:09:17 -0700
commit11cbda2add5d3eb7c415f1f6dd8186181a7f9874 (patch)
tree7d722860aa28b92087406bf063c7ad6fe6c45c30 /refs.c
parent480e78595ea531482018826d35fed0fb0529afa2 (diff)
parent508fd8e8baf3e18ee40b2cf0b8899188a8506d07 (diff)
downloadgit-11cbda2add5d3eb7c415f1f6dd8186181a7f9874.tar.gz
Merge branch 'js/default-branch-name'
The name of the primary branch in existing repositories, and the default name used for the first branch in newly created repositories, is made configurable, so that we can eventually wean ourselves off of the hardcoded 'master'. * js/default-branch-name: contrib: subtree: adjust test to change in fmt-merge-msg testsvn: respect `init.defaultBranch` remote: use the configured default branch name when appropriate clone: use configured default branch name when appropriate init: allow setting the default for the initial branch name via the config init: allow specifying the initial branch name for the new repository docs: add missing diamond brackets submodule: fall back to remote's HEAD for missing remote.<name>.branch send-pack/transport-helper: avoid mentioning a particular branch fmt-merge-msg: stop treating `master` specially
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/refs.c b/refs.c
index 11abdc7f18..639cba93b4 100644
--- a/refs.c
+++ b/refs.c
@@ -562,6 +562,36 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)
argv_array_pushf(prefixes, *p, len, prefix);
}
+char *repo_default_branch_name(struct repository *r)
+{
+ const char *config_key = "init.defaultbranch";
+ const char *config_display_key = "init.defaultBranch";
+ char *ret = NULL, *full_ref;
+
+ if (repo_config_get_string(r, config_key, &ret) < 0)
+ die(_("could not retrieve `%s`"), config_display_key);
+
+ if (!ret)
+ ret = xstrdup("master");
+
+ full_ref = xstrfmt("refs/heads/%s", ret);
+ if (check_refname_format(full_ref, 0))
+ die(_("invalid branch name: %s = %s"), config_display_key, ret);
+ free(full_ref);
+
+ return ret;
+}
+
+const char *git_default_branch_name(void)
+{
+ static char *ret;
+
+ if (!ret)
+ ret = repo_default_branch_name(the_repository);
+
+ return ret;
+}
+
/*
* *string and *len will only be substituted, and *string returned (for
* later free()ing) if the string passed in is a magic short-hand form