-
Notifications
You must be signed in to change notification settings - Fork 143
Allow overriding the default name of the default branch #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fffdb99
1216de5
5456364
1d723d3
9edd4fd
7747eaa
1cff770
0a7c0bd
6c72abf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
init.templateDir:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
|
||
Specify the directory from which templates will be copied. | ||
(See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].) | ||
|
||
init.defaultBranch:: | ||
Allows overriding the default branch name e.g. when initializing | ||
a new repository or when cloning an empty repository. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ SYNOPSIS | |
-------- | ||
[verse] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
|
||
'git init' [-q | --quiet] [--bare] [--template=<template_directory>] | ||
[--separate-git-dir <git dir>] [--object-format=<format] | ||
[--separate-git-dir <git dir>] [--object-format=<format>] | ||
[-b <branch-name> | --initial-branch=<branch-name>] | ||
[--shared[=<permissions>]] [directory] | ||
|
||
|
||
|
@@ -67,6 +68,12 @@ repository. | |
+ | ||
If this is reinitialization, the repository will be moved to the specified path. | ||
|
||
-b <branch-name:: | ||
--initial-branch=<branch-name>:: | ||
|
||
Use the specified name for the initial branch in the newly created repository. | ||
If not specified, fall back to the default name: `master`. | ||
|
||
--shared[=(false|true|umask|group|all|world|everybody|0xxx)]:: | ||
|
||
Specify that the Git repository is to be shared amongst several users. This | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,7 +183,7 @@ set-branch (-d|--default) [--] <path>:: | |
Sets the default remote tracking branch for the submodule. The | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
|
||
`--branch` option allows the remote branch to be specified. The | ||
`--default` option removes the submodule.<name>.branch configuration | ||
key, which causes the tracking branch to default to 'master'. | ||
key, which causes the tracking branch to default to the remote 'HEAD'. | ||
|
||
set-url [--] <path> <newurl>:: | ||
Sets the URL of the specified submodule to <newurl>. Then, it will | ||
|
@@ -284,7 +284,7 @@ OPTIONS | |
`.gitmodules` for `update --remote`. A special value of `.` is used to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Philippe Blain wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
|
||
indicate that the name of the branch in the submodule should be the | ||
same name as the current branch in the current repository. If the | ||
option is not specified, it defaults to 'master'. | ||
option is not specified, it defaults to the remote 'HEAD'. | ||
|
||
-f:: | ||
--force:: | ||
|
@@ -322,10 +322,10 @@ OPTIONS | |
the superproject's recorded SHA-1 to update the submodule, use the | ||
status of the submodule's remote-tracking branch. The remote used | ||
is branch's remote (`branch.<name>.remote`), defaulting to `origin`. | ||
The remote branch used defaults to `master`, but the branch name may | ||
be overridden by setting the `submodule.<name>.branch` option in | ||
either `.gitmodules` or `.git/config` (with `.git/config` taking | ||
precedence). | ||
The remote branch used defaults to the remote `HEAD`, but the branch | ||
name may be overridden by setting the `submodule.<name>.branch` | ||
option in either `.gitmodules` or `.git/config` (with `.git/config` | ||
taking precedence). | ||
+ | ||
This works for any of the supported update procedures (`--checkout`, | ||
`--rebase`, etc.). The only change is the source of the target SHA-1. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1111,7 +1111,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix) | |
} | ||
} | ||
|
||
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, INIT_DB_QUIET); | ||
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL, | ||
INIT_DB_QUIET); | ||
|
||
if (real_git_dir) | ||
git_dir = real_git_dir; | ||
|
@@ -1266,9 +1267,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix) | |
remote_head_points_at = NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
|
||
remote_head = NULL; | ||
option_no_checkout = 1; | ||
if (!option_bare) | ||
install_branch_config(0, "master", option_origin, | ||
"refs/heads/master"); | ||
if (!option_bare) { | ||
const char *branch = git_default_branch_name(); | ||
char *ref = xstrfmt("refs/heads/%s", branch); | ||
|
||
install_branch_config(0, branch, option_origin, ref); | ||
free(ref); | ||
} | ||
} | ||
|
||
write_refspec_config(src_ref_prefix, our_head_points_at, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,6 +203,7 @@ void initialize_repository_version(int hash_algo) | |
|
||
static int create_default_files(const char *template_path, | ||
const char *original_git_dir, | ||
const char *initial_branch, | ||
const struct repository_format *fmt) | ||
{ | ||
struct stat st1; | ||
|
@@ -258,15 +259,26 @@ static int create_default_files(const char *template_path, | |
die("failed to set up refs db: %s", err.buf); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, "brian m. carlson" wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Eric Sunshine wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Jeff King wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Jeff King wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Phillip Wood wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Phillip Wood wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Alban Gruin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, "brian m. carlson" wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Alban Gruin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Jeff King wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
|
||
|
||
/* | ||
* Create the default symlink from ".git/HEAD" to the "master" | ||
* branch, if it does not exist yet. | ||
* Point the HEAD symref to the initial branch with if HEAD does | ||
* not yet exist. | ||
*/ | ||
path = git_path_buf(&buf, "HEAD"); | ||
reinit = (!access(path, R_OK) | ||
|| readlink(path, junk, sizeof(junk)-1) != -1); | ||
if (!reinit) { | ||
if (create_symref("HEAD", "refs/heads/master", NULL) < 0) | ||
char *ref; | ||
|
||
if (!initial_branch) | ||
initial_branch = git_default_branch_name(); | ||
|
||
ref = xstrfmt("refs/heads/%s", initial_branch); | ||
if (check_refname_format(ref, 0) < 0) | ||
die(_("invalid initial branch name: '%s'"), | ||
initial_branch); | ||
|
||
if (create_symref("HEAD", ref, NULL) < 0) | ||
exit(1); | ||
free(ref); | ||
} | ||
|
||
initialize_repository_version(fmt->hash_algo); | ||
|
@@ -383,7 +395,8 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash | |
} | ||
|
||
int init_db(const char *git_dir, const char *real_git_dir, | ||
const char *template_dir, int hash, unsigned int flags) | ||
const char *template_dir, int hash, const char *initial_branch, | ||
unsigned int flags) | ||
{ | ||
int reinit; | ||
int exist_ok = flags & INIT_DB_EXIST_OK; | ||
|
@@ -425,7 +438,11 @@ int init_db(const char *git_dir, const char *real_git_dir, | |
|
||
validate_hash_algorithm(&repo_fmt, hash); | ||
|
||
reinit = create_default_files(template_dir, original_git_dir, &repo_fmt); | ||
reinit = create_default_files(template_dir, original_git_dir, | ||
initial_branch, &repo_fmt); | ||
if (reinit && initial_branch) | ||
warning(_("re-init: ignored --initial-branch=%s"), | ||
initial_branch); | ||
|
||
create_object_directory(); | ||
|
||
|
@@ -528,6 +545,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) | |
const char *template_dir = NULL; | ||
unsigned int flags = 0; | ||
const char *object_format = NULL; | ||
const char *initial_branch = NULL; | ||
int hash_algo = GIT_HASH_UNKNOWN; | ||
const struct option init_db_options[] = { | ||
OPT_STRING(0, "template", &template_dir, N_("template-directory"), | ||
|
@@ -541,6 +559,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) | |
OPT_BIT('q', "quiet", &flags, N_("be quiet"), INIT_DB_QUIET), | ||
OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"), | ||
N_("separate git dir from working tree")), | ||
OPT_STRING('b', "initial-branch", &initial_branch, N_("name"), | ||
N_("override the name of the initial branch")), | ||
OPT_STRING(0, "object-format", &object_format, N_("hash"), | ||
N_("specify the hash algorithm to use")), | ||
OPT_END() | ||
|
@@ -652,5 +672,6 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) | |
UNLEAK(work_tree); | ||
|
||
flags |= INIT_DB_EXIST_OK; | ||
return init_db(git_dir, real_git_dir, template_dir, hash_algo, flags); | ||
return init_db(git_dir, real_git_dir, template_dir, hash_algo, | ||
initial_branch, flags); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -451,10 +451,7 @@ static void fmt_merge_msg_title(struct strbuf *out, | |
strbuf_addf(out, " of %s", srcs.items[i].string); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Đoàn Trần Công Danh wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Đoàn Trần Công Danh wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
|
||
} | ||
|
||
if (!strcmp("master", current_branch)) | ||
strbuf_addch(out, '\n'); | ||
else | ||
strbuf_addf(out, " into %s\n", current_branch); | ||
strbuf_addf(out, " into %s\n", current_branch); | ||
} | ||
|
||
static void fmt_tag_signature(struct strbuf *tagbuf, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
static const char *url; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Jeff King wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
|
||
static int dump_from_file; | ||
static const char *private_ref; | ||
static const char *remote_ref = "refs/heads/master"; | ||
static char *remote_ref; | ||
static const char *marksfilename, *notes_ref; | ||
struct rev_note { unsigned int rev_nr; }; | ||
|
||
|
@@ -286,14 +286,17 @@ int cmd_main(int argc, const char **argv) | |
private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT, | ||
notes_ref_sb = STRBUF_INIT; | ||
static struct remote *remote; | ||
const char *url_in; | ||
const char *url_in, *remote_ref_short; | ||
|
||
setup_git_directory(); | ||
if (argc < 2 || argc > 3) { | ||
usage("git-remote-svn <remote-name> [<url>]"); | ||
return 1; | ||
} | ||
|
||
remote_ref_short = git_default_branch_name(); | ||
remote_ref = xstrfmt("refs/heads/%s", remote_ref_short); | ||
|
||
remote = remote_get(argv[1]); | ||
url_in = (argc == 3) ? argv[2] : remote->url[0]; | ||
|
||
|
@@ -306,7 +309,8 @@ int cmd_main(int argc, const char **argv) | |
url = url_sb.buf; | ||
} | ||
|
||
strbuf_addf(&private_ref_sb, "refs/svn/%s/master", remote->name); | ||
strbuf_addf(&private_ref_sb, "refs/svn/%s/%s", | ||
remote->name, remote_ref_short); | ||
private_ref = private_ref_sb.buf; | ||
|
||
strbuf_addf(¬es_ref_sb, "refs/notes/%s/revs", remote->name); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,15 +276,15 @@ static void read_branches_file(struct remote *remote) | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
|
||
/* | ||
* The branches file would have URL and optionally | ||
* #branch specified. The "master" (or specified) branch is | ||
* #branch specified. The default (or specified) branch is | ||
* fetched and stored in the local branch matching the | ||
* remote name. | ||
*/ | ||
frag = strchr(buf.buf, '#'); | ||
if (frag) | ||
*(frag++) = '\0'; | ||
else | ||
frag = "master"; | ||
frag = (char *)git_default_branch_name(); | ||
|
||
add_url_alias(remote, strbuf_detach(&buf, NULL)); | ||
strbuf_addf(&buf, "refs/heads/%s:refs/heads/%s", | ||
|
@@ -2097,8 +2097,16 @@ struct ref *guess_remote_head(const struct ref *head, | |
if (head->symref) | ||
return copy_ref(find_ref_by_name(refs, head->symref)); | ||
|
||
/* If refs/heads/master could be right, it is. */ | ||
/* If a remote branch exists with the default branch name, let's use it. */ | ||
if (!all) { | ||
char *ref = xstrfmt("refs/heads/%s", git_default_branch_name()); | ||
|
||
r = find_ref_by_name(refs, ref); | ||
free(ref); | ||
if (r && oideq(&r->old_oid, &head->old_oid)) | ||
return copy_ref(r); | ||
|
||
/* Fall back to the hard-coded historical default */ | ||
r = find_ref_by_name(refs, "refs/heads/master"); | ||
if (r && oideq(&r->old_oid, &head->old_oid)) | ||
return copy_ref(r); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -406,7 +406,7 @@ int send_pack(struct send_pack_args *args, | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Johannes Schindelin wrote (reply to this):
|
||
if (!remote_refs) { | ||
fprintf(stderr, "No refs in common and none specified; doing nothing.\n" | ||
"Perhaps you should specify a branch such as 'master'.\n"); | ||
"Perhaps you should specify a branch.\n"); | ||
return 0; | ||
} | ||
if (args->atomic && !atomic_supported) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Jeff King wrote (reply to this):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Johannes Schindelin wrote (reply to this):