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
This commit is contained in:
30
refs.c
30
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
|
||||
|
Reference in New Issue
Block a user