提交 4017761f 编写于 作者: J Johannes Schindelin 提交者: Junio C Hamano

branch.autosetupmerge: allow boolean values, or "all"

Junio noticed that switching on autosetupmerge unilaterally started
cluttering the config for local branches.  That is not the original
intention of branch.autosetupmerge, which was meant purely for
convenience when branching off of remote branches, but that semantics
got lost somewhere.

If you still want that "new" behavior, you can switch
branch.autosetupmerge to the value "all".  Otherwise, it is interpreted
as a boolean, which triggers setting up defaults _only_ when branching
off of a remote branch, i.e. the originally intended behavior.
Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 b24f56d6
...@@ -309,7 +309,10 @@ branch.autosetupmerge:: ...@@ -309,7 +309,10 @@ branch.autosetupmerge::
so that gitlink:git-pull[1] will appropriately merge from that so that gitlink:git-pull[1] will appropriately merge from that
remote branch. Note that even if this option is not set, remote branch. Note that even if this option is not set,
this behavior can be chosen per-branch using the `--track` this behavior can be chosen per-branch using the `--track`
and `--no-track` options. This option defaults to false. and `--no-track` options. This option can have values
'false' (never touch the configuration), 'all' (do this
for all branches), or 'true' (do this only when
branching from a remote tracking branch), and defaults to 'true'.
branch.<name>.remote:: branch.<name>.remote::
When in branch <name>, it tells `git fetch` which remote to fetch. When in branch <name>, it tells `git fetch` which remote to fetch.
......
...@@ -52,8 +52,9 @@ OPTIONS ...@@ -52,8 +52,9 @@ OPTIONS
set up configuration so that git-pull will automatically set up configuration so that git-pull will automatically
retrieve data from the remote branch. Set the retrieve data from the remote branch. Set the
branch.autosetupmerge configuration variable to true if you branch.autosetupmerge configuration variable to true if you
want git-checkout and git-branch to always behave as if want git-checkout and git-branch to behave as if
'--track' were given. '--track' were given when you branch from a remote
tracking branch.
--no-track:: --no-track::
When -b is given and a branch is created off a remote branch, When -b is given and a branch is created off a remote branch,
......
...@@ -22,7 +22,7 @@ static const char builtin_branch_usage[] = ...@@ -22,7 +22,7 @@ static const char builtin_branch_usage[] =
static const char *head; static const char *head;
static unsigned char head_sha1[20]; static unsigned char head_sha1[20];
static int branch_track_remotes = 1; static int branch_track = 1; /* 0 = none, 1 = remotes, 2 = all */
static int branch_use_color; static int branch_use_color;
static char branch_colors[][COLOR_MAXLEN] = { static char branch_colors[][COLOR_MAXLEN] = {
...@@ -66,8 +66,12 @@ static int git_branch_config(const char *var, const char *value) ...@@ -66,8 +66,12 @@ static int git_branch_config(const char *var, const char *value)
color_parse(value, var, branch_colors[slot]); color_parse(value, var, branch_colors[slot]);
return 0; return 0;
} }
if (!strcmp(var, "branch.autosetupmerge")) if (!strcmp(var, "branch.autosetupmerge")) {
branch_track_remotes = git_config_bool(var, value); if (!strcmp(value, "all"))
branch_track = 2;
else
branch_track = git_config_bool(var, value);
}
return git_default_config(var, value); return git_default_config(var, value);
} }
...@@ -504,7 +508,9 @@ static void create_branch(const char *name, const char *start_name, ...@@ -504,7 +508,9 @@ static void create_branch(const char *name, const char *start_name,
/* When branching off a remote branch, set up so that git-pull /* When branching off a remote branch, set up so that git-pull
automatically merges from there. So far, this is only done for automatically merges from there. So far, this is only done for
remotes registered via .git/config. */ remotes registered via .git/config. */
if (real_ref && track) if (real_ref && (track == 2 ||
(track == 1 &&
!prefixcmp(real_ref, "refs/remotes/"))))
set_branch_defaults(name, real_ref); set_branch_defaults(name, real_ref);
if (write_ref_sha1(lock, sha1, msg) < 0) if (write_ref_sha1(lock, sha1, msg) < 0)
...@@ -564,7 +570,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) ...@@ -564,7 +570,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
int i; int i;
git_config(git_branch_config); git_config(git_branch_config);
track = branch_track_remotes; track = branch_track;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
const char *arg = argv[i]; const char *arg = argv[i];
...@@ -576,7 +582,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) ...@@ -576,7 +582,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
break; break;
} }
if (!strcmp(arg, "--track")) { if (!strcmp(arg, "--track")) {
track = 1; track = 2;
continue; continue;
} }
if (!strcmp(arg, "--no-track")) { if (!strcmp(arg, "--no-track")) {
......
...@@ -148,6 +148,15 @@ test_expect_success 'test tracking setup via config' \ ...@@ -148,6 +148,15 @@ test_expect_success 'test tracking setup via config' \
test $(git config branch.my3.remote) = local && test $(git config branch.my3.remote) = local &&
test $(git config branch.my3.merge) = refs/heads/master' test $(git config branch.my3.merge) = refs/heads/master'
test_expect_success 'autosetupmerge = all' '
git config branch.autosetupmerge true &&
git branch all1 master &&
test -z "$(git config branch.all1.merge)" &&
git config branch.autosetupmerge all &&
git branch all2 master &&
test $(git config branch.all2.merge) = refs/heads/master
'
test_expect_success 'test overriding tracking setup via --no-track' \ test_expect_success 'test overriding tracking setup via --no-track' \
'git config branch.autosetupmerge true && 'git config branch.autosetupmerge true &&
git config remote.local.url . && git config remote.local.url . &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册