From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Paolo Bonzini <bonzini@gnu.org>
Subject: [PATCH] branch.autosetupmerge: allow boolean values, or "all"
Date: Sun, 8 Jul 2007 13:41:21 +0100 (BST) [thread overview]
Message-ID: <Pine.LNX.4.64.0707081336020.4248@racer.site> (raw)
In-Reply-To: <7vhcof2rur.fsf@assigned-by-dhcp.cox.net>
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>
---
On Sun, 8 Jul 2007, Junio C Hamano wrote:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
> > "git branch --track" will setup config variables when
> > branching from a remote branch, so that if you say "git pull"
> > while being on that branch, it automatically fetches the
> > correct remote, and merges the correct branch.
>
> While I think it would have been the right thing to do if the
> code did this only for a remote branch, I think there is a bug
> somewhere. I just saw this:
>
> ... some random changes ...
> master$ git commit -a -s -m 'Some work meant for topic.'
> master$ git branch jc/new-topic
> Branch jc/new-topic set up to track local branch refs/heads/master
>
> Eh? I did not want this to get applied for my local branches.
That is certainly unexpected and unwelcomed. Alas, I think it is
one of the consequences of rarely executed (and thus, tested)
code.
I rarely branch, but use one long running branch to commit and
revert, so that a "git log -S<keyword> -p" brings me back my huge
debug output changes, and therefore I did not catch it.
> I do not necessarily think the command line --track is broken.
Me, neither. Therefore, this patch does not change the semantics
of that one. But it was really unexpected for me to see that this
works with anything but remote branches.
> I am very tempted to revert this, but won't do so tonight, yet.
Well, I marked it as RFC, and was surprised to wake up to it being
applied. But thanks for not reverting right away; I think this
patch should fix the issue.
builtin-branch.c | 18 ++++++++++++------
t/t3200-branch.sh | 9 +++++++++
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/builtin-branch.c b/builtin-branch.c
index 507b47c..49195a1 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -22,7 +22,7 @@ static const char builtin_branch_usage[] =
static const char *head;
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 char branch_colors[][COLOR_MAXLEN] = {
@@ -66,8 +66,12 @@ static int git_branch_config(const char *var, const char *value)
color_parse(value, var, branch_colors[slot]);
return 0;
}
- if (!strcmp(var, "branch.autosetupmerge"))
- branch_track_remotes = git_config_bool(var, value);
+ if (!strcmp(var, "branch.autosetupmerge")) {
+ if (!strcmp(value, "all"))
+ branch_track = 2;
+ else
+ branch_track = git_config_bool(var, value);
+ }
return git_default_config(var, value);
}
@@ -525,7 +529,9 @@ static void create_branch(const char *name, const char *start_name,
/* When branching off a remote branch, set up so that git-pull
automatically merges from there. So far, this is only done for
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);
if (write_ref_sha1(lock, sha1, msg) < 0)
@@ -586,7 +592,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
int i;
git_config(git_branch_config);
- track = branch_track_remotes;
+ track = branch_track;
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
@@ -598,7 +604,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
break;
}
if (!strcmp(arg, "--track")) {
- track = 1;
+ track = 2;
continue;
}
if (!strcmp(arg, "--no-track")) {
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index c6f472a..a19e961 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -148,6 +148,15 @@ test_expect_success 'test tracking setup via config' \
test $(git config branch.my3.remote) = local &&
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' \
'git config branch.autosetupmerge true &&
git config remote.local.url . &&
--
1.5.3.rc0.2742.g2050
next prev parent reply other threads:[~2007-07-08 12:48 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-06 21:54 [RFC/PATCH] git-branch: default to --track Johannes Schindelin
2007-07-08 8:59 ` Junio C Hamano
2007-07-08 12:41 ` Johannes Schindelin [this message]
2007-07-08 18:41 ` [PATCH] branch.autosetupmerge: allow boolean values, or "all" Junio C Hamano
2007-07-08 19:15 ` Johannes Schindelin
2007-07-09 1:59 ` Paolo Bonzini
2007-07-09 2:27 ` Junio C Hamano
2007-07-09 11:35 ` [PATCH] branch --track: code cleanup and saner handling of local branches Johannes Schindelin
2007-07-09 21:05 ` Junio C Hamano
2007-07-09 21:05 ` Johannes Schindelin
2007-07-09 22:01 ` Junio C Hamano
2007-07-10 3:02 ` [PATCH 1/2] Add for_each_remote() function, and extend remote_find_tracking() Johannes Schindelin
2007-07-10 3:55 ` Daniel Barkalow
2007-07-10 14:11 ` Johannes Schindelin
2007-07-10 5:07 ` Junio C Hamano
2007-07-10 5:23 ` Daniel Barkalow
2007-07-10 17:48 ` [PATCH v2 " Johannes Schindelin
2007-07-10 18:38 ` Junio C Hamano
2007-07-10 19:28 ` Johannes Schindelin
2007-07-10 21:09 ` Daniel Barkalow
2007-07-10 17:50 ` [PATCH v2 2/2] branch --track: code cleanup and saner handling of local branches Johannes Schindelin
2007-07-10 3:05 ` [PATCH " Johannes Schindelin
2007-07-09 11:28 ` [PATCH] branch.autosetupmerge: allow boolean values, or "all" Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0707081336020.4248@racer.site \
--to=johannes.schindelin@gmx.de \
--cc=bonzini@gnu.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).