git-branch: allow --track to work w/local branches
RFC PATCH 1/2 git-branch: allow --track to work w/local branches
When given --track (or if branch.autosetupmerge is true) and basing off a local branch, set branch.<newbranch>.remote to "." and branch.<newbranch>.merge to the local branch. This allows us to use "git pull" (w/o options) on the new branch.
Previously --track was silently ignored when basing off a local branch.
--- builtin-branch.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
builtin-branch.c +10 -0
@@ -402,6 +402,16 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)return error ("Tracking not set up: name too long: %s" , new_ref); +if (!prefixcmp (orig_ref,"refs/heads/" )) { +sprintf (key,"branch.%s.remote" , new_ref); +git_config_set (key,"." ); +sprintf (key,"branch.%s.merge" , new_ref); +git_config_set (key, orig_ref); +printf ("Branch %s set up to track local branch %s.\n" , + new_ref, orig_ref); +return 0 ; + } +memset (&tracking,0 ,sizeof (tracking)); tracking.spec.dst = (char *)orig_ref; if (for_each_remote(find_tracked_branch, &tracking) ||
Signature · 1 line
1.5.4.1.1281.g75df
RFC PATCH 2/2 new --rebase option to set branch.*.rebase for new branches
Add a --rebase option to git-branch and git-checkout. If given, it implies --track but additionally sets branch.<newbranch>.rebase to true.
--- builtin-branch.c | 18 ++++++++++++++---- git-checkout.sh | 11 ++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-)
builtin-branch.c +14 -4
@@ -393,7 +393,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)* to infer the settings for branch.<new_ref>.{remote,merge} from the * config. */ -static int setup_tracking (const char *new_ref,const char *orig_ref) +static int setup_tracking (const char *new_ref,const char *orig_ref,int rebase) {char key[1024 ];struct tracking tracking;
@@ -407,6 +407,10 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)git_config_set (key,"." );sprintf (key,"branch.%s.merge" , new_ref);git_config_set (key, orig_ref); +if (rebase) { +sprintf (key,"branch.%s.rebase" , new_ref); +git_config_set (key,"true" ); + }printf ("Branch %s set up to track local branch %s.\n" , new_ref, orig_ref);return 0 ;
@@ -428,6 +432,10 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)sprintf (key,"branch.%s.merge" , new_ref);git_config_set (key, tracking.src);free (tracking.src); +if (rebase) { +sprintf (key,"branch.%s.rebase" , new_ref); +git_config_set (key,"true" ); + }printf ("Branch %s set up to track remote branch %s.\n" , new_ref, orig_ref); }
@@ -436,7 +444,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref) }static void create_branch (const char *name,const char *start_name, -int force,int reflog,int track) +int force,int reflog,int track,int rebase) {struct ref_lock *lock;struct commit *commit;
@@ -495,7 +503,7 @@ static void create_branch(const char *name, const char *start_name,automatically merges from there. So far, this is only done for remotes registered via .git/config. */ if (real_ref && track) -setup_tracking (name, real_ref); +setup_tracking (name, real_ref, rebase);if (write_ref_sha1 (lock, sha1, msg) <0 )die ("Failed to write ref: %s." ,strerror (errno));
@@ -566,12 +574,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix)int verbose =0 , abbrev =DEFAULT_ABBREV , detached =0 ;int reflog =0 , track;int kinds =REF_LOCAL_BRANCH ; +int rebase =0 ;struct commit_list *with_commit =NULL ;struct option options[] = {OPT_GROUP ("Generic options" ),OPT__VERBOSE (&verbose),OPT_BOOLEAN (0 ,"track" , &track,"set up tracking mode (see git-pull(1))" ), +OPT_BOOLEAN (0 ,"rebase" , &rebase,"set up branch to rebase (see git-pull(1))" ),OPT_BOOLEAN (0 ,"color" , &branch_use_color,"use colored output" ),OPT_SET_INT ('r' ,NULL , &kinds,"act on remote-tracking branches" ,REF_REMOTE_BRANCH ),
@@ -625,7 +635,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)rename_branch (argv[0 ], argv[1 ], rename >1 ); else if (argc <= 2) create_branch(argv[0], (argc == 2) ? argv[1] : head, - force_create, reflog, track); + force_create, reflog, track, rebase); else usage_with_options(builtin_branch_usage, options);
git-checkout.sh +8 -3
@@ -7,6 +7,7 @@ git-checkout [options] [<branch>] [<paths>...] b= create a new branch started at <branch> l create the new branch's reflog track arrange that the new branch tracks the remote branch +rebase arrange that the new branch rebases f proceed even if the index or working tree is not HEAD m merge local modifications into the new branch q,quiet be quiet
@@ -23,6 +24,7 @@ new_name= force= branch= track= +rebase= newbranch= newbranch_log= merge=
@@ -49,6 +51,9 @@ while test $# != 0; do --track|--no-track) track="$1" ;; + --rebase) + rebase="$1" + ;; -f) force=1 ;;
@@ -92,9 +97,9 @@ then fi [ "$1" = "--" ] && shift -case "$newbranch,$track" in +case "$newbranch,$track,$rebase" in ,--*) - die "git checkout: --track and --no-track require -b" + die "git checkout: --track, --no-track and --rebase require -b" esac case "$force$merge" in
@@ -261,7 +266,7 @@ fi # if [ "$?" -eq 0 ]; then if [ "$newbranch" ]; then - git branch $track $newbranch_log "$newbranch" "$new_name" || exit + git branch $track $rebase $newbranch_log "$newbranch" "$new_name" || exit branch="$newbranch" fi if test -n "$branch"
Signature · 1 line
1.5.4.1.1281.g75df
PATCH 1/1 branch: optionally setup branch.*.merge from upstream local branches
In reply to Jay Soffiangit branch / git checkout -b now honor --track when the upstream branch is local. Previously --track was silently ignored for local upstream branches.
The configuration setting branch.autosetupmerge can now be set to "always" which is equivalent to using --track. Setting branch.autosetupmerge to boolean true will retains the former behavior of only setting up branch.*.merge for remote upstream branches.
---
Quoted 9 lines · Johannes Schindelin
Hi,
Quoted 4 lines · Junio C Hamano
This area was last cleaned up in 6f084a5 (branch --track: code cleanup and saner handling of local branches). I do not know if the original intention of the code was to allow a hack like this to work, or it is just an unintended accident that it happens to work. Dscho, any ideas?
Quoted 6 lines
AFAIR the problem was that you were (rightfully) annoyed when you were setting up your local branches, and all of a sudden, they were set up with loads of tracking information, cluttering your config.
Basically, that is the reason why we disallowed tracking information to be set up for local branching.
Hopefully this is an acceptable compromise? Junio suggested making this implicit:
[remote "."]
fetch = refs/*:refs/*
But I thought that might affect other areas, and I don't think this is too bad.
branch.c | 12 ++++++++++-- branch.h | 8 +++++++- builtin-branch.c | 11 ++++++++--- builtin-checkout.c | 15 ++++++++++----- 4 files changed, 35 insertions(+), 11 deletions(-)
branch.c +10 -2
@@ -71,7 +71,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)void create_branch (const char *head,const char *name,const char *start_name, -int force,int reflog,int track) +int force,int reflog,enum branch_track track) {struct ref_lock *lock;struct commit *commit;
@@ -130,7 +130,15 @@ void create_branch(const char *head,automatically merges from there. So far, this is only done for remotes registered via .git/config. */ if (real_ref && track) -setup_tracking (name, real_ref); +if (setup_tracking (name, real_ref) ==1 && track ==BRANCH_TRACK_ALWAYS ) { +char key[1024 ]; +sprintf (key,"branch.%s.remote" , name); +git_config_set (key,"." ); +sprintf (key,"branch.%s.merge" , name); +git_config_set (key, real_ref); +printf ("Branch %s set up with upstream branch %s.\n" , + name, real_ref); + }if (write_ref_sha1 (lock, sha1, msg) <0 )die ("Failed to write ref: %s." ,strerror (errno));
branch.h +7 -1
@@ -1,6 +1,12 @@#ifndef BRANCH_H #define BRANCH_H +enum branch_track { +BRANCH_TRACK_FALSE =0 , +BRANCH_TRACK_TRUE =1 , +BRANCH_TRACK_ALWAYS =2 , +}; +/* Functions for acting on the information about branches. */ /*
@@ -13,7 +19,7 @@* branch for (if any). */ void create_branch (const char *head,const char *name,const char *start_name, -int force,int reflog,int track); +int force,int reflog,enum branch_track track);/* * Remove information about the state of working on the current
builtin-branch.c +8 -3
@@ -30,7 +30,7 @@ static const char * const builtin_branch_usage[] = {static const char *head;static unsigned char head_sha1[20 ]; -static int branch_track =1 ; +static enum branch_track branch_track =BRANCH_TRACK_FALSE ;static int branch_use_color;static char branch_colors[][COLOR_MAXLEN ] = {
@@ -77,6 +77,10 @@ static int git_branch_config(const char *var, const char *value)return 0 ; }if (!strcmp (var,"branch.autosetupmerge" )) { +if (value && !strcasecmp (value,"always" )) { + branch_track =BRANCH_TRACK_ALWAYS ; +return 0 ; + } branch_track =git_config_bool (var, value);return 0 ; }
@@ -420,14 +424,15 @@ int cmd_branch(int argc, const char **argv, const char *prefix) {int delete =0 , rename =0 , force_create =0 ;int verbose =0 , abbrev =DEFAULT_ABBREV , detached =0 ; -int reflog =0 , track; +int reflog =0 ; +enum branch_track track;int kinds =REF_LOCAL_BRANCH ;struct commit_list *with_commit =NULL ;struct option options[] = {OPT_GROUP ("Generic options" ),OPT__VERBOSE (&verbose), -OPT_BOOLEAN (0 ,"track" , &track,"set up tracking mode (see git-pull(1))" ), +OPT_SET_INT (0 ,"track" , &track,"set up tracking mode (see git-pull(1))" ,BRANCH_TRACK_ALWAYS ),OPT_BOOLEAN (0 ,"color" , &branch_use_color,"use colored output" ),OPT_SET_INT ('r' ,NULL , &kinds,"act on remote-tracking branches" ,REF_REMOTE_BRANCH ),
builtin-checkout.c +10 -5
@@ -186,7 +186,7 @@ struct checkout_opts {char *new_branch;int new_branch_log; -int track; +enum branch_track track; };struct branch_info {
@@ -521,13 +521,18 @@ static int switch_branches(struct checkout_opts *opts,return post_checkout_hook (old.commit, new->commit,1 ); } -static int branch_track =0 ; +static enum branch_track branch_track =BRANCH_TRACK_FALSE ;static int git_checkout_config (const char *var,const char *value) { -if (!strcmp (var,"branch.autosetupmerge" )) +if (!strcmp (var,"branch.autosetupmerge" )) { +if (value && !strcasecmp (value,"always" )) { + branch_track =BRANCH_TRACK_ALWAYS ; +return 0 ; + } branch_track =git_config_bool (var, value); - +return 0 ; + }return git_default_config (var, value); }
@@ -542,7 +547,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)OPT__QUIET (&opts.quiet),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" ,BRANCH_TRACK_ALWAYS ),OPT_BOOLEAN ('f' ,NULL , &opts.force,"force" ),OPT_BOOLEAN ('m' ,NULL , &opts.merge,"merge" ), OPT_END(),
Signature · 1 line
1.5.4.2.183.g9fe5b
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Hi,
branch.h line 6
Quoted 11 lines · Jay Soffian
branch.h +3
-0@@ -1,6 +1,12 @@#ifndef BRANCH_H #define BRANCH_H +enum branch_track { +BRANCH_TRACK_FALSE =0 , + BRANCH_TRACK_TRUE = 1,
BRANCH_TRACK_REMOTES would be a better name here. And you do not need the "= 1" and "= 2".
Quoted 11 lines
branch.h +3
-0+ BRANCH_TRACK_ALWAYS = 2, +}; +/* Functions for acting on the information about branches. */ /* builtin-branch.c +0
-0
builtin-branch.c static const char * const builtin_branch_usage[] = { · line 33
Quoted 5 lines
builtin-branch.c +1
-1@@ -30,7 +30,7 @@ static const char * const builtin_branch_usage[] = {static const char *head;static unsigned char head_sha1[20 ]; -static int branch_track =1 ; +static enum branch_track branch_track =BRANCH_TRACK_FALSE ;
That is a clear regression.
builtin-branch.c static int git_branch_config(const char *var, const char *value) · line 86
Quoted 11 lines
builtin-branch.c +4
-0@@ -77,6 +77,10 @@ static int git_branch_config(const char *var, const char *value)return 0 ; }if (!strcmp (var,"branch.autosetupmerge" )) { +if (value && !strcasecmp (value,"always" )) { + branch_track =BRANCH_TRACK_ALWAYS ; +return 0 ; + } branch_track =git_config_bool (var, value);return 0 ; }
You have this in builtin-branch.c and builtin-checkout.c. Duplicated code. IMHO it is time to move this into the git_default_config() function (with "branch_track" being renamed to "git_branch_track", and moved to environment.c).
Personally, I have no problem with typing "git merge <branch>" in your workflow. I would even avoid saying "git pull" for obviously-local branches, because I would have forgotten which branch it tracked originally.
But hey, if you really want to... ;-)
Ciao,
Dscho
PATCH 1/1 branch: optionally setup branch.*.merge from upstream local branches
git branch / git checkout -b now honor --track when the upstream branch is local. Previously --track was silently ignored for local upstream branches.
The configuration setting branch.autosetupmerge can now be set to "always" which is equivalent to using --track. Setting branch.autosetupmerge to boolean true will retains the former behavior of only setting up branch.*.merge for remote upstream branches.
---
Incorporated Johannes' feedback and updated documentation as well.
Documentation/config.txt | 13 ++++++++----- Documentation/git-branch.txt | 24 ++++++++++++------------ Documentation/git-checkout.txt | 25 ++++++++++++------------- branch.c | 12 ++++++++++-- branch.h | 2 +- builtin-branch.c | 13 ++++--------- builtin-checkout.c | 13 ++++--------- cache.h | 8 ++++++++ config.c | 8 ++++++++ environment.c | 1 + 10 files changed, 68 insertions(+), 51 deletions(-)
Documentation/config.txt +8 -5
@@ -378,11 +378,14 @@ apply.whitespace:: as the '--whitespace' option. See linkgit:git-apply[1]. branch.autosetupmerge:: - Tells `git-branch` and `git-checkout` to setup new branches - so that linkgit:git-pull[1] will appropriately merge from that - remote branch. Note that even if this option is not set, - this behavior can be chosen per-branch using the `--track` - and `--no-track` options. This option defaults to true. + Tells `git-branch` and `git-checkout` to setup `branch.*.remote` + and `branch.*.merge` for new branches so that linkgit:git-pull[1] + will appropriately merge from that upstream branch. Note that even + if this option is not set, this behavior can be chosen per-branch + using the `--track` and `--no-track` options. This option defaults + to true, which will setup tracking for remote branches. Set it to + `always` to automatically setup the aforementioned options for local + upstream branches as well. branch.<name>.remote:: When in branch <name>, it tells `git fetch` which remote to fetch.
Documentation/git-branch.txt +12 -12
@@ -105,20 +105,20 @@ OPTIONS Display the full sha1s in output listing rather than abbreviating them. --track:: - Set up configuration so that git-pull will automatically - retrieve data from the remote branch. Use this if you always - pull from the same remote branch into the new branch, or if you - don't want to use "git pull <repository> <refspec>" explicitly. - This behavior is the default. Set the - branch.autosetupmerge configuration variable to false if you - want git-checkout and git-branch to always behave as if - '--no-track' were given. + Set up configuration so that git-pull will + automatically retrieve data from the upstream branch. Use this if + you always pull from the same upstream branch into the new branch, + or if you don't want to use "git pull <repository> <refspec>" + explicitly. This behavior is the default for remote branches. + Set the branch.autosetupmerge configuration variable to false if you + want git-checkout and git-branch to always behave as if '--no-track' + were given. Set it to 'always' if you want git-checkout and git-branch + to always behave as if '--track' were given. --no-track:: - When a branch is created off a remote branch, - set up configuration so that git-pull will not retrieve data - from the remote branch, ignoring the branch.autosetupmerge - configuration variable. + Ignore the branch.autosetupmerge configuration variable. When + using git pull with the new branch, a <refspec> will have to be + given explicitly. <branchname>:: The name of the branch to create or delete.
Documentation/git-checkout.txt +12 -13
@@ -48,21 +48,20 @@ OPTIONS may restrict the characters allowed in a branch name. --track:: - When -b is given and a branch is created off a remote branch, - set up configuration so that git-pull will automatically - retrieve data from the remote branch. Use this if you always - pull from the same remote branch into the new branch, or if you - don't want to use "git pull <repository> <refspec>" explicitly. - This behavior is the default. Set the - branch.autosetupmerge configuration variable to false if you - want git-checkout and git-branch to always behave as if - '--no-track' were given. + When -b is given set up configuration so that git-pull will + automatically retrieve data from the upstream branch. Use this if + you always pull from the same upstream branch into the new branch, + or if you don't want to use "git pull <repository> <refspec>" + explicitly. This behavior is the default for remote branches. + Set the branch.autosetupmerge configuration variable to false if you + want git-checkout and git-branch to always behave as if '--no-track' + were given. Set it to 'always' if you want git-checkout and git-branch + to always behave as if '--track' were given. --no-track:: - When -b is given and a branch is created off a remote branch, - set up configuration so that git-pull will not retrieve data - from the remote branch, ignoring the branch.autosetupmerge - configuration variable. + Ignore the branch.autosetupmerge configuration variable. When + using git pull with the new branch, a <refspec> will have to be + given explicitly. -l:: Create the new branch's reflog. This activates recording of
branch.c +10 -2
@@ -71,7 +71,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)void create_branch (const char *head,const char *name,const char *start_name, -int force,int reflog,int track) +int force,int reflog,enum branch_track track) {struct ref_lock *lock;struct commit *commit;
@@ -130,7 +130,15 @@ void create_branch(const char *head,automatically merges from there. So far, this is only done for remotes registered via .git/config. */ if (real_ref && track) -setup_tracking (name, real_ref); +if (setup_tracking (name, real_ref) ==1 && track ==BRANCH_TRACK_ALWAYS ) { +char key[1024 ]; +sprintf (key,"branch.%s.remote" , name); +git_config_set (key,"." ); +sprintf (key,"branch.%s.merge" , name); +git_config_set (key, real_ref); +printf ("Branch %s set up with upstream branch %s.\n" , + name, real_ref); + }if (write_ref_sha1 (lock, sha1, msg) <0 )die ("Failed to write ref: %s." ,strerror (errno));
branch.h +1 -1
@@ -13,7 +13,7 @@* branch for (if any). */ void create_branch (const char *head,const char *name,const char *start_name, -int force,int reflog,int track); +int force,int reflog,enum branch_track track);/* * Remove information about the state of working on the current
builtin-branch.c +4 -9
@@ -30,8 +30,6 @@ static const char * const builtin_branch_usage[] = {static const char *head;static unsigned char head_sha1[20 ]; -static int branch_track =1 ; -static int branch_use_color =-1 ;static char branch_colors[][COLOR_MAXLEN ] = {"\033[m" ,/* reset */
@@ -76,10 +74,6 @@ 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 =git_config_bool (var, value); -return 0 ; - }return git_color_default_config (var, value); }
@@ -420,14 +414,15 @@ int cmd_branch(int argc, const char **argv, const char *prefix) {int delete =0 , rename =0 , force_create =0 ;int verbose =0 , abbrev =DEFAULT_ABBREV , detached =0 ; -int reflog =0 , track; +int reflog =0 ; +enum branch_track track;int kinds =REF_LOCAL_BRANCH ;struct commit_list *with_commit =NULL ;struct option options[] = {OPT_GROUP ("Generic options" ),OPT__VERBOSE (&verbose), -OPT_BOOLEAN (0 ,"track" , &track,"set up tracking mode (see git-pull(1))" ), +OPT_SET_INT (0 ,"track" , &track,"set up tracking mode (see git-pull(1))" ,BRANCH_TRACK_ALWAYS ),OPT_BOOLEAN (0 ,"color" , &branch_use_color,"use colored output" ),OPT_SET_INT ('r' ,NULL , &kinds,"act on remote-tracking branches" ,REF_REMOTE_BRANCH ),
@@ -458,7 +453,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)if (branch_use_color ==-1 ) branch_use_color = git_use_color_default; - track = branch_track; + track = git_branch_track; argc =parse_options (argc, argv, options, builtin_branch_usage,0 );if (!!delete + !!rename + !!force_create >1 )usage_with_options (builtin_branch_usage, options);
builtin-checkout.c +4 -9
@@ -186,7 +186,7 @@ struct checkout_opts {char *new_branch;int new_branch_log; -int track; +enum branch_track track; };struct branch_info {
@@ -521,13 +521,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); }
@@ -542,7 +537,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)OPT__QUIET (&opts.quiet),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" ,BRANCH_TRACK_ALWAYS ),OPT_BOOLEAN ('f' ,NULL , &opts.force,"force" ),OPT_BOOLEAN ('m' ,NULL , &opts.merge,"merge" ), OPT_END(),
@@ -553,7 +548,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)git_config (git_checkout_config); - opts.track = branch_track; + opts.track = git_branch_track; argc =parse_options (argc, argv, options, checkout_usage,0 );if (argc) {
@@ -582,7 +577,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) argc--; } -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)
cache.h +8 -0
@@ -393,6 +393,14 @@ enum safe_crlf {extern enum safe_crlf safe_crlf; +enum branch_track { +BRANCH_TRACK_REMOTES_FALSE =0 , +BRANCH_TRACK_REMOTES_TRUE , +BRANCH_TRACK_ALWAYS , +}; + +extern enum branch_track git_branch_track; +#define GIT_REPO_VERSION 0extern int repository_format_version;extern int check_repository_format (void );
config.c +8 -0
@@ -464,6 +464,14 @@ int git_default_config(const char *var, const char *value) whitespace_rule_cfg =parse_whitespace_rule (value);return 0 ; } +if (!strcmp (var,"branch.autosetupmerge" )) { +if (value && !strcasecmp (value,"always" )) { + git_branch_track =BRANCH_TRACK_ALWAYS ; +return 0 ; + } + git_branch_track =git_config_bool (var, value); +return 0 ; + }/* Add other config variables here and to Documentation/config.txt. */ return 0 ;
environment.c +1 -0
@@ -37,6 +37,7 @@ const char *excludes_file;int auto_crlf =0 ;/* 1: both ways, -1: only when adding git objects */ enum safe_crlf safe_crlf =SAFE_CRLF_WARN ;unsigned whitespace_rule_cfg =WS_DEFAULT_RULE ; +enum branch_track git_branch_track =BRANCH_TRACK_REMOTES_TRUE ;/* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg;
Signature · 1 line
1.5.4.2.203.gf8d86
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Hi,
sorry, I overlooked that earlier:
branch.c void create_branch(const char *head, · line 133
Quoted 10 lines · Jay Soffian
branch.c +1
-1@@ -130,7 +130,15 @@ void create_branch(const char *head,automatically merges from there. So far, this is only done for remotes registered via .git/config. */ if (real_ref && track) -setup_tracking (name, real_ref); +if (setup_tracking (name, real_ref) ==1 && track ==BRANCH_TRACK_ALWAYS ) {
This line is too long.
branch.c void create_branch(const char *head, · line 135
Quoted 2 lines
branch.c +2
-0+char key[1024 ]; +sprintf (key,"branch.%s.remote" , name);
To stay safe, you should use snprintf() and test the return value.
branch.c void create_branch(const char *head, · line 137
Quoted 2 lines
branch.c +2
-0+git_config_set (key,"." ); +sprintf (key,"branch.%s.merge" , name);
Same here.
Thanks,
Dscho
PATCH 1/1 branch: optionally setup branch.*.merge from upstream local branches
git branch / git checkout -b now honor --track when the upstream branch is local. Previously --track was silently ignored for local upstream branches.
The configuration setting branch.autosetupmerge can now be set to "always" which is equivalent to using --track. Setting branch.autosetupmerge to boolean true will retains the former behavior of only setting up branch.*.merge for remote upstream branches.
---
Incorporated Johannes' second round of feedback. This should be all for awhile.
Documentation/config.txt | 13 ++++++++----- Documentation/git-branch.txt | 24 ++++++++++++------------ Documentation/git-checkout.txt | 25 ++++++++++++------------- branch.c | 19 ++++++++++++------- branch.h | 2 +- builtin-branch.c | 13 ++++--------- builtin-checkout.c | 13 ++++--------- cache.h | 8 ++++++++ config.c | 8 ++++++++ environment.c | 1 + 10 files changed, 70 insertions(+), 56 deletions(-)
Documentation/config.txt +8 -5
@@ -378,11 +378,14 @@ apply.whitespace:: as the '--whitespace' option. See linkgit:git-apply[1]. branch.autosetupmerge:: - Tells `git-branch` and `git-checkout` to setup new branches - so that linkgit:git-pull[1] will appropriately merge from that - remote branch. Note that even if this option is not set, - this behavior can be chosen per-branch using the `--track` - and `--no-track` options. This option defaults to true. + Tells `git-branch` and `git-checkout` to setup `branch.*.remote` + and `branch.*.merge` for new branches so that linkgit:git-pull[1] + will appropriately merge from that upstream branch. Note that even + if this option is not set, this behavior can be chosen per-branch + using the `--track` and `--no-track` options. This option defaults + to true, which will setup tracking for remote branches. Set it to + `always` to automatically setup the aforementioned options for local + upstream branches as well. branch.<name>.remote:: When in branch <name>, it tells `git fetch` which remote to fetch.
Documentation/git-branch.txt +12 -12
@@ -105,20 +105,20 @@ OPTIONS Display the full sha1s in output listing rather than abbreviating them. --track:: - Set up configuration so that git-pull will automatically - retrieve data from the remote branch. Use this if you always - pull from the same remote branch into the new branch, or if you - don't want to use "git pull <repository> <refspec>" explicitly. - This behavior is the default. Set the - branch.autosetupmerge configuration variable to false if you - want git-checkout and git-branch to always behave as if - '--no-track' were given. + Set up configuration so that git-pull will + automatically retrieve data from the upstream branch. Use this if + you always pull from the same upstream branch into the new branch, + or if you don't want to use "git pull <repository> <refspec>" + explicitly. This behavior is the default for remote branches. + Set the branch.autosetupmerge configuration variable to false if you + want git-checkout and git-branch to always behave as if '--no-track' + were given. Set it to 'always' if you want git-checkout and git-branch + to always behave as if '--track' were given. --no-track:: - When a branch is created off a remote branch, - set up configuration so that git-pull will not retrieve data - from the remote branch, ignoring the branch.autosetupmerge - configuration variable. + Ignore the branch.autosetupmerge configuration variable. When + using git pull with the new branch, a <refspec> will have to be + given explicitly. <branchname>:: The name of the branch to create or delete.
Documentation/git-checkout.txt +12 -13
@@ -48,21 +48,20 @@ OPTIONS may restrict the characters allowed in a branch name. --track:: - When -b is given and a branch is created off a remote branch, - set up configuration so that git-pull will automatically - retrieve data from the remote branch. Use this if you always - pull from the same remote branch into the new branch, or if you - don't want to use "git pull <repository> <refspec>" explicitly. - This behavior is the default. Set the - branch.autosetupmerge configuration variable to false if you - want git-checkout and git-branch to always behave as if - '--no-track' were given. + When -b is given set up configuration so that git-pull will + automatically retrieve data from the upstream branch. Use this if + you always pull from the same upstream branch into the new branch, + or if you don't want to use "git pull <repository> <refspec>" + explicitly. This behavior is the default for remote branches. + Set the branch.autosetupmerge configuration variable to false if you + want git-checkout and git-branch to always behave as if '--no-track' + were given. Set it to 'always' if you want git-checkout and git-branch + to always behave as if '--track' were given. --no-track:: - When -b is given and a branch is created off a remote branch, - set up configuration so that git-pull will not retrieve data - from the remote branch, ignoring the branch.autosetupmerge - configuration variable. + Ignore the branch.autosetupmerge configuration variable. When + using git pull with the new branch, a <refspec> will have to be + given explicitly. -l:: Create the new branch's reflog. This activates recording of
branch.c +12 -7
@@ -37,7 +37,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)* to infer the settings for branch.<new_ref>.{remote,merge} from the * config. */ -static int setup_tracking (const char *new_ref,const char *orig_ref) +static int setup_tracking (const char *new_ref,const char *orig_ref,int always) {char key[1024 ];struct tracking tracking;
@@ -49,8 +49,12 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)memset (&tracking,0 ,sizeof (tracking)); tracking.spec.dst = (char *)orig_ref;if (for_each_remote (find_tracked_branch, &tracking) || - !tracking.matches) -return 1 ; + !tracking.matches) { +if (!always) +return 1 ; + tracking.matches =1 ; + tracking.src =xstrdup (orig_ref); + }if (tracking.matches >1 ) return error("Not tracking: ambiguous information for ref %s",
@@ -62,8 +66,9 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)sprintf (key,"branch.%s.merge" , new_ref);git_config_set (key, tracking.src);free (tracking.src); -printf ("Branch %s set up to track remote branch %s.\n" , - new_ref, orig_ref); +printf ("Branch %s set up to track %s branch %s.\n" , + new_ref, tracking.remote ?"remote" :"local" , + orig_ref); }return 0 ;
@@ -71,7 +76,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)void create_branch (const char *head,const char *name,const char *start_name, -int force,int reflog,int track) +int force,int reflog,enum branch_track track) {struct ref_lock *lock;struct commit *commit;
@@ -130,7 +135,7 @@ void create_branch(const char *head,automatically merges from there. So far, this is only done for remotes registered via .git/config. */ if (real_ref && track) -setup_tracking (name, real_ref); +setup_tracking (name, real_ref, (track ==BRANCH_TRACK_ALWAYS ));if (write_ref_sha1 (lock, sha1, msg) <0 )die ("Failed to write ref: %s." ,strerror (errno));
branch.h +1 -1
@@ -13,7 +13,7 @@* branch for (if any). */ void create_branch (const char *head,const char *name,const char *start_name, -int force,int reflog,int track); +int force,int reflog,enum branch_track track);/* * Remove information about the state of working on the current
builtin-branch.c +4 -9
@@ -30,8 +30,6 @@ static const char * const builtin_branch_usage[] = {static const char *head;static unsigned char head_sha1[20 ]; -static int branch_track =1 ; -static int branch_use_color =-1 ;static char branch_colors[][COLOR_MAXLEN ] = {"\033[m" ,/* reset */
@@ -76,10 +74,6 @@ 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 =git_config_bool (var, value); -return 0 ; - }return git_color_default_config (var, value); }
@@ -420,14 +414,15 @@ int cmd_branch(int argc, const char **argv, const char *prefix) {int delete =0 , rename =0 , force_create =0 ;int verbose =0 , abbrev =DEFAULT_ABBREV , detached =0 ; -int reflog =0 , track; +int reflog =0 ; +enum branch_track track;int kinds =REF_LOCAL_BRANCH ;struct commit_list *with_commit =NULL ;struct option options[] = {OPT_GROUP ("Generic options" ),OPT__VERBOSE (&verbose), -OPT_BOOLEAN (0 ,"track" , &track,"set up tracking mode (see git-pull(1))" ), +OPT_SET_INT (0 ,"track" , &track,"set up tracking mode (see git-pull(1))" ,BRANCH_TRACK_ALWAYS ),OPT_BOOLEAN (0 ,"color" , &branch_use_color,"use colored output" ),OPT_SET_INT ('r' ,NULL , &kinds,"act on remote-tracking branches" ,REF_REMOTE_BRANCH ),
@@ -458,7 +453,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)if (branch_use_color ==-1 ) branch_use_color = git_use_color_default; - track = branch_track; + track = git_branch_track; argc =parse_options (argc, argv, options, builtin_branch_usage,0 );if (!!delete + !!rename + !!force_create >1 )usage_with_options (builtin_branch_usage, options);
builtin-checkout.c +4 -9
@@ -186,7 +186,7 @@ struct checkout_opts {char *new_branch;int new_branch_log; -int track; +enum branch_track track; };struct branch_info {
@@ -521,13 +521,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); }
@@ -542,7 +537,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)OPT__QUIET (&opts.quiet),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" ,BRANCH_TRACK_ALWAYS ),OPT_BOOLEAN ('f' ,NULL , &opts.force,"force" ),OPT_BOOLEAN ('m' ,NULL , &opts.merge,"merge" ), OPT_END(),
@@ -553,7 +548,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)git_config (git_checkout_config); - opts.track = branch_track; + opts.track = git_branch_track; argc =parse_options (argc, argv, options, checkout_usage,0 );if (argc) {
@@ -582,7 +577,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) argc--; } -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)
cache.h +8 -0
@@ -393,6 +393,14 @@ enum safe_crlf {extern enum safe_crlf safe_crlf; +enum branch_track { +BRANCH_TRACK_REMOTES_FALSE =0 , +BRANCH_TRACK_REMOTES_TRUE , +BRANCH_TRACK_ALWAYS , +}; + +extern enum branch_track git_branch_track; +#define GIT_REPO_VERSION 0extern int repository_format_version;extern int check_repository_format (void );
config.c +8 -0
@@ -464,6 +464,14 @@ int git_default_config(const char *var, const char *value) whitespace_rule_cfg =parse_whitespace_rule (value);return 0 ; } +if (!strcmp (var,"branch.autosetupmerge" )) { +if (value && !strcasecmp (value,"always" )) { + git_branch_track =BRANCH_TRACK_ALWAYS ; +return 0 ; + } + git_branch_track =git_config_bool (var, value); +return 0 ; + }/* Add other config variables here and to Documentation/config.txt. */ return 0 ;
environment.c +1 -0
@@ -37,6 +37,7 @@ const char *excludes_file;int auto_crlf =0 ;/* 1: both ways, -1: only when adding git objects */ enum safe_crlf safe_crlf =SAFE_CRLF_WARN ;unsigned whitespace_rule_cfg =WS_DEFAULT_RULE ; +enum branch_track git_branch_track =BRANCH_TRACK_REMOTES_TRUE ;/* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg;
Signature · 1 line
1.5.4.2.203.gf8d86
PATCH 1/1 test cases: optionally setup branch.*.merge from upstream local branches
Added test cases for new "optionally setup branch.*.merge from upstream local branches" functionality.
--- t/t3200-branch.sh | 21 +++++++++++++++++++-- 1 files changed, 19 insertions(+), 2 deletions(-)
t/t3200-branch.sh +19 -2
@@ -161,7 +161,7 @@ test_expect_success 'avoid ambiguous track' ' ' test_expect_success 'test overriding tracking setup via --no-track' \ - 'git config branch.autosetupmerge true && + 'git config branch.autosetupmerge always && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/master || git-fetch local) &&
@@ -171,7 +171,9 @@ test_expect_success 'test overriding tracking setup via --no-track' \ ! test "$(git config branch.my2.merge)" = refs/heads/master' test_expect_success 'no tracking without .fetch entries' \ - 'git branch --track my6 s && + 'git config branch.autosetupmerge true && + git branch my6 s && + git config branch.automsetupmerge false && test -z "$(git config branch.my6.remote)" && test -z "$(git config branch.my6.merge)"'
@@ -192,6 +194,21 @@ test_expect_success 'test deleting branch without config' \ 'git branch my7 s && test "$(git branch -d my7 2>&1)" = "Deleted branch my7."' +test_expect_success 'test tracking without .fetch entries w/--track given' \ + 'git branch --track my8 && + test "$(git config branch.my8.remote)" && + test "$(git config branch.my8.merge)"' + +test_expect_success \ + 'test tracking without .fetch entries w/autosetupmerge=always' \ + 'git config branch.autosetupmerge always && + git branch --track my9 && + git config branch.autosetupmerge false + test "$(git config branch.my9.remote)" && + test "$(git config branch.my9.merge)"' + + + # Keep this test last, as it changes the current branch cat >expect <<EOF 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
Signature · 1 line
1.5.4.2.203.gf8d86
Re: [PATCH] test cases: optionally setup branch.*.merge from upstream local branches
Hi,
Quoted 6 lines · Jay Soffian
Added test cases for new "optionally setup branch.*.merge from upstream local branches" functionality.
Signed-off-by Jay Soffian <[email protected]>--- t/t3200-branch.sh | 21 +++++++++++++++++++--
You might want to add another patch, this time to t7201-co.sh, which demonstrates that even a "branch.autosetupmerge false" does not prevent "git checkout --track -b <name>" from working.
Ciao,
Dscho
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
In reply to Jay SoffianHi,
Quoted 1 line · Jay Soffian
Incorporated Johannes' second round of feedback.
Not exactly.
Quoted 16 lines
branch.c +1
-1@@ -37,7 +37,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)* to infer the settings for branch.<new_ref>.{remote,merge} from the * config. */ -static int setup_tracking (const char *new_ref,const char *orig_ref) +static int setup_tracking (const char *new_ref,const char *orig_ref,int always) {char key[1024 ];struct tracking tracking;@@ -49,8 +49,12 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)memset (&tracking,0 ,sizeof (tracking)); tracking.spec.dst = (char *)orig_ref;
branch.c static int setup_tracking(const char *new_ref, const char *orig_ref) · line 58
Quoted 10 lines
branch.c +6
-2if (for_each_remote (find_tracked_branch, &tracking) || - !tracking.matches) -return 1 ; + !tracking.matches) { +if (!always) +return 1 ; + tracking.matches =1 ; + tracking.src =xstrdup (orig_ref); + }
This looks completely different than what I commented on. And my comments suggested a different solution.
Unfortunately, I will not have time for the rest of the day to review that new thing (it is not at all obvious for me why this works as intended, and does not break anything else).
But you can use the time to write some tests ;-)
Ciao,
Dscho
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Quoted 7 lines · Johannes Schindelin
Hi,
Quoted 1 line · Jay Soffian
Incorporated Johannes' second round of feedback.
Not exactly.
Heh...
Quoted 2 lines
This looks completely different than what I commented on. And my comments suggested a different solution.
Thought process went like this:
- fix sprintf() to use snprintf()
- notice setup_tracking() uses sprintf() and think about fixing it too
- realize setup_tracking() does bounds checking first and its use of sprintf() is therefor safe.
- go to copy the bounds checking code from setup_tracking() to the area you commented on.
- realized duplicating the code was dumb and I could just re-use what was already in setup_tracking() via what was just sent.
Quoted 1 line
But you can use the time to write some tests ;-)
Sure I can. I really hope after all this work the patch gets accepted.
j.
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
In reply to Jay SoffianHi,
Quoted 6 lines · Jay Soffian
branch.c +0
-0@@ -49,8 +49,12 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)memset (&tracking,0 ,sizeof (tracking));
branch.c static int setup_tracking(const char *new_ref, const char *orig_ref) · line 57
Quoted 10 lines
branch.c +6
-2tracking.spec.dst = (char *)orig_ref;if (for_each_remote (find_tracked_branch, &tracking) || - !tracking.matches) -return 1 ; + !tracking.matches) { +if (!always) +return 1 ; + tracking.matches =1 ; + tracking.src =xstrdup (orig_ref); + }
I think you need to split this into
if (for_each_remote(...)) return 1; if (!tracking.matches && !always) return 1;
because an error in for_each_remote() is a proper error, and should not be ignored (speaking of which, the return value is unchecked...). And then, later,
if (tracking.matches == 1) {
sprintf(key, "branch.%s.remote", new_ref);
git_config_set(key, tracking.remote ? tracking.remote : ".");
sprintf(key, "branch.%s.merge", new_ref);
- git_config_set(key, tracking.src);
+ git_config_set(key, tracking.src ? tracking.src : orig_ref);
free(tracking.src);branch.c void create_branch(const char *head, · line 138
Quoted 6 lines
branch.c +1
-1@@ -130,7 +135,7 @@ void create_branch(const char *head,automatically merges from there. So far, this is only done for remotes registered via .git/config. */ if (real_ref && track) -setup_tracking (name, real_ref); +setup_tracking (name, real_ref, (track ==BRANCH_TRACK_ALWAYS ));
It is a matter of taste, I guess, but I would remove the parens around the boolean expression.
FWIW a very good argument in favour of your patch is IMHO that now, "--track" works as a user would expect, even for local branch-offs.
And of course that you were very responsive, and really put in a lot of effort.
Thanks,
Dscho
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
In reply to Johannes SchindelinQuoted 19 lines · Johannes Schindelin
Hi,
sorry, I overlooked that earlier:
branch.c void create_branch(const char *head, · line 133
Quoted 10 lines · Jay Soffian
branch.c +1
-1@@ -130,7 +130,15 @@ void create_branch(const char *head,automatically merges from there. So far, this is only done for remotes registered via .git/config. */ if (real_ref && track) -setup_tracking (name, real_ref); +if (setup_tracking (name, real_ref) ==1 && track ==BRANCH_TRACK_ALWAYS ) {This line is too long.
Quoted 4 lines
branch.c void create_branch(const char *head, · line 135
Quoted 2 lines
branch.c +2
-0+char key[1024 ]; +sprintf (key,"branch.%s.remote" , name);To stay safe, you should use
snprintf()and test the return value.
Or use strbufs.
Mike
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
In reply to Johannes SchindelinQuoted 8 lines · Johannes Schindelin
branch.h line 6
Quoted 3 lines · Jay Soffian
branch.h +3
-0+enum branch_track { +BRANCH_TRACK_FALSE =0 , +BRANCH_TRACK_TRUE =1 ,
BRANCH_TRACK_REMOTESwould be a better name here. And you do not need the "= 1" and "= 2".
I was just following along. Plenty of enum examples in the current code do this. Am I missing something subtle about when assigning explicit values should be done?
Quoted 5 lines
builtin-branch.c static const char * const builtin_branch_usage[] = { · line 33
Quoted 3 lines
builtin-branch.c +1
-1-static int branch_track =1 ; +static enum branch_track branch_track =BRANCH_TRACK_FALSE ;That is a clear regression.
Perhaps. It's consistent with builtin-checkout.c though (which was initializing it to 0). Who to believe?
Quoted 8 lines
Quoted 8 lines
builtin-branch.c +4
-0@@ -77,6 +77,10 @@ static int git_branch_config(const char *var, const char *value)return 0 ; }if (!strcmp (var,"branch.autosetupmerge" )) { +if (value && !strcasecmp (value,"always" )) { + branch_track =BRANCH_TRACK_ALWAYS ; +return 0 ; + }
Quoted 8 lines
builtin-branch.c static int git_branch_config(const char *var, const char *value) · line 86
Quoted 3 lines
builtin-branch.c +0
-0branch_track =git_config_bool (var, value);return 0 ; }You have this in
builtin-branch.candbuiltin-checkout.c. Duplicated code. IMHO it is time to move this into thegit_default_config()function (with "branch_track" being renamed to "git_branch_track", and moved toenvironment.c).
Mkay, builtin-checkout.c author didn't do it, so...
Quoted 4 lines
Personally, I have no problem with typing "git merge <branch>" in your workflow. I would even avoid saying "git pull" for obviously-local branches, because I would have forgotten which branch it tracked originally.
Um, well, apply this patch, set branch.autosetupmerge=always and then branch.*.merge will tell you which branch it tracked originally. :-)
Aside, then how do you figure out the upstream branch is if you've forgotten?
j.
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Hi,
Quoted 11 lines · Jay Soffian
Quoted 6 lines · Johannes Schindelin
builtin-branch.c static const char * const builtin_branch_usage[] = { · line 33
Quoted 2 lines · Jay Soffian
builtin-branch.c +1
-1-static int branch_track =1 ; +static enum branch_track branch_track =BRANCH_TRACK_FALSE ;That is a clear regression.
Perhaps. It's consistent with
builtin-checkout.cthough (which was initializing it to 0). Who to believe?
Well, in the way _you_ implemented it, it is a clear regression, since _your_ patch changes the 1 to a 0.
Quoted 7 lines
Quoted 4 lines
Personally, I have no problem with typing "git merge <branch>" in your workflow. I would even avoid saying "git pull" for obviously-local branches, because I would have forgotten which branch it tracked originally.
Um, well, apply this patch, set branch.autosetupmerge=always and then branch.*.merge will tell you which branch it tracked originally. :-)
That's what I meant. Rather than _looking it up_, and then saying "git pull", I'd do "git merge <branch>" _directly_. One command. Not two.
Quoted 2 lines
Aside, then how do you figure out the upstream branch is if you've forgotten?
Well, that's easy. I would look at the output of "git show-branch --all".
But then, I usually do not care too much which branch I branched off, but which branch to merge with/rebase on.
Ciao,
Dscho
Quoted 11 lines · Jay Soffian
builtin-branch.c +3
-0@@ -402,6 +402,16 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)return error ("Tracking not set up: name too long: %s" , new_ref); +if (!prefixcmp (orig_ref,"refs/heads/" )) { +sprintf (key,"branch.%s.remote" , new_ref); +git_config_set (key,"." );
builtin-branch.c static int setup_tracking(const char *new_ref, const char *orig_ref) · line 417
Quoted 10 lines
builtin-branch.c +7
-0+sprintf (key,"branch.%s.merge" , new_ref); +git_config_set (key, orig_ref); +printf ("Branch %s set up to track local branch %s.\n" , + new_ref, orig_ref); +return 0 ; + } +memset (&tracking,0 ,sizeof (tracking)); tracking.spec.dst = (char *)orig_ref; if (for_each_remote(find_tracked_branch, &tracking) ||
Although I am not so familiar with this area, the patch somehow did not feel right, so I ended up doing a bit of digging.
After the context of the patch, we have this:
if (tracking.matches == 1) {
sprintf(key, "branch.%s.remote", new_ref);
git_config_set(key, tracking.remote ? tracking.remote : ".");
sprintf(key, "branch.%s.merge", new_ref);
git_config_set(key, tracking.src);So it looks to me that the code already has intention to set the "branch.*.remote" variable to "." when certain condition is met. And the condition is "when tracking.remote is NULL, or it is already a dot".
for_each_remote() iterates thru the remotes andfind_tracked_branch() does this:
static int find_tracked_branch(struct remote *remote, void *priv)
{
struct tracking *tracking = priv;
if (!remote_find_tracking(remote, &tracking->spec)) {
if (++tracking->matches == 1) {
tracking->src = tracking->spec.src;
tracking->remote = remote->name;
} else {
free(tracking->spec.src);
if (tracking->src) {
free(tracking->src);
tracking->src = NULL;
}
}
tracking->spec.src = NULL;
}
return 0;
}So if there is a remote whose name is "." (or NULL, but I do not know when that can happen --- remote.c::make_remote() does not allow creating such a remote as far as I can tell), that would be found without the added extra code, wouldn't it?
I did a bit of experiment and with this in .git/config:
[remote "."]
fetch = refs/*:refs/*it turns out that you do not have to patch the code at all. The above manual configuration feels somewhat like an ugly hack but perhaps we should make the above two lines implied? This area was last cleaned up in 6f084a5 (branch --track: code cleanup and saner handling of local branches). I do not know if the original intention of the code was to allow a hack like this to work, or it is just an unintended accident that it happens to work. Dscho, any ideas?
Quoted 11 lines · Junio C Hamano
Although I am not so familiar with this area, the patch somehow did not feel right, so I ended up doing a bit of digging.
After the context of the patch, we have this:
if (tracking.matches == 1) { sprintf(key, "branch.%s.remote", new_ref); git_config_set(key, tracking.remote ? tracking.remote : "."); sprintf(key, "branch.%s.merge", new_ref); git_config_set(key, tracking.src);
Quoted 4 lines
So it looks to me that the code already has intention to set the "branch.*.remote" variable to "." when certain condition is met. And the condition is "when tracking.remote is NULL, or it is already a dot".
I was confused by the use of the ternary operator. I couldn't figure out how tracking.remote could be NULL. I chalked it up to bit-rot but them forget to mention that in my email. I'm glad you took another look, but I still don't understand how tracking.remote can be NULL and tracking.matches == 1.
Quoted 5 lines
So if there is a remote whose name is "." (or NULL, but I do not know when that can happen ---
remote.c::make_remote()does not allow creating such a remote as far as I can tell), that would be found without the added extra code, wouldn't it?
Quoted 8 lines
I did a bit of experiment and with this in .git/config:
[remote "."] fetch = refs/*:refs/*it turns out that you do not have to patch the code at all. The above manual configuration feels somewhat like an ugly hack but perhaps we should make the above two lines implied?
Hmm, that just causes tracking.remote to be set to ".", not to NULL? Right?
j.
Hi,
Quoted 4 lines · Junio C Hamano
This area was last cleaned up in 6f084a5 (branch --track: code cleanup and saner handling of local branches). I do not know if the original intention of the code was to allow a hack like this to work, or it is just an unintended accident that it happens to work. Dscho, any ideas?
AFAIR the problem was that you were (rightfully) annoyed when you were setting up your local branches, and all of a sudden, they were set up with loads of tracking information, cluttering your config.
Basically, that is the reason why we disallowed tracking information to be set up for local branching.
Ciao,
Dscho
Quoted 6 lines · Johannes Schindelin
AFAIR the problem was that you were (rightfully) annoyed when you were setting up your local branches, and all of a sudden, they were set up with loads of tracking information, cluttering your config.
Basically, that is the reason why we disallowed tracking information to be set up for local branching.
Hrmm, I was annoyed that when setting up my local branches, they *don't* get tracking information. Otherwise I can't use "git pull" with them, which I'd like to. So maybe something like:
* Using --track or --notrack adds (or doesn't) the information, because well, I specified it explicitly.
* Otherwise (if neither --track nor --notrack) is specified, check the setting of branch.autosetupmerge. Currently it's a boolean, but perhaps it can take on a new setting and have:
- false
- true
- always ; new setting which means to setup tracking information for ; both local and remote branches
?
j.
PATCH 1/1 branch: optionally setup branch.*.merge from upstream local branches
In reply to Jay Soffiangit branch / git checkout -b now honor --track when the upstream branch is local. Previously --track was silently ignored for local upstream branches.
The configuration setting branch.autosetupmerge can now be set to "always" which is equivalent to using --track. Setting branch.autosetupmerge to boolean true will retains the former behavior of only setting up branch.*.merge for remote upstream branches.
Includes test cases for the new functionality.
---
Changes from last iteration:
- Reworked the documentation. I incorporated some of Junio's suggestions, but I made a lot of other clarifications (IMO...). Let me know what you think.
- Added a suggested test case to t7201-co and some of my own to t3200-branch.
- Renamed the enum values per Junio.
- Incorporated suggestions from Junio and Johannes re:setup_tracking().
- The code/doc/and test case changes are now all in this commit together (I don't think it's too much for review...?)
Thanks for the feedback so far.
Documentation/config.txt | 15 ++++++--- Documentation/git-branch.txt | 69 +++++++++++++++++----------------------- Documentation/git-checkout.txt | 61 ++++++++++++++++++----------------- branch.c | 20 +++++++---- branch.h | 2 +- builtin-branch.c | 14 +++----- builtin-checkout.c | 13 ++----- cache.h | 8 +++++ config.c | 8 +++++ environment.c | 1 + t/t3200-branch.sh | 32 ++++++++++++++++-- t/t7201-co.sh | 8 +++++ 12 files changed, 147 insertions(+), 104 deletions(-)
Documentation/config.txt +10 -5
@@ -378,11 +378,16 @@ apply.whitespace:: as the '--whitespace' option. See linkgit:git-apply[1]. branch.autosetupmerge:: - Tells `git-branch` and `git-checkout` to setup new branches - so that linkgit:git-pull[1] will appropriately merge from that - remote branch. Note that even if this option is not set, - this behavior can be chosen per-branch using the `--track` - and `--no-track` options. This option defaults to true. + When setting up new branch <name> from existing branch + <starting-point>, tells linkgit:git-branch[1] and + linkgit:git-checkout[1] to configure branch.<name>.remote and + branch.<name>.merge for use with linkgit:git-fetch[1] and + linkgit:git-pull[1]. There are three valid settings: `false` -- no + automatic setup; `true` -- automatic setup when <starting-poiint> is + a remote branch; `always` -- automatic setup when <starting-point> + is either a local or remote branch. The `--track` and `--no-track` + options to linkgit:git-branch[1] and linkgit:git-checkout[1] always + override this setting. The default is `true`. branch.<name>.remote:: When in branch <name>, it tells `git fetch` which remote to fetch.
Documentation/git-branch.txt +29 -40
112 lines not on this page · raw message
Documentation/git-checkout.txt +32 -29
93 lines not on this page · raw message
branch.c +13 -7
@@ -37,7 +37,8 @@ static int find_tracked_branch(struct remote *remote, void *priv)* to infer the settings for branch.<new_ref>.{remote,merge} from the * config. */ -static int setup_tracking (const char *new_ref,const char *orig_ref) +static int setup_tracking (const char *new_ref,const char *orig_ref, +enum branch_track track) {char key[1024 ];struct tracking tracking;
@@ -48,10 +49,14 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)memset (&tracking,0 ,sizeof (tracking)); tracking.spec.dst = (char *)orig_ref; -if (for_each_remote (find_tracked_branch, &tracking) || - !tracking.matches) +if (for_each_remote (find_tracked_branch, &tracking))return 1 ; +if (!tracking.matches && track ==BRANCH_TRACK_ALWAYS ) { + tracking.matches =1 ; + tracking.src =xstrdup (orig_ref); + } +if (tracking.matches >1 )return error ("Not tracking: ambiguous information for ref %s" , orig_ref);
@@ -62,8 +67,9 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)sprintf (key,"branch.%s.merge" , new_ref);git_config_set (key, tracking.src);free (tracking.src); -printf ("Branch %s set up to track remote branch %s.\n" , - new_ref, orig_ref); +printf ("Branch %s set up to track %s branch %s.\n" , + new_ref, tracking.remote ?"remote" :"local" , + orig_ref); }return 0 ;
@@ -71,7 +77,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)void create_branch (const char *head,const char *name,const char *start_name, -int force,int reflog,int track) +int force,int reflog,enum branch_track track) {struct ref_lock *lock;struct commit *commit;
@@ -130,7 +136,7 @@ void create_branch(const char *head,automatically merges from there. So far, this is only done for remotes registered via .git/config. */ if (real_ref && track) -setup_tracking (name, real_ref); +setup_tracking (name, real_ref, track);if (write_ref_sha1 (lock, sha1, msg) <0 )die ("Failed to write ref: %s." ,strerror (errno));
branch.h +1 -1
@@ -13,7 +13,7 @@* branch for (if any). */ void create_branch (const char *head,const char *name,const char *start_name, -int force,int reflog,int track); +int force,int reflog,enum branch_track track);/* * Remove information about the state of working on the current
builtin-branch.c +5 -9
@@ -30,8 +30,6 @@ static const char * const builtin_branch_usage[] = {static const char *head;static unsigned char head_sha1[20 ]; -static int branch_track =1 ; -static int branch_use_color =-1 ;static char branch_colors[][COLOR_MAXLEN ] = {"\033[m" ,/* reset */
@@ -76,10 +74,6 @@ 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 =git_config_bool (var, value); -return 0 ; - }return git_color_default_config (var, value); }
@@ -420,14 +414,16 @@ int cmd_branch(int argc, const char **argv, const char *prefix) {int delete =0 , rename =0 , force_create =0 ;int verbose =0 , abbrev =DEFAULT_ABBREV , detached =0 ; -int reflog =0 , track; +int reflog =0 ; +enum branch_track track;int kinds =REF_LOCAL_BRANCH ;struct commit_list *with_commit =NULL ;struct option options[] = {OPT_GROUP ("Generic options" ),OPT__VERBOSE (&verbose), -OPT_BOOLEAN (0 ,"track" , &track,"set up tracking mode (see git-pull(1))" ), +OPT_SET_INT (0 ,"track" , &track,"set up tracking mode (see git-pull(1))" , +BRANCH_TRACK_ALWAYS ),OPT_BOOLEAN (0 ,"color" , &branch_use_color,"use colored output" ),OPT_SET_INT ('r' ,NULL , &kinds,"act on remote-tracking branches" ,REF_REMOTE_BRANCH ),
@@ -458,7 +454,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)if (branch_use_color ==-1 ) branch_use_color = git_use_color_default; - track = branch_track; + track = git_branch_track; argc =parse_options (argc, argv, options, builtin_branch_usage,0 );if (!!delete + !!rename + !!force_create >1 )usage_with_options (builtin_branch_usage, options);
builtin-checkout.c +4 -9
@@ -186,7 +186,7 @@ struct checkout_opts {char *new_branch;int new_branch_log; -int track; +enum branch_track track; };struct branch_info {
@@ -521,13 +521,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); }
@@ -542,7 +537,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)OPT__QUIET (&opts.quiet),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" ,BRANCH_TRACK_ALWAYS ),OPT_BOOLEAN ('f' ,NULL , &opts.force,"force" ),OPT_BOOLEAN ('m' ,NULL , &opts.merge,"merge" ), OPT_END(),
@@ -553,7 +548,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)git_config (git_checkout_config); - opts.track = branch_track; + opts.track = git_branch_track; argc =parse_options (argc, argv, options, checkout_usage,0 );if (argc) {
@@ -582,7 +577,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) argc--; } -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)
cache.h +8 -0
@@ -393,6 +393,14 @@ enum safe_crlf {extern enum safe_crlf safe_crlf; +enum branch_track { +BRANCH_TRACK_NEVER =0 , +BRANCH_TRACK_REMOTE , +BRANCH_TRACK_ALWAYS , +}; + +extern enum branch_track git_branch_track; +#define GIT_REPO_VERSION 0extern int repository_format_version;extern int check_repository_format (void );
config.c +8 -0
@@ -464,6 +464,14 @@ int git_default_config(const char *var, const char *value) whitespace_rule_cfg =parse_whitespace_rule (value);return 0 ; } +if (!strcmp (var,"branch.autosetupmerge" )) { +if (value && !strcasecmp (value,"always" )) { + git_branch_track =BRANCH_TRACK_ALWAYS ; +return 0 ; + } + git_branch_track =git_config_bool (var, value); +return 0 ; + }/* Add other config variables here and to Documentation/config.txt. */ return 0 ;
environment.c +1 -0
@@ -37,6 +37,7 @@ const char *excludes_file;int auto_crlf =0 ;/* 1: both ways, -1: only when adding git objects */ enum safe_crlf safe_crlf =SAFE_CRLF_WARN ;unsigned whitespace_rule_cfg =WS_DEFAULT_RULE ; +enum branch_track git_branch_track =BRANCH_TRACK_REMOTE ;/* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg;
t/t3200-branch.sh +28 -4
@@ -15,6 +15,9 @@ test_expect_success \ 'echo Hello > A && git update-index --add A && git-commit -m "Initial commit." && + echo World >> A && + git update-index --add A && + git-commit -m "Second commit." && HEAD=$(git rev-parse --verify HEAD)' test_expect_success \
@@ -161,7 +164,7 @@ test_expect_success 'avoid ambiguous track' ' ' test_expect_success 'test overriding tracking setup via --no-track' \ - 'git config branch.autosetupmerge true && + 'git config branch.autosetupmerge always && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/master || git-fetch local) &&
@@ -171,7 +174,9 @@ test_expect_success 'test overriding tracking setup via --no-track' \ ! test "$(git config branch.my2.merge)" = refs/heads/master' test_expect_success 'no tracking without .fetch entries' \ - 'git branch --track my6 s && + 'git config branch.autosetupmerge true && + git branch my6 s && + git config branch.automsetupmerge false && test -z "$(git config branch.my6.remote)" && test -z "$(git config branch.my6.merge)"'
@@ -192,14 +197,33 @@ test_expect_success 'test deleting branch without config' \ 'git branch my7 s && test "$(git branch -d my7 2>&1)" = "Deleted branch my7."' -# Keep this test last, as it changes the current branch +test_expect_success 'test tracking without .fetch entries w/--track given' \ + 'git branch --track my8 && + test "$(git config branch.my8.remote)" && + test "$(git config branch.my8.merge)"' + +test_expect_success \ + 'no tracking entries from non-branch HEAD even w/autosetupmerge=always)' \ + 'git config branch.autosetupmerge always && + git branch my9 HEAD^ && + git config branch.autosetupmerge false && + test -z "$(git config branch.my9.remote)" && + test -z "$(git config branch.my9.merge)"' + +test_expect_success \ + 'no tracking entries from non-branch HEAD even w/--track' \ + 'git branch --track my10 HEAD^ && + test -z "$(git config branch.my10.remote)" && + test -z "$(git config branch.my10.merge)"' + +# Keep this test last, as they change the current branch cat >expect <<EOF 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master EOF test_expect_success \ 'git checkout -b g/h/i -l should create a branch and a log' \ 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ - git-checkout -b g/h/i -l master && + git checkout -b g/h/i -l master && test -f .git/refs/heads/g/h/i && test -f .git/logs/refs/heads/g/h/i && diff expect .git/logs/refs/heads/g/h/i'
t/t7201-co.sh +8 -0
@@ -279,4 +279,12 @@ test_expect_success 'checkout with ambiguous tag/branch names' ' ' +test_expect_success \ + 'checkout w/--track sets up tracking w/autosetupmerge=false' ' + git config branch.autosetupmerge false && + git checkout -f master && git clean -f && + git checkout --track -b track && + test "$(git config branch.track.remote)" && + test "$(git config branch.track.merge)"' + test_done
Signature · 1 line
1.5.4.2.203.gf8d86
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Jay Soffian, Tue, Feb 19, 2008 03:07:12 +0100:
cache.h enum safe_crlf { · line 397
Quoted 10 lines
cache.h +2
-0@@ -393,6 +393,14 @@ enum safe_crlf {extern enum safe_crlf safe_crlf; +enum branch_track { +BRANCH_TRACK_NEVER =0 ,
enums start at 0 anyway, don't they?
Quoted 3 lines
cache.h +3
-0+BRANCH_TRACK_REMOTE , + BRANCH_TRACK_ALWAYS, +};
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Quoted 5 lines · Alex Riesen
Jay Soffian, Tue, Feb 19, 2008 03:07:12 +0100:
cache.h enum safe_crlf { · line 397
Quoted 2 lines
cache.h +2
-0+enum branch_track { +BRANCH_TRACK_NEVER =0 ,enums start at 0 anyway, don't they?
I don't know, but guys, give me a break on the enums already. What's the preferred syntax already because the existing code is not consistent:
enum color_branch {
COLOR_BRANCH_RESET = 0,
COLOR_BRANCH_PLAIN = 1,
COLOR_BRANCH_REMOTE = 2,
COLOR_BRANCH_LOCAL = 3,
COLOR_BRANCH_CURRENT = 4,
};
enum {
TAGS_UNSET = 0,
TAGS_DEFAULT = 1,
TAGS_SET = 2
};
enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
enum exist_status {
index_nonexistent = 0,
index_directory,
index_gitdir,
};
enum CAPABILITY {
NOLOGIN = 0,
UIDPLUS,
LITERALPLUS,
NAMESPACE,
};
j.
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Jay Soffian, Tue, Feb 19, 2008 14:49:17 +0100:
Quoted 10 lines · Alex Riesen
Quoted 5 lines
Jay Soffian, Tue, Feb 19, 2008 03:07:12 +0100:
cache.h enum safe_crlf { · line 397
Quoted 2 lines
cache.h +2
-0+enum branch_track { +BRANCH_TRACK_NEVER =0 ,enums start at 0 anyway, don't they?
I don't know, but guys, give me a break on the enums already. What's the preferred syntax already because the existing code is not consistent:
Well, it could also mean that there is no rules yet, and you can do the next sane thing of your choice.
Quoted 8 lines
enum
color_branch{
COLOR_BRANCH_RESET= 0,
COLOR_BRANCH_PLAIN= 1,
COLOR_BRANCH_REMOTE= 2,
COLOR_BRANCH_LOCAL= 3,
COLOR_BRANCH_CURRENT= 4,
};
Quoted 5 lines
enum {
TAGS_UNSET= 0,
TAGS_DEFAULT= 1,
TAGS_SET= 2
};
Which is just as useless. It is not useful even for documentation, as the verbatim values are not used anywere else (i.e. they are not a part of file format, where they could stand out as the numbers listed).
It looks like someone was just too paranoid or suffered a mental damage from too long exposure to proprietary code.
Quoted 8 lines
enum
update_mode{ BOTH = 0,WORKING_DIRECTORY, INDEX } *modes;enum
exist_status{
index_nonexistent= 0,
index_directory,
index_gitdir,
};
Quoted 6 lines
enum CAPABILITY {
NOLOGIN = 0,
UIDPLUS,
LITERALPLUS,
NAMESPACE,
};
All the same...
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Quoted 10 lines · Alex Riesen
Well, it could also mean that there is no rules yet, and you can do the next sane thing of your choice.
Quoted 7 lines
enum
color_branch{
COLOR_BRANCH_RESET= 0,
COLOR_BRANCH_PLAIN= 1,
COLOR_BRANCH_REMOTE= 2,
COLOR_BRANCH_LOCAL= 3,
COLOR_BRANCH_CURRENT= 4,
};
This enum is used as an index into branch_colors[] array. Of course, by omitting everything you will get the default "start with 0, incrementing by 1" which will be the right assignment anyway. But we would want to leave a clue for people who would want to touch this later that individual values have some meaning, more than just that they have to be distinct.
Quoted 5 lines
Quoted 5 lines
enum {
TAGS_UNSET= 0,
TAGS_DEFAULT= 1,
TAGS_SET= 2
};
This one can be made unspecified or even shuffled, because nobody does:
int function_that_acts_on_tag_setting(int tag) {
if (!tag) {
... do something ...
}
if (TAGS_DEFAULT <= tag) {
... do something else ...
}
return some_array[tag];
}So there is no reason to spell out any of the values.
Quoted 1 line
Quoted 1 line
enum
update_mode{ BOTH = 0,WORKING_DIRECTORY, INDEX } *modes;
Likewise.
Quoted 5 lines
Quoted 5 lines
enum
exist_status{
index_nonexistent= 0,
index_directory,
index_gitdir,
};
Likewise, modulo that making "nonexistent" explicitly to 0 is a very sensible thing whoever wrote that code has done. This is used as a type of directory_exists_in_index() function, and callers can say:
if (!directory_exists_in_index(dirname)) {
... ah, there is no such directory ...
} else {
... something exists, but I do not care what kind ...
}So spelling out that "nonexistent MUST BE 0" (even though C language will give value 0 to it anyway) is a good convention.
Quoted 6 lines
Quoted 6 lines
enum CAPABILITY {
NOLOGIN = 0,
UIDPLUS,
LITERALPLUS,
NAMESPACE,
};
This seems to be meant to match the order in the corresponding cap_list[] array, so this cannot be reshuffled (iow, it is similar to color_branch).
If you do not need to have any specific value assigned nor order among the enum tokens, (i.e. somebody later can add a new enum anywhere in the decl or even reshuffle the existing ones without breaking your code), it is a good idea to hint that fact by not having any "= value" in the decl. If you do rely on specific one being zero (see "exist_status" example above), it is better to spell it out that it has to be zero even if it is the first entry to hint that fact. Of course, if you need a set of values that are not sequential, you would need to spell out each and every one of them.
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Quoted 25 lines · Junio C Hamano
Quoted 10 lines · Alex Riesen
Well, it could also mean that there is no rules yet, and you can do the next sane thing of your choice.
Quoted 7 lines
enum
color_branch{
COLOR_BRANCH_RESET= 0,
COLOR_BRANCH_PLAIN= 1,
COLOR_BRANCH_REMOTE= 2,
COLOR_BRANCH_LOCAL= 3,
COLOR_BRANCH_CURRENT= 4,
};This enum is used as an index into branch_colors[] array. ... ... But we would want to leave a clue for people who would want to touch this later that individual values have some meaning, more than just that they have to be distinct.
...Quoted 6 lines
Quoted 6 lines
enum CAPABILITY {
NOLOGIN = 0,
UIDPLUS,
LITERALPLUS,
NAMESPACE,
};
Quoted 3 lines
This seems to be meant to match the order in the corresponding cap_list[] array, so this cannot be reshuffled (iow, it is similar to
color_branch).
Side note. My preference for enum that indexes an array is to use the latter, not spelling everything out like "color_branch" does. The first one being 0 and everybody else increments by 1 is a good enough clue that you cannot arbitrarily reshuffle them (as opposed to everbody left to the default). After being warned with the clue, somebody who is adding new elements to the array and defining a symbolic index to the element will know to append to the list, not just insert into an arbitrary place. Spelling out all the rest explicitly like "color_branch" one does is wasteful (new entries would need to carry "= (n+1)"), pointless (you cannot write anything but "= (n+1)" because it is an array index), and misleading (it makes you wonder if the specific values have meaning other than being used for an array index).
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
In reply to Jay SoffianHi,
Quoted 8 lines · Jay Soffian
Quoted 5 lines · Alex Riesen
Jay Soffian, Tue, Feb 19, 2008 03:07:12 +0100:
cache.h enum safe_crlf { · line 397
Quoted 2 lines
cache.h +2
-0+enum branch_track { +BRANCH_TRACK_NEVER =0 ,enums start at 0 anyway, don't they?
I don't know, but guys, give me a break on the enums already.
Heh.
Don't be discouraged. I think you help educating me here, too:
Quoted 2 lines
What's the preferred syntax already because the existing code is not
consistent: [...]
I had the impression that the first was set to "= 0", and the rest was not explicitely set. But I was obviously wrong.
Ciao,
Dscho
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
In reply to Jay SoffianQuoted 18 lines · Jay Soffian
branch.c +2
-1@@ -37,7 +37,8 @@ static int find_tracked_branch(struct remote *remote, void *priv)* to infer the settings for branch.<new_ref>.{remote,merge} from the * config. */ -static int setup_tracking (const char *new_ref,const char *orig_ref) +static int setup_tracking (const char *new_ref,const char *orig_ref, +enum branch_track track) {char key[1024 ];struct tracking tracking;@@ -48,10 +49,14 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)memset (&tracking,0 ,sizeof (tracking)); tracking.spec.dst = (char *)orig_ref;
branch.c static int setup_tracking(const char *new_ref, const char *orig_ref) · line 59
Quoted 10 lines
branch.c +6
-2-if (for_each_remote (find_tracked_branch, &tracking) || - !tracking.matches) +if (for_each_remote (find_tracked_branch, &tracking))return 1 ; +if (!tracking.matches && track ==BRANCH_TRACK_ALWAYS ) { + tracking.matches =1 ; + tracking.src =xstrdup (orig_ref); + } +
Well that's obviously wrong (though it causes no problems, setup_tracking() would return 0 when it should return 1, but its return value is currently ignored). I changed it to:
if (!tracking.matches) {
if (track != BRANCH_TRACK_ALWAYS)
return 1;
tracking.matches = 1;
tracking.src = xstrdup(orig_ref);
}j.
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Hi,
Quoted 34 lines · Jay Soffian
Quoted 18 lines · Jay Soffian
branch.c +2
-1@@ -37,7 +37,8 @@ static int find_tracked_branch(struct remote *remote, void *priv)* to infer the settings for branch.<new_ref>.{remote,merge} from the * config. */ -static int setup_tracking (const char *new_ref,const char *orig_ref) +static int setup_tracking (const char *new_ref,const char *orig_ref, +enum branch_track track) {char key[1024 ];struct tracking tracking;@@ -48,10 +49,14 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)memset (&tracking,0 ,sizeof (tracking)); tracking.spec.dst = (char *)orig_ref;branch.c static int setup_tracking(const char *new_ref, const char *orig_ref) · line 59
Quoted 10 lines
branch.c +6
-2-if (for_each_remote (find_tracked_branch, &tracking) || - !tracking.matches) +if (for_each_remote (find_tracked_branch, &tracking))return 1 ; +if (!tracking.matches && track ==BRANCH_TRACK_ALWAYS ) { + tracking.matches =1 ; + tracking.src =xstrdup (orig_ref); + } +Well that's obviously wrong (though it causes no problems,
setup_tracking()would return 0 when it should return 1, but its return value is currently ignored). I changed it to:
Quoted 6 lines
if (!tracking.matches) {
if (track != BRANCH_TRACK_ALWAYS)
return 1;
tracking.matches = 1;
tracking.src = xstrdup(orig_ref);
}Ah, yes. But I still maintain that xstrdup()ing orig_ref only to free it later is ugly. Why not have the "tracking.src ? tracking.src : orig_ref" as I suggested? The free() obviously can stay, since it will say "free(NULL)" in the case of tracking.matches == 0.
Ciao,
Dscho
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Quoted 11 lines · Johannes Schindelin
Quoted 7 lines · Jay Soffian
if (!tracking.matches) { if (track != BRANCH_TRACK_ALWAYS) return 1; tracking.matches = 1; tracking.src = xstrdup(orig_ref); }
Quoted 3 lines
Ah, yes. But I still maintain that xstrdup()ing
orig_refonly to free it later is ugly. Why not have the "tracking.src ? tracking.src :orig_ref" as I suggested?
Sorry, I'd missed that. Good idea, will do.
j.
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
In reply to Johannes SchindelinQuoted 5 lines · Johannes Schindelin
Ah, yes. But I still maintain that xstrdup()ing
orig_refonly to free it later is ugly. Why not have the "tracking.src ? tracking.src :orig_ref" as I suggested? Thefree()obviously can stay, since it will say "free(NULL)" in the case of tracking.matches == 0.
How about this?
static int setup_tracking(const char *new_ref, const char *orig_ref,
enum branch_track track)
{
char key[1024];
struct tracking tracking;
if (strlen(new_ref) > 1024 - 7 - 7 - 1)
return error("Tracking not set up: name too long: %s",
new_ref);
memset(&tracking, 0, sizeof(tracking));
tracking.spec.dst = (char *)orig_ref;
if (for_each_remote(find_tracked_branch, &tracking))
return 1;
if (!tracking.matches && track != BRANCH_TRACK_ALWAYS)
return 1;
if (tracking.matches > 1)
return error("Not tracking: ambiguous information for ref %s",
orig_ref);
sprintf(key, "branch.%s.remote", new_ref);
git_config_set(key, tracking.remote ? tracking.remote : ".");
sprintf(key, "branch.%s.merge", new_ref);
git_config_set(key, tracking.src ? tracking.src : orig_ref);
free(tracking.src);
printf("Branch %s set up to track %s branch %s.\n", new_ref,
tracking.remote ? "remote" : "local", orig_ref);
return 0;
}j.
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Hi,
Quoted 33 lines · Jay Soffian
Quoted 5 lines · Johannes Schindelin
Ah, yes. But I still maintain that xstrdup()ing
orig_refonly to free it later is ugly. Why not have the "tracking.src ? tracking.src :orig_ref" as I suggested? Thefree()obviously can stay, since it will say "free(NULL)" in the case of tracking.matches == 0.How about this?
static int setup_tracking(const char
*new_ref, const char*orig_ref,
enumbranch_tracktrack){ char key[1024]; struct tracking tracking; if (strlen(new_ref) > 1024 - 7 - 7 - 1) return error("Tracking not set up: name too long: %s", new_ref); memset(&tracking, 0, sizeof(tracking)); tracking.spec.dst = (char *)orig_ref; if (for_each_remote(find_tracked_branch, &tracking)) return 1; if (!tracking.matches && track != BRANCH_TRACK_ALWAYS) return 1; if (tracking.matches > 1) return error("Not tracking: ambiguous information for ref %s", orig_ref); sprintf(key, "branch.%s.remote", new_ref); git_config_set(key, tracking.remote ? tracking.remote : ".");
Quoted 8 lines
sprintf(key, "branch.%s.merge", new_ref);
git_config_set(key, tracking.src ? tracking.src : orig_ref);
free(tracking.src);
printf("Branch %s set up to track %s branch %s.\n", new_ref,
tracking.remote ? "remote" : "local", orig_ref);
return 0;
}I like it.
Ciao,
Dscho
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
In reply to Jay SoffianQuoted 9 lines · Jay Soffian
Documentation/config.txt +0
-0@@ -378,11 +378,16 @@ apply.whitespace:: as the '--whitespace' option. See linkgit:git-apply[1]. branch.autosetupmerge::
Documentation/config.txt apply.whitespace:: · line 390
Quoted 10 lines
Documentation/config.txt +10
-0+ When setting up new branch <name> from existing branch + <starting-point>, tells linkgit:git-branch[1] and + linkgit:git-checkout[1] to configure branch.<name>.remote and + branch.<name>.merge for use with linkgit:git-fetch[1] and + linkgit:git-pull[1]. There are three valid settings: `false` -- no + automatic setup; `true` -- automatic setup when <starting-poiint> is + a remote branch; `always` -- automatic setup when <starting-point> + is either a local or remote branch. The `--track` and `--no-track` + options to linkgit:git-branch[1] and linkgit:git-checkout[1] always + override this setting. The default is `true`.
Three issues.
(1) "tells X and Y to configure" is bad. We may later want to add a command that forks a new branch from an existing one, and you sure do want it to honor this variable. Better not list the commands but tell the reader that it applies to the act of forking a new branch based on an existing one.
(2) "configure X and Y" is bad. We may later want to add new configuration variables to facilitate marking a branch that builds on top of another in addition to the existing remote and merge, and you sure do want them to be also set up appropriately.
(3) "for use with X and Y" is bad. We may later want to add new commands that you would use to work with a branch that builds on top of another, and you sure do want them to honor the configuration variables this automatically sets up.
So, how about...
When creating a new branch starting at an existing 'upstream' branch, the new branch can be marked as building on top of the 'upstream' branch, by setting a few configuration variables (e.g. branch.<name>.remote and branch.<name>.merge). This can be explicitly asked for by giving --track (and turned off by giving --no-track) option to commands that create a new branch (e.g. linkgit:git-branch[1]); this variable is consulted when neither option is given.
+
When set to true, act as if --track is given only if 'upstream' is a remote tracking branch. When set to always, act as if --track is given even if 'upstream' is a local branch. When set to false, no such extra configuration is made. Defaults to true.
Quoted 5 lines
Documentation/git-branch.txt +0
-0
Documentation/git-branch.txt SYNOPSIS · line 16
Quoted 9 lines
Documentation/git-branch.txt +3
-3@@ -11,9 +11,9 @@ SYNOPSIS 'git-branch' [--color | --no-color] [-r | -a] [-v [--abbrev=<length> | --no-abbrev]] [--contains <commit>] -'git-branch' [--track | --no-track] [-l] [-f] <branchname> [<start-point>] -'git-branch' (-m | -M) [<oldbranch>] <newbranch> -'git-branch' (-d | -D) [-r] <branchname>... +'git-branch' [--track | --no-track] [-l] [-f] <newbranch> [<start-point>] +'git-branch' (-m | -M) [<branch>] <newbranch> +'git-branch' (-d | -D) [-r] <branch>...
Looks more-or-less unnecessary churn to me. If you have to rename the placeholders, I would say:
git branch <branch> [<start-point>]
git branch -m [<old>] <new>
git branch -d <branch>
would be short, sweet and sufficient.
Quoted 6 lines
Documentation/git-branch.txt +0
-0DESCRIPTION -----------@@ -25,29 +25,25 @@ With `--contains <commit>`, shows only the branches that contains the named commit (in other words, the branches whose tip commits are descendant of the named commit).
Documentation/git-branch.txt With `--contains <commit>`, shows only the branches that · line 33
Quoted 10 lines
Documentation/git-branch.txt +6
-4-In its second form, a new branch named <branchname> will be created. -It will start out with a head equal to the one given as <start-point>. -If no <start-point> is given, the branch will be created with a head -equal to that of the currently checked out branch. +In its second form, a new branch named <newbranch> will be created. +It will start out with a head equal to <start-point>. If no +<start-point> is given, it is assumed to be the currently checked +out branch. The new branch may optionally be configured for use with +linkgit:git-pull[1] -- see `--track` and `--no-track` in the OPTIONS +section below.
Drop all the changes except for the last sentence.
Documentation/git-branch.txt With `--contains <commit>`, shows only the branches that · line 38
Quoted 5 lines
Documentation/git-branch.txt +2
-1Note that this will create the new branch, but it will not switch the working tree to it; use "git checkout <newbranch>" to switch to the -new branch. +new branch. (As a shortcut consider using "git checkout [--track | +--notrack ] -b <newbranch>" instead.)
Hinting an alternative is good but is too verbose.
"git checkout -b" can be used to create and switch in one step.
would be short, sweet and sufficient.
Documentation/git-branch.txt With `--contains <commit>`, shows only the branches that · line 42
Quoted 6 lines
Documentation/git-branch.txt +0
-6-When a local branch is started off a remote branch, git sets up the -branch so that linkgit:git-pull[1] will appropriately merge from that -remote branch. If this behavior is not desired, it is possible to -disable it using the global `branch.autosetupmerge` configuration -flag. That setting can be overridden by using the `--track` -and `--no-track` options.
Why remove this?
Quoted 4 lines
Documentation/git-branch.txt +0
-0@@ -105,38 +101,31 @@ OPTIONS Display the full sha1s in output listing rather than abbreviating them. --track::
Documentation/git-branch.txt OPTIONS · line 105
Quoted 10 lines
Documentation/git-branch.txt +2
-8- Set up configuration so that git-pull will automatically - retrieve data from the remote branch. Use this if you always - pull from the same remote branch into the new branch, or if you - don't want to use "git pull <repository> <refspec>" explicitly. - This behavior is the default. Set the - branch.autosetupmerge configuration variable to false if you - want git-checkout and git-branch to always behave as if - '--no-track' were given. + Set up the new branch's configuration so that linkgit:git-pull[1] + will appropriately merge from the start point when run without
"from the start point" is misleading.
Documentation/git-branch.txt OPTIONS · line 109
Quoted 4 lines
Documentation/git-branch.txt +4
-0+ arguments while in the new branch. `--track` is the default behavior + when the start point is a remote branch. See the documentation for + the `branch.autosetupmerge` configuration variable in + linkgit:git-config[1] for how to modify the default.
How about
When <start-point> is a name of an existing branch (either local or remote tracking branch), treat the <start-point> branch as the upstream branch for the new branch (i.e. the new branch is marked to build on top of the branch) by setting a few extra configuration variables to cause "git pull" without repository and refspec parameters to fetch and merge (or rebase) from the upstream branch. By default, this happens when forking from a remote tracking branch without this option. This default can be modified by the branch.autosetupmerge configuration variable.
By the way, I think the existing code is buggy. When you say:
$ git branch --track new $(git rev-parse --verify HEAD~12)
the command should barf, saying "Starting point is not a branch; it is impossible to set up a tracking information", perhaps without even creating the "new" branch. Instead, it silently creates a new branch.
Documentation/git-branch.txt OPTIONS · line 113
Quoted 3 lines
Documentation/git-branch.txt +2
-0--no-track:: + Ignore the `branch.autosetupmerge` configuration variable. The new + branch will not be setup for automatic merging.
This is much better than the original text.
Documentation/git-branch.txt OPTIONS · line 124
Quoted 6 lines
Documentation/git-branch.txt +2
-2<start-point>:: The new branch will be created with a HEAD equal to this. It may - be given as a branch name, a commit-id, or a tag. If this option - is omitted, the current branch is assumed. + be given as a branch name, a commit-id, or a tag. Defaults + to the current HEAD.
I do not think this is what _you_ want (although I do not personally care). Defaulting to HEAD means <start-point> is not a name of the branch in such a case. I suspect that you would want this to create a new branch that follows your current branch (assuming your HEAD is not detached):
$ git branch --track new
wouldn't you?
Quoted 15 lines
Documentation/git-checkout.txt +2
-1@@ -8,25 +8,27 @@ git-checkout - Checkout and switch to a branch SYNOPSIS -------- [verse] -'git-checkout' [-q] [-f] [[--track | --no-track] -b <new_branch> [-l]] [-m] [<branch>] +'git-checkout' [-q] [-f] [-m] <branch> +'git-checkout' [-q] [-f] [-m] [-l] [--track | --no-track] -b <newbranch> [<start-point>] 'git-checkout' [<tree-ish>] <paths>... DESCRIPTION -----------
Documentation/git-checkout.txt git-checkout - Checkout and switch to a branch · line 20
Quoted 10 lines
Documentation/git-checkout.txt +3
-6-When <paths> are not given, this command switches branches by -updating the index and working tree to reflect the specified -branch, <branch>, and updating HEAD to be <branch> or, if -specified, <new_branch>. Using -b will cause <new_branch> to -be created; in this case you can use the --track or --no-track -options, which will be passed to `git branch`. +It its first form this command switches branches by updating the +index and working tree to reflect <branch> and updating HEAD to +<branch>.
Now this is getting tiresome. The rewrite might be a good change for readability but this does not have anything to do with --track. The review process of such a rewrite should be done as an independent topic.
I give up (for now).
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
Quoted 22 lines · Junio C Hamano
Three issues.
(1) "tells X and Y to configure" is bad. We may later want to add a command that forks a new branch from an existing one, and you sure do want it to honor this variable. Better not list the commands but tell the reader that it applies to the act of forking a new branch based on an existing one.
(2) "configure X and Y" is bad. We may later want to add new configuration variables to facilitate marking a branch that builds on top of another in addition to the existing remote and merge, and you sure do want them to be also set up appropriately.
(3) "for use with X and Y" is bad. We may later want to add new commands that you would use to work with a branch that builds on top of another, and you sure do want them to honor the configuration variables this automatically sets up.
So, how about...
Quoted 8 lines
When creating a new branch starting at an existing 'upstream' branch, the new branch can be marked as building on top of the 'upstream' branch, by setting a few configuration variables (e.g. branch.<name>.remote and branch.<name>.merge). This can be explicitly asked for by giving
--track(and turned off by giving--no-track) option to commands that create a new branch (e.g. linkgit:git-branch[1]); this variable is consulted when neither option is given.
I disagree. I think explicit is better than implicit and if a new command or config variable is added, then the docs should be similarly updated.
Quoted 1 line
Looks more-or-less unnecessary churn to me.
I was trying to make git-branch(1) and git-checkout(1) consistent.
Quoted 8 lines
Documentation/git-branch.txt With `--contains <commit>`, shows only the branches that · line 42
Quoted 6 lines
Documentation/git-branch.txt +0
-6-When a local branch is started off a remote branch, git sets up the -branch so that linkgit:git-pull[1] will appropriately merge from that -remote branch. If this behavior is not desired, it is possible to -disable it using the global `branch.autosetupmerge` configuration -flag. That setting can be overridden by using the `--track` -and `--no-track` options.Why remove this?
Because --track and --no-track are documented in the OPTIONS section, so there is no reason to document them up top as well. None of the other options [-l], [-q], [-f] are documented in the intro.
Quoted 7 lines
By the way, I think the existing code is buggy. When you say:
$ git branch --track new $(git rev-parse --verify HEAD~12)the command should barf, saying "Starting point is not a branch; it is impossible to set up a tracking information", perhaps without even creating the "new" branch. Instead, it silently creates a new branch.
That's what it did before I started touching any code. Perhaps it should be a separate cleanup patch.
Quoted 10 lines
Documentation/git-branch.txt OPTIONS · line 124
Quoted 6 lines
<start-point>::
The new branch will be created with a HEAD equal to this. It mayDocumentation/git-branch.txt +2
-2- be given as a branch name, a commit-id, or a tag. If this option - is omitted, the current branch is assumed. + be given as a branch name, a commit-id, or a tag. Defaults + to the current HEAD.I do not think this is what _you_ want (although I do not personally care). Defaulting to HEAD means <start-point> is not a name of the branch in such a case.
Okay, that's a subtle difference. The existing documentation conflates (I think) "HEAD" with "current branch". I see now they are different.
Quoted 6 lines
Now this is getting tiresome. The rewrite might be a good change for readability but this does not have anything to do with --track. The review process of such a rewrite should be done as an independent topic.
I give up (for now).
<grumble>
I will rip all the documentation changes out of this patch and do them separately at a later time if at all. The current documentation has lots of areas for improvement. It's hard to touch it w/o realizing you've made a clean spot and then wanting to rewrite whole swaths. I happen to think I'm a decent technical writer (no, it's not my day job) and I thought the changes I was making, from the perspective of a new set of eyes, made things more clear. I give up on that for now.
I too find it tiresome trying to get this patch into git. As a newbie contributor, I'm beginning to find this very discouraging. I appreciate that changes need a lot of scrutiny, but if the same amount of scrutiny were applied to the existing code it would never get through.
Which is not to say that I don't appreciate your feedback and work on git. </grumble>
j.
Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches
In reply to Jay SoffianQuoted 5 lines · Jay Soffian
Documentation/config.txt +0
-0
Documentation/config.txt apply.whitespace:: · line 385
Quoted 9 lines
Documentation/config.txt +5
-0@@ -378,11 +378,14 @@ apply.whitespace:: as the '--whitespace' option. See linkgit:git-apply[1]. branch.autosetupmerge:: + Tells `git-branch` and `git-checkout` to setup `branch.*.remote` + and `branch.*.merge` for new branches so that linkgit:git-pull[1] + will appropriately merge from that upstream branch. Note that even + if this option is not set, this behavior can be chosen per-branch + using the `--track` and `--no-track` options. This option defaults
You have an unintended tab there.
Documentation/config.txt apply.whitespace:: · line 388
Quoted 3 lines
Documentation/config.txt +3
-0+ to true, which will setup tracking for remote branches. Set it to + `always` to automatically setup the aforementioned options for local + upstream branches as well.
I somehow find it easier to read if the default is always described at the end of the paragraph, i.e. "Setting this to value X does foo, Y does bar, Z does baz. Defaults to X.", but that may be just me.
Quoted 8 lines
Documentation/git-branch.txt +0
-0@@ -105,20 +105,20 @@ OPTIONS Display the full sha1s in output listing rather than abbreviating them. --track::
Documentation/git-branch.txt OPTIONS · line 116
Quoted 10 lines
Documentation/git-branch.txt +9
-0+ Set up configuration so that git-pull will + automatically retrieve data from the upstream branch. Use this if + you always pull from the same upstream branch into the new branch, + or if you don't want to use "git pull <repository> <refspec>" + explicitly. This behavior is the default for remote branches. + Set the branch.autosetupmerge configuration variable to false if you + want git-checkout and git-branch to always behave as if '--no-track' + were given. Set it to 'always' if you want git-checkout and git-branch + to always behave as if '--track' were given.
Re-wrapping the
paragraph at an unusual place. It is Ok to do so if it is done to keep the unchanged part intact to minimize the diff text, but otherwise, please don't.
You reworded "remote branch" to "upstream branch" here and other places. I think that makes the intention easier to understand. It is "the branch this new branch intends to build on top of", so the earlier text should have said "remote tracking branch" but the intention has always been to mean "on top of whom will I be building".
This is not a flaw in your patch, but I suspect "or if you don't want to" should have been "and if you don't want to".
"This behaviour is the default for remote branches" feels a bit odd. It confuses the first time reader as if you are saying "if you are creating a remote branch with "git-branch" command, this behaviour is the default", which is not what you are saying. I think "... the default when forking off of a remote tracking branch" is what you meant.
Documentation/git-branch.txt OPTIONS · line 121
Quoted 8 lines
--no-track::
Documentation/git-branch.txt +3
-4- When a branch is created off a remote branch, - set up configuration so that git-pull will not retrieve data - from the remote branch, ignoring the branch.autosetupmerge - configuration variable. + Ignore the branch.autosetupmerge configuration variable. When + using git pull with the new branch, a <refspec> will have to be + given explicitly.
This rewrite probably has made the description easier to understand.
Documentation/git-checkout.txt OPTIONS · line 51
Quoted 10 lines
Documentation/git-checkout.txt +1
-0@@ -48,21 +48,20 @@ OPTIONS may restrict the characters allowed in a branch name. --track:: + When -b is given set up configuration so that git-pull will
s/given/&,/;
Documentation/git-checkout.txt
Quoted 4 lines
Documentation/git-checkout.txt +4
-0+ automatically retrieve data from the upstream branch. Use this if + you always pull from the same upstream branch into the new branch, + or if you don't want to use "git pull <repository> <refspec>" + explicitly. This behavior is the default for remote branches.
The same comment on "or if you don't want to" applies.
Documentation/git-checkout.txt static int setup_tracking(const char *new_ref, const char *orig_ref) · line 57
Quoted 12 lines
Documentation/git-checkout.txt +6
-2@@ -49,8 +49,12 @@ static int setup_tracking(const char *new_ref, const char *orig_ref) memset(&tracking, 0, sizeof(tracking)); tracking.spec.dst = (char *)orig_ref; if (for_each_remote(find_tracked_branch, &tracking) || - !tracking.matches) - return 1; + !tracking.matches) { + if (!always) + return 1; + tracking.matches = 1; + tracking.src = xstrdup(orig_ref); + }
I suspect this is a clever fallback to pretend as if you have [remote "."] fetch=refs/*:refs/* when nothing else matches, but I think it needs an explanation why this is a good idea and would not break others. Also I suspect this should be moved after you see for-each-remote returns without error and did not find any match.
Quoted 10 lines
Documentation/git-checkout.txt +1
-1@@ -71,7 +76,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref) void create_branch(const char *head, const char *name, const char *start_name, - int force, int reflog, int track) + int force, int reflog, enum branch_track track) { struct ref_lock *lock; struct commit *commit;
Documentation/git-checkout.txt void create_branch(const char *head, · line 138
Quoted 5 lines
Documentation/git-checkout.txt +1
-1@@ -130,7 +135,7 @@ void create_branch(const char *head, automatically merges from there. So far, this is only done for remotes registered via .git/config. */ if (real_ref && track) - setup_tracking(name, real_ref); + setup_tracking(name, real_ref, (track == BRANCH_TRACK_ALWAYS));
It probably is better to pass 'track' itself and have the special case logic inside setup_tracking() instead. Maybe we would want to add new tracking mode that needs different matching logic there later.
The move to default_config() is probably a good idea.
cache.h enum safe_crlf { · line 400
Quoted 13 lines
cache.h +5
-0@@ -393,6 +393,14 @@ enum safe_crlf {extern enum safe_crlf safe_crlf; +enum branch_track { +BRANCH_TRACK_REMOTES_FALSE =0 , +BRANCH_TRACK_REMOTES_TRUE , +BRANCH_TRACK_ALWAYS , +};
Perhaps BRANCH_TRACK_{NEVER,REMOTE,ALWAYS} would be easier (although I cannot decide if s/NEVER/FALSE/ would be better)?