@matheusbsbs / matheus-bagliano / commits / 4017761fd8
Fork 0

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: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 8, 2007 at 13:41 UTC 4017761fd89060f2b57d7799f6bbda8b3568d3d4
4 files changed +28 -9
Documentation/config.txt
+4 -1
@@ -309,7 +309,10 @@ branch.autosetupmerge::
309 so that gitlink:git-pull[1] will appropriately merge from that
310 remote branch. Note that even if this option is not set,
311 this behavior can be chosen per-branch using the `--track`
312 - and `--no-track` options. This option defaults to false.
312 + and `--no-track` options. This option can have values
313 + 'false' (never touch the configuration), 'all' (do this
314 + for all branches), or 'true' (do this only when
315 + branching from a remote tracking branch), and defaults to 'true'.
316
317 branch.<name>.remote::
318 When in branch <name>, it tells `git fetch` which remote to fetch.
Documentation/git-checkout.txt
+3 -2
@@ -52,8 +52,9 @@ OPTIONS
52 set up configuration so that git-pull will automatically
53 retrieve data from the remote branch. Set the
54 branch.autosetupmerge configuration variable to true if you
55 - want git-checkout and git-branch to always behave as if
56 - '--track' were given.
55 + want git-checkout and git-branch to behave as if
56 + '--track' were given when you branch from a remote
57 + tracking branch.
58
59 --no-track::
60 When -b is given and a branch is created off a remote branch,
builtin-branch.c
+12 -6
@@ -22,7 +22,7 @@ static const char builtin_branch_usage[] =
22 static const char *head;
23 static unsigned char head_sha1[20];
24
25 -static int branch_track_remotes = 1;
25 +static int branch_track = 1; /* 0 = none, 1 = remotes, 2 = all */
26
27 static int branch_use_color;
28 static char branch_colors[][COLOR_MAXLEN] = {
@@ -66,8 +66,12 @@ static int git_branch_config(const char *var, const char *value)
66 color_parse(value, var, branch_colors[slot]);
67 return 0;
68 }
69 - if (!strcmp(var, "branch.autosetupmerge"))
70 - branch_track_remotes = git_config_bool(var, value);
69 + if (!strcmp(var, "branch.autosetupmerge")) {
70 + if (!strcmp(value, "all"))
71 + branch_track = 2;
72 + else
73 + branch_track = git_config_bool(var, value);
74 + }
75
76 return git_default_config(var, value);
77 }
@@ -504,7 +508,9 @@ static void create_branch(const char *name, const char *start_name,
508 /* When branching off a remote branch, set up so that git-pull
509 automatically merges from there. So far, this is only done for
510 remotes registered via .git/config. */
507 - if (real_ref && track)
511 + if (real_ref && (track == 2 ||
512 + (track == 1 &&
513 + !prefixcmp(real_ref, "refs/remotes/"))))
514 set_branch_defaults(name, real_ref);
515
516 if (write_ref_sha1(lock, sha1, msg) < 0)
@@ -564,7 +570,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
570 int i;
571
572 git_config(git_branch_config);
567 - track = branch_track_remotes;
573 + track = branch_track;
574
575 for (i = 1; i < argc; i++) {
576 const char *arg = argv[i];
@@ -576,7 +582,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
582 break;
583 }
584 if (!strcmp(arg, "--track")) {
579 - track = 1;
585 + track = 2;
586 continue;
587 }
588 if (!strcmp(arg, "--no-track")) {
t/t3200-branch.sh
+9
@@ -148,6 +148,15 @@ test_expect_success 'test tracking setup via config' \
148 test $(git config branch.my3.remote) = local &&
149 test $(git config branch.my3.merge) = refs/heads/master'
150
151 +test_expect_success 'autosetupmerge = all' '
152 + git config branch.autosetupmerge true &&
153 + git branch all1 master &&
154 + test -z "$(git config branch.all1.merge)" &&
155 + git config branch.autosetupmerge all &&
156 + git branch all2 master &&
157 + test $(git config branch.all2.merge) = refs/heads/master
158 +'
159 +
160 test_expect_success 'test overriding tracking setup via --no-track' \
161 'git config branch.autosetupmerge true &&
162 git config remote.local.url . &&