path: root/builtin-checkout.c
diff options
authorJay Soffian <>2008-02-19 16:24:37 (GMT)
committerJunio C Hamano <>2008-02-20 05:17:45 (GMT)
commit9ed36cfa35cfbd09c454f12194a91cd50ba284d1 (patch)
treedb9d61a4a4e47cf8fe6f442f1c46f1d6cce09ae4 /builtin-checkout.c
parent569012bf91ddb25220483e8912e079ce8a501525 (diff)
branch: optionally setup branch.*.merge from upstream local branches
"git branch" and "git checkout -b" now honor --track option even when the upstream branch is local. Previously --track was silently ignored when forking from a local branch. Also the command did not error out when --track was explicitly asked for but the forked point specified was not an existing branch (i.e. when there is no way to set up the tracking configuration), but now it correctly does. The configuration setting branch.autosetupmerge can now be set to "always", which is equivalent to using --track from the command line. Setting branch.autosetupmerge to "true" will retain the former behavior of only setting up branch.*.merge for remote upstream branches. Includes test cases for the new functionality. Signed-off-by: Jay Soffian <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin-checkout.c')
1 files changed, 5 insertions, 9 deletions
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 5291f72..b1820a4 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -186,7 +186,7 @@ struct checkout_opts {
char *new_branch;
int new_branch_log;
- int track;
+ enum branch_track track;
struct branch_info {
@@ -457,13 +457,8 @@ static int switch_branches(struct checkout_opts *opts,
return post_checkout_hook(old.commit, new->commit, 1);
-static int branch_track = 0;
static int git_checkout_config(const char *var, const char *value)
- if (!strcmp(var, "branch.autosetupmerge"))
- branch_track = git_config_bool(var, value);
return git_default_config(var, value);
@@ -478,7 +473,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
OPT_STRING('b', NULL, &opts.new_branch, "new branch", "branch"),
OPT_BOOLEAN('l', NULL, &opts.new_branch_log, "log for new branch"),
- OPT_BOOLEAN( 0 , "track", &opts.track, "track"),
+ OPT_SET_INT( 0 , "track", &opts.track, "track",
OPT_BOOLEAN('f', NULL, &opts.force, "force"),
OPT_BOOLEAN('m', NULL, &opts.merge, "merge"),
@@ -489,7 +485,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
- opts.track = branch_track;
+ opts.track = git_branch_track;
argc = parse_options(argc, argv, options, checkout_usage, 0);
if (argc) {
@@ -518,7 +514,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
- if (!opts.new_branch && (opts.track != branch_track))
+ if (!opts.new_branch && (opts.track != git_branch_track))
die("git checkout: --track and --no-track require -b");
if (opts.force && opts.merge)