{"thread":{"id":"12177","subject":"[PATCH] branch: optionally setup branch.*.merge from upstream local branches","startedAt":"2008-02-18T13:53:37Z","lastAt":"2008-02-18T20:59:13Z","messageCount":5,"participants":["Jay Soffian","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"69146","messageId":"1203342817-19653-1-git-send-email-jaysoffian@gmail.com","threadId":"12177","inReplyTo":null,"subject":"[PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-18T13:53:37Z","receivedAt":"2008-02-18T13:53:37Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"git branch / git checkout -b now honor --track when the upstream branch\nis local. Previously --track was silently ignored for local upstream\nbranches.\n\nThe configuration setting branch.autosetupmerge can now be set to\n\"always\" which is equivalent to using --track. Setting\nbranch.autosetupmerge to boolean true will retains the former behavior\nof only setting up branch.*.merge for remote upstream branches.\n\nSigned-off-by: Jay Soffian <jaysoffian@gmail.com>\n---\n Incorporated Johannes' second round of feedback. This should be all for awhile.\n\n Documentation/config.txt       |   13 ++++++++-----\n Documentation/git-branch.txt   |   24 ++++++++++++------------\n Documentation/git-checkout.txt |   25 ++++++++++++-------------\n branch.c                       |   19 ++++++++++++-------\n branch.h                       |    2 +-\n builtin-branch.c               |   13 ++++---------\n builtin-checkout.c             |   13 ++++---------\n cache.h                        |    8 ++++++++\n config.c                       |    8 ++++++++\n environment.c                  |    1 +\n 10 files changed, 70 insertions(+), 56 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex fb6dae0..f15fe0a 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -378,11 +378,14 @@ apply.whitespace::\n \tas the '--whitespace' option. See linkgit:git-apply[1].\n \n branch.autosetupmerge::\n-\tTells `git-branch` and `git-checkout` to setup new branches\n-\tso that linkgit:git-pull[1] will appropriately merge from that\n-\tremote branch.  Note that even if this option is not set,\n-\tthis behavior can be chosen per-branch using the `--track`\n-\tand `--no-track` options.  This option defaults to true.\n+\tTells `git-branch` and `git-checkout` to setup `branch.*.remote`\n+\tand `branch.*.merge` for new branches so that linkgit:git-pull[1]\n+\twill appropriately merge from that upstream branch. Note that even\n+\tif this option is not set, this behavior can be chosen per-branch\n+\tusing the `--track`\tand `--no-track` options. This option defaults\n+\tto true, which will setup tracking for remote branches. Set it to\n+\t`always` to automatically setup the aforementioned options for local\n+\tupstream branches as well.\n \n branch.<name>.remote::\n \tWhen in branch <name>, it tells `git fetch` which remote to fetch.\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 7e8874a..ce2fc64 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -105,20 +105,20 @@ OPTIONS\n \tDisplay the full sha1s in output listing rather than abbreviating them.\n \n --track::\n-\tSet up configuration so that git-pull will automatically\n-\tretrieve data from the remote branch.  Use this if you always\n-\tpull from the same remote branch into the new branch, or if you\n-\tdon't want to use \"git pull <repository> <refspec>\" explicitly.\n-\tThis behavior is the default.  Set the\n-\tbranch.autosetupmerge configuration variable to false if you\n-\twant git-checkout and git-branch to always behave as if\n-\t'--no-track' were given.\n+\tSet up configuration so that git-pull will\n+\tautomatically retrieve data from the upstream branch.  Use this if\n+\tyou always pull from the same upstream branch into the new branch,\n+\tor if you don't want to use \"git pull <repository> <refspec>\"\n+\texplicitly. This behavior is the default for remote branches.\n+\tSet the branch.autosetupmerge configuration variable to false if you\n+\twant git-checkout and git-branch to always behave as if '--no-track'\n+\twere given. Set it to 'always' if you want git-checkout and git-branch\n+\tto always behave as if '--track' were given.\n \n --no-track::\n-\tWhen a branch is created off a remote branch,\n-\tset up configuration so that git-pull will not retrieve data\n-\tfrom the remote branch, ignoring the branch.autosetupmerge\n-\tconfiguration variable.\n+\tIgnore the branch.autosetupmerge configuration variable. When\n+\tusing git pull with the new branch, a <refspec> will have to be\n+\tgiven explicitly.\n \n <branchname>::\n \tThe name of the branch to create or delete.\ndiff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\nindex b4cfa04..ad2ab51 100644\n--- a/Documentation/git-checkout.txt\n+++ b/Documentation/git-checkout.txt\n@@ -48,21 +48,20 @@ OPTIONS\n \tmay restrict the characters allowed in a branch name.\n \n --track::\n-\tWhen -b is given and a branch is created off a remote branch,\n-\tset up configuration so that git-pull will automatically\n-\tretrieve data from the remote branch.  Use this if you always\n-\tpull from the same remote branch into the new branch, or if you\n-\tdon't want to use \"git pull <repository> <refspec>\" explicitly.\n-\tThis behavior is the default.  Set the\n-\tbranch.autosetupmerge configuration variable to false if you\n-\twant git-checkout and git-branch to always behave as if\n-\t'--no-track' were given.\n+\tWhen -b is given set up configuration so that git-pull will\n+\tautomatically retrieve data from the upstream branch.  Use this if\n+\tyou always pull from the same upstream branch into the new branch,\n+\tor if you don't want to use \"git pull <repository> <refspec>\"\n+\texplicitly. This behavior is the default for remote branches.\n+\tSet the branch.autosetupmerge configuration variable to false if you\n+\twant git-checkout and git-branch to always behave as if '--no-track'\n+\twere given. Set it to 'always' if you want git-checkout and git-branch\n+\tto always behave as if '--track' were given.\n \n --no-track::\n-\tWhen -b is given and a branch is created off a remote branch,\n-\tset up configuration so that git-pull will not retrieve data\n-\tfrom the remote branch, ignoring the branch.autosetupmerge\n-\tconfiguration variable.\n+\tIgnore the branch.autosetupmerge configuration variable. When\n+\tusing git pull with the new branch, a <refspec> will have to be\n+\tgiven explicitly.\n \n -l::\n \tCreate the new branch's reflog.  This activates recording of\ndiff --git a/branch.c b/branch.c\nindex 1fc8788..64f0a4a 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -37,7 +37,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)\n  * to infer the settings for branch.<new_ref>.{remote,merge} from the\n  * config.\n  */\n-static int setup_tracking(const char *new_ref, const char *orig_ref)\n+static int setup_tracking(const char *new_ref, const char *orig_ref, int always)\n {\n \tchar key[1024];\n \tstruct tracking tracking;\n@@ -49,8 +49,12 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)\n \tmemset(&tracking, 0, sizeof(tracking));\n \ttracking.spec.dst = (char *)orig_ref;\n \tif (for_each_remote(find_tracked_branch, &tracking) ||\n-\t\t\t!tracking.matches)\n-\t\treturn 1;\n+\t\t\t!tracking.matches) {\n+\t\tif (!always)\n+\t\t\treturn 1;\n+\t\ttracking.matches = 1;\n+\t\ttracking.src = xstrdup(orig_ref);\n+\t}\n \n \tif (tracking.matches > 1)\n \t\treturn error(\"Not tracking: ambiguous information for ref %s\",\n@@ -62,8 +66,9 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)\n \t\tsprintf(key, \"branch.%s.merge\", new_ref);\n \t\tgit_config_set(key, tracking.src);\n \t\tfree(tracking.src);\n-\t\tprintf(\"Branch %s set up to track remote branch %s.\\n\",\n-\t\t\t       new_ref, orig_ref);\n+\t\tprintf(\"Branch %s set up to track %s branch %s.\\n\",\n+\t\t\tnew_ref, tracking.remote ? \"remote\" : \"local\", \n+\t\t\torig_ref);\n \t}\n \n \treturn 0;\n@@ -71,7 +76,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)\n \n void create_branch(const char *head,\n \t\t   const char *name, const char *start_name,\n-\t\t   int force, int reflog, int track)\n+\t\t   int force, int reflog, enum branch_track track)\n {\n \tstruct ref_lock *lock;\n \tstruct commit *commit;\n@@ -130,7 +135,7 @@ void create_branch(const char *head,\n \t   automatically merges from there.  So far, this is only done for\n \t   remotes registered via .git/config.  */\n \tif (real_ref && track)\n-\t\tsetup_tracking(name, real_ref);\n+\t\tsetup_tracking(name, real_ref, (track == BRANCH_TRACK_ALWAYS));\n \n \tif (write_ref_sha1(lock, sha1, msg) < 0)\n \t\tdie(\"Failed to write ref: %s.\", strerror(errno));\ndiff --git a/branch.h b/branch.h\nindex d30abe0..9f0c2a2 100644\n--- a/branch.h\n+++ b/branch.h\n@@ -13,7 +13,7 @@\n  * branch for (if any).\n  */\n void create_branch(const char *head, const char *name, const char *start_name,\n-\t\t   int force, int reflog, int track);\n+\t\t   int force, int reflog, enum branch_track track);\n \n /*\n  * Remove information about the state of working on the current\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex 7e99103..3b53bb7 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -30,8 +30,6 @@ static const char * const builtin_branch_usage[] = {\n static const char *head;\n static unsigned char head_sha1[20];\n \n-static int branch_track = 1;\n-\n static int branch_use_color = -1;\n static char branch_colors[][COLOR_MAXLEN] = {\n \t\"\\033[m\",\t/* reset */\n@@ -76,10 +74,6 @@ static int git_branch_config(const char *var, const char *value)\n \t\tcolor_parse(value, var, branch_colors[slot]);\n \t\treturn 0;\n \t}\n-\tif (!strcmp(var, \"branch.autosetupmerge\")) {\n-\t\tbranch_track = git_config_bool(var, value);\n-\t\treturn 0;\n-\t}\n \treturn git_color_default_config(var, value);\n }\n \n@@ -420,14 +414,15 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n {\n \tint delete = 0, rename = 0, force_create = 0;\n \tint verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;\n-\tint reflog = 0, track;\n+\tint reflog = 0;\n+\tenum branch_track track;\n \tint kinds = REF_LOCAL_BRANCH;\n \tstruct commit_list *with_commit = NULL;\n \n \tstruct option options[] = {\n \t\tOPT_GROUP(\"Generic options\"),\n \t\tOPT__VERBOSE(&verbose),\n-\t\tOPT_BOOLEAN( 0 , \"track\",  &track, \"set up tracking mode (see git-pull(1))\"),\n+\t\tOPT_SET_INT( 0 , \"track\",  &track, \"set up tracking mode (see git-pull(1))\", BRANCH_TRACK_ALWAYS),\n \t\tOPT_BOOLEAN( 0 , \"color\",  &branch_use_color, \"use colored output\"),\n \t\tOPT_SET_INT('r', NULL,     &kinds, \"act on remote-tracking branches\",\n \t\t\tREF_REMOTE_BRANCH),\n@@ -458,7 +453,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \tif (branch_use_color == -1)\n \t\tbranch_use_color = git_use_color_default;\n \n-\ttrack = branch_track;\n+\ttrack = git_branch_track;\n \targc = parse_options(argc, argv, options, builtin_branch_usage, 0);\n \tif (!!delete + !!rename + !!force_create > 1)\n \t\tusage_with_options(builtin_branch_usage, options);\ndiff --git a/builtin-checkout.c b/builtin-checkout.c\nindex 0d19835..cf26e10 100644\n--- a/builtin-checkout.c\n+++ b/builtin-checkout.c\n@@ -186,7 +186,7 @@ struct checkout_opts {\n \n \tchar *new_branch;\n \tint new_branch_log;\n-\tint track;\n+\tenum branch_track track;\n };\n \n struct branch_info {\n@@ -521,13 +521,8 @@ static int switch_branches(struct checkout_opts *opts,\n \treturn post_checkout_hook(old.commit, new->commit, 1);\n }\n \n-static int branch_track = 0;\n-\n static int git_checkout_config(const char *var, const char *value)\n {\n-\tif (!strcmp(var, \"branch.autosetupmerge\"))\n-\t\tbranch_track = git_config_bool(var, value);\n-\n \treturn git_default_config(var, value);\n }\n \n@@ -542,7 +537,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \t\tOPT__QUIET(&opts.quiet),\n \t\tOPT_STRING('b', NULL, &opts.new_branch, \"new branch\", \"branch\"),\n \t\tOPT_BOOLEAN('l', NULL, &opts.new_branch_log, \"log for new branch\"),\n-\t\tOPT_BOOLEAN( 0 , \"track\", &opts.track, \"track\"),\n+\t\tOPT_SET_INT( 0 , \"track\",  &opts.track, \"track\", BRANCH_TRACK_ALWAYS),\n \t\tOPT_BOOLEAN('f', NULL, &opts.force, \"force\"),\n \t\tOPT_BOOLEAN('m', NULL, &opts.merge, \"merge\"),\n \t\tOPT_END(),\n@@ -553,7 +548,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \n \tgit_config(git_checkout_config);\n \n-\topts.track = branch_track;\n+\topts.track = git_branch_track;\n \n \targc = parse_options(argc, argv, options, checkout_usage, 0);\n \tif (argc) {\n@@ -582,7 +577,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \t\targc--;\n \t}\n \n-\tif (!opts.new_branch && (opts.track != branch_track))\n+\tif (!opts.new_branch && (opts.track != git_branch_track))\n \t\tdie(\"git checkout: --track and --no-track require -b\");\n \n \tif (opts.force && opts.merge)\ndiff --git a/cache.h b/cache.h\nindex 2b59c44..90b3a9e 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -393,6 +393,14 @@ enum safe_crlf {\n \n extern enum safe_crlf safe_crlf;\n \n+enum branch_track {\n+\tBRANCH_TRACK_REMOTES_FALSE = 0,\n+\tBRANCH_TRACK_REMOTES_TRUE,\n+\tBRANCH_TRACK_ALWAYS,\n+};\n+\n+extern enum branch_track git_branch_track;\n+\n #define GIT_REPO_VERSION 0\n extern int repository_format_version;\n extern int check_repository_format(void);\ndiff --git a/config.c b/config.c\nindex 8064cae..556b2ec 100644\n--- a/config.c\n+++ b/config.c\n@@ -464,6 +464,14 @@ int git_default_config(const char *var, const char *value)\n \t\twhitespace_rule_cfg = parse_whitespace_rule(value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"branch.autosetupmerge\")) {\n+\t\tif (value && !strcasecmp(value, \"always\")) {\n+\t\t\tgit_branch_track = BRANCH_TRACK_ALWAYS;\n+\t\t\treturn 0;\n+\t\t}\n+\t\tgit_branch_track = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \t/* Add other config variables here and to Documentation/config.txt. */\n \treturn 0;\ndiff --git a/environment.c b/environment.c\nindex 3527f16..24334a2 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -37,6 +37,7 @@ const char *excludes_file;\n int auto_crlf = 0;\t/* 1: both ways, -1: only when adding git objects */\n enum safe_crlf safe_crlf = SAFE_CRLF_WARN;\n unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;\n+enum branch_track git_branch_track = BRANCH_TRACK_REMOTES_TRUE;\n \n /* This is set by setup_git_dir_gently() and/or git_default_config() */\n char *git_work_tree_cfg;\n-- \n1.5.4.2.203.gf8d86\n"},{"id":"69150","messageId":"alpine.LSU.1.00.0802181403040.30505@racer.site","threadId":"12177","inReplyTo":"1203342817-19653-1-git-send-email-jaysoffian@gmail.com","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-02-18T14:05:36Z","receivedAt":"2008-02-18T14:05:36Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 18 Feb 2008, Jay Soffian wrote:\n\n>  Incorporated Johannes' second round of feedback.\n\nNot exactly.\n\n> diff --git a/branch.c b/branch.c\n> index 1fc8788..64f0a4a 100644\n> --- a/branch.c\n> +++ b/branch.c\n> @@ -37,7 +37,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)\n>   * to infer the settings for branch.<new_ref>.{remote,merge} from the\n>   * config.\n>   */\n> -static int setup_tracking(const char *new_ref, const char *orig_ref)\n> +static int setup_tracking(const char *new_ref, const char *orig_ref, int always)\n>  {\n>  \tchar key[1024];\n>  \tstruct tracking tracking;\n> @@ -49,8 +49,12 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)\n>  \tmemset(&tracking, 0, sizeof(tracking));\n>  \ttracking.spec.dst = (char *)orig_ref;\n>  \tif (for_each_remote(find_tracked_branch, &tracking) ||\n> -\t\t\t!tracking.matches)\n> -\t\treturn 1;\n> +\t\t\t!tracking.matches) {\n> +\t\tif (!always)\n> +\t\t\treturn 1;\n> +\t\ttracking.matches = 1;\n> +\t\ttracking.src = xstrdup(orig_ref);\n> +\t}\n>  \n\nThis looks completely different than what I commented on.  And my comments \nsuggested a different solution.\n\nUnfortunately, I will not have time for the rest of the day to review that \nnew thing (it is not at all obvious for me why this works as intended, and \ndoes not break anything else).\n\nBut you can use the time to write some tests ;-)\n\nCiao,\nDscho\n"},{"id":"69154","messageId":"76718490802180638k6f776463t692a828f71ce0a58@mail.gmail.com","threadId":"12177","inReplyTo":"alpine.LSU.1.00.0802181403040.30505@racer.site","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-18T14:38:48Z","receivedAt":"2008-02-18T14:38:48Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Feb 18, 2008 9:05 AM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Mon, 18 Feb 2008, Jay Soffian wrote:\n>\n> >  Incorporated Johannes' second round of feedback.\n>\n> Not exactly.\n\nHeh...\n\n> This looks completely different than what I commented on.  And my comments\n> suggested a different solution.\n\nThought process went like this:\n\n- fix sprintf() to use snprintf()\n- notice setup_tracking() uses sprintf() and think about fixing it too\n- realize setup_tracking() does bounds checking first and its use of sprintf()\n  is therefor safe.\n- go to copy the bounds checking code from setup_tracking() to the area you\n  commented on.\n- realized duplicating the code was dumb and I could just re-use what was\n  already in setup_tracking() via what was just sent.\n\n> But you can use the time to write some tests ;-)\n\nSure I can. I really hope after all this work the patch gets accepted.\n\nj.\n"},{"id":"69185","messageId":"alpine.LSU.1.00.0802181839400.30505@racer.site","threadId":"12177","inReplyTo":"1203342817-19653-1-git-send-email-jaysoffian@gmail.com","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-02-18T18:47:51Z","receivedAt":"2008-02-18T18:47:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 18 Feb 2008, Jay Soffian wrote:\n\n> diff --git a/branch.c b/branch.c\n> index 1fc8788..64f0a4a 100644\n> --- a/branch.c\n> +++ b/branch.c\n> @@ -49,8 +49,12 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)\n>  \tmemset(&tracking, 0, sizeof(tracking));\n>  \ttracking.spec.dst = (char *)orig_ref;\n>  \tif (for_each_remote(find_tracked_branch, &tracking) ||\n> -\t\t\t!tracking.matches)\n> -\t\treturn 1;\n> +\t\t\t!tracking.matches) {\n> +\t\tif (!always)\n> +\t\t\treturn 1;\n> +\t\ttracking.matches = 1;\n> +\t\ttracking.src = xstrdup(orig_ref);\n> +\t}\n\nI think you need to split this into\n\n\tif (for_each_remote(...))\n\t\treturn 1;\n\tif (!tracking.matches && !always)\n\t\t\treturn 1;\n\nbecause an error in for_each_remote() is a proper error, and should not be \nignored (speaking of which, the return value is unchecked...).  And then, \nlater,\n\n        if (tracking.matches == 1) {\n                sprintf(key, \"branch.%s.remote\", new_ref);\n                git_config_set(key, tracking.remote ?  tracking.remote : \".\");\n                sprintf(key, \"branch.%s.merge\", new_ref);\n-               git_config_set(key, tracking.src);\n+               git_config_set(key, tracking.src ? tracking.src : orig_ref);\n                free(tracking.src);\n\n> @@ -130,7 +135,7 @@ void create_branch(const char *head,\n>  \t   automatically merges from there.  So far, this is only done for\n>  \t   remotes registered via .git/config.  */\n>  \tif (real_ref && track)\n> -\t\tsetup_tracking(name, real_ref);\n> +\t\tsetup_tracking(name, real_ref, (track == BRANCH_TRACK_ALWAYS));\n\nIt is a matter of taste, I guess, but I would remove the parens around the \nboolean expression.\n\nFWIW a very good argument in favour of your patch is IMHO that now, \n\"--track\" works as a user would expect, even for local branch-offs.\n\nAnd of course that you were very responsive, and really put in a lot of \neffort.\n\nThanks,\nDscho\n"},{"id":"69210","messageId":"7vir0mnfq6.fsf@gitster.siamese.dyndns.org","threadId":"12177","inReplyTo":"1203342817-19653-1-git-send-email-jaysoffian@gmail.com","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-18T20:59:13Z","receivedAt":"2008-02-18T20:59:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jay Soffian <jaysoffian@gmail.com> writes:\n\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index fb6dae0..f15fe0a 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -378,11 +378,14 @@ apply.whitespace::\n>  \tas the '--whitespace' option. See linkgit:git-apply[1].\n>  \n>  branch.autosetupmerge::\n> ...\n> +\tTells `git-branch` and `git-checkout` to setup `branch.*.remote`\n> +\tand `branch.*.merge` for new branches so that linkgit:git-pull[1]\n> +\twill appropriately merge from that upstream branch. Note that even\n> +\tif this option is not set, this behavior can be chosen per-branch\n> +\tusing the `--track`\tand `--no-track` options. This option defaults\n\nYou have an unintended tab there.\n\n> +\tto true, which will setup tracking for remote branches. Set it to\n> +\t`always` to automatically setup the aforementioned options for local\n> +\tupstream branches as well.\n\nI somehow find it easier to read if the default is always\ndescribed at the end of the paragraph, i.e. \"Setting this to\nvalue X does foo, Y does bar, Z does baz. Defaults to X.\", but\nthat may be just me.\n\n> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\n> index 7e8874a..ce2fc64 100644\n> --- a/Documentation/git-branch.txt\n> +++ b/Documentation/git-branch.txt\n> @@ -105,20 +105,20 @@ OPTIONS\n>  \tDisplay the full sha1s in output listing rather than abbreviating them.\n>  \n>  --track::\n> ...\n> +\tSet up configuration so that git-pull will\n> +\tautomatically retrieve data from the upstream branch.  Use this if\n> +\tyou always pull from the same upstream branch into the new branch,\n> +\tor if you don't want to use \"git pull <repository> <refspec>\"\n> +\texplicitly. This behavior is the default for remote branches.\n> +\tSet the branch.autosetupmerge configuration variable to false if you\n> +\twant git-checkout and git-branch to always behave as if '--no-track'\n> +\twere given. Set it to 'always' if you want git-checkout and git-branch\n> +\tto always behave as if '--track' were given.\n\nRe-wrapping the\nparagraph at an unusual place.  It is Ok to do so if it is done\nto keep the unchanged part intact to minimize the diff text, but\notherwise, please don't.\n\nYou reworded \"remote branch\" to \"upstream branch\" here and other\nplaces.  I think that makes the intention easier to understand.\nIt is \"the branch this new branch intends to build on top of\",\nso the earlier text should have said \"remote tracking branch\"\nbut the intention has always been to mean \"on top of whom will I\nbe building\".\n\nThis is not a flaw in your patch, but I suspect \"or if you\ndon't want to\" should have been \"and if you don't want to\".\n\n\"This behaviour is the default for remote branches\" feels a bit\nodd.  It confuses the first time reader as if you are saying \"if\nyou are creating a remote branch with \"git-branch\" command, this\nbehaviour is the default\", which is not what you are saying.  I\nthink \"... the default when forking off of a remote tracking\nbranch\" is what you meant.\n\n>  --no-track::\n> -\tWhen a branch is created off a remote branch,\n> -\tset up configuration so that git-pull will not retrieve data\n> -\tfrom the remote branch, ignoring the branch.autosetupmerge\n> -\tconfiguration variable.\n> +\tIgnore the branch.autosetupmerge configuration variable. When\n> +\tusing git pull with the new branch, a <refspec> will have to be\n> +\tgiven explicitly.\n\nThis rewrite probably has made the description easier to understand.\n\n> diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\n> index b4cfa04..ad2ab51 100644\n> --- a/Documentation/git-checkout.txt\n> +++ b/Documentation/git-checkout.txt\n> @@ -48,21 +48,20 @@ OPTIONS\n>  \tmay restrict the characters allowed in a branch name.\n>  \n>  --track::\n> ...\n> +\tWhen -b is given set up configuration so that git-pull will\n\ns/given/&,/;\n\n> +\tautomatically retrieve data from the upstream branch.  Use this if\n> +\tyou always pull from the same upstream branch into the new branch,\n> +\tor if you don't want to use \"git pull <repository> <refspec>\"\n> +\texplicitly. This behavior is the default for remote branches.\n\nThe same comment on \"or if you don't want to\" applies.\n\n> @@ -49,8 +49,12 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)\n>  \tmemset(&tracking, 0, sizeof(tracking));\n>  \ttracking.spec.dst = (char *)orig_ref;\n>  \tif (for_each_remote(find_tracked_branch, &tracking) ||\n> -\t\t\t!tracking.matches)\n> -\t\treturn 1;\n> +\t\t\t!tracking.matches) {\n> +\t\tif (!always)\n> +\t\t\treturn 1;\n> +\t\ttracking.matches = 1;\n> +\t\ttracking.src = xstrdup(orig_ref);\n> +\t}\n\nI suspect this is a clever fallback to pretend as if you have\n[remote \".\"] fetch=refs/*:refs/* when nothing else matches, but\nI think it needs an explanation why this is a good idea and\nwould not break others.  Also I suspect this should be moved\nafter you see for-each-remote returns without error and did not\nfind any match.\n\n> @@ -71,7 +76,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)\n>  \n>  void create_branch(const char *head,\n>  \t\t   const char *name, const char *start_name,\n> -\t\t   int force, int reflog, int track)\n> +\t\t   int force, int reflog, enum branch_track track)\n>  {\n>  \tstruct ref_lock *lock;\n>  \tstruct commit *commit;\n> @@ -130,7 +135,7 @@ void create_branch(const char *head,\n>  \t   automatically merges from there.  So far, this is only done for\n>  \t   remotes registered via .git/config.  */\n>  \tif (real_ref && track)\n> -\t\tsetup_tracking(name, real_ref);\n> +\t\tsetup_tracking(name, real_ref, (track == BRANCH_TRACK_ALWAYS));\n\nIt probably is better to pass 'track' itself and have the\nspecial case logic inside setup_tracking() instead.  Maybe we\nwould want to add new tracking mode that needs different\nmatching logic there later.\n\nThe move to default_config() is probably a good idea.\n\n> diff --git a/cache.h b/cache.h\n> index 2b59c44..90b3a9e 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -393,6 +393,14 @@ enum safe_crlf {\n>  \n>  extern enum safe_crlf safe_crlf;\n>  \n> +enum branch_track {\n> +\tBRANCH_TRACK_REMOTES_FALSE = 0,\n> +\tBRANCH_TRACK_REMOTES_TRUE,\n> +\tBRANCH_TRACK_ALWAYS,\n> +};\n\nPerhaps BRANCH_TRACK_{NEVER,REMOTE,ALWAYS} would be easier\n(although I cannot decide if s/NEVER/FALSE/ would be better)?\n"}]}