{"thread":{"id":"12185","subject":"[PATCH] branch: optionally setup branch.*.merge from upstream local branches","startedAt":"2008-02-19T02:07:12Z","lastAt":"2008-02-20T00:55:31Z","messageCount":14,"participants":["Jay Soffian","Junio C Hamano","Alex Riesen","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"69222","messageId":"1203386832-43969-1-git-send-email-jaysoffian@gmail.com","threadId":"12185","inReplyTo":null,"subject":"[PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-19T02:07:12Z","receivedAt":"2008-02-19T02:07:12Z","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\nIncludes test cases for the new functionality.\n\nSigned-off-by: Jay Soffian <jaysoffian@gmail.com>\n---\nChanges from last iteration:\n\n- Reworked the documentation. I incorporated some of Junio's suggestions, but\n  I made a lot of other clarifications (IMO...). Let me know what you think.\n\n- Added a suggested test case to t7201-co and some of my own to t3200-branch.\n\n- Renamed the enum values per Junio.\n\n- Incorporated suggestions from Junio and Johannes re:setup_tracking().\n\n- The code/doc/and test case changes are now all in this commit together (I\n  don't think it's too much for review...?)\n\nThanks for the feedback so far.\n\n Documentation/config.txt       |   15 ++++++---\n Documentation/git-branch.txt   |   69 +++++++++++++++++-----------------------\n Documentation/git-checkout.txt |   61 ++++++++++++++++++-----------------\n branch.c                       |   20 +++++++----\n branch.h                       |    2 +-\n builtin-branch.c               |   14 +++-----\n builtin-checkout.c             |   13 ++-----\n cache.h                        |    8 +++++\n config.c                       |    8 +++++\n environment.c                  |    1 +\n t/t3200-branch.sh              |   32 ++++++++++++++++--\n t/t7201-co.sh                  |    8 +++++\n 12 files changed, 147 insertions(+), 104 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex fb6dae0..fd4904f 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -378,11 +378,16 @@ 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+\tWhen setting up new branch <name> from existing branch\n+\t<starting-point>, tells linkgit:git-branch[1] and\n+\tlinkgit:git-checkout[1] to configure branch.<name>.remote and\n+\tbranch.<name>.merge for use with linkgit:git-fetch[1] and\n+\tlinkgit:git-pull[1]. There are three valid settings: `false` -- no\n+\tautomatic setup; `true` -- automatic setup when <starting-poiint> is\n+\ta remote branch; `always` -- automatic setup when <starting-point>\n+\tis either a local or remote branch. The `--track` and `--no-track`\n+\toptions to linkgit:git-branch[1] and linkgit:git-checkout[1] always\n+\toverride this setting. The default is `true`.\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..3ad9dc0 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -11,9 +11,9 @@ SYNOPSIS\n 'git-branch' [--color | --no-color] [-r | -a]\n \t   [-v [--abbrev=<length> | --no-abbrev]]\n \t   [--contains <commit>]\n-'git-branch' [--track | --no-track] [-l] [-f] <branchname> [<start-point>]\n-'git-branch' (-m | -M) [<oldbranch>] <newbranch>\n-'git-branch' (-d | -D) [-r] <branchname>...\n+'git-branch' [--track | --no-track] [-l] [-f] <newbranch> [<start-point>]\n+'git-branch' (-m | -M) [<branch>] <newbranch>\n+'git-branch' (-d | -D) [-r] <branch>...\n \n DESCRIPTION\n -----------\n@@ -25,29 +25,25 @@ With `--contains <commit>`, shows only the branches that\n contains the named commit (in other words, the branches whose\n tip commits are descendant of the named commit).\n \n-In its second form, a new branch named <branchname> will be created.\n-It will start out with a head equal to the one given as <start-point>.\n-If no <start-point> is given, the branch will be created with a head\n-equal to that of the currently checked out branch.\n+In its second form, a new branch named <newbranch> will be created.\n+It will start out with a head equal to <start-point>. If no\n+<start-point> is given, it is assumed to be the currently checked\n+out branch. The new branch may optionally be configured for use with\n+linkgit:git-pull[1] -- see `--track` and `--no-track` in the OPTIONS\n+section below.\n \n Note that this will create the new branch, but it will not switch the\n working tree to it; use \"git checkout <newbranch>\" to switch to the\n-new branch.\n+new branch. (As a shortcut consider using \"git checkout [--track | \n+--notrack ] -b <newbranch>\" instead.)\n \n-When a local branch is started off a remote branch, git sets up the\n-branch so that linkgit:git-pull[1] will appropriately merge from that\n-remote branch.  If this behavior is not desired, it is possible to\n-disable it using the global `branch.autosetupmerge` configuration\n-flag.  That setting can be overridden by using the `--track`\n-and `--no-track` options.\n-\n-With a '-m' or '-M' option, <oldbranch> will be renamed to <newbranch>.\n-If <oldbranch> had a corresponding reflog, it is renamed to match\n+With a '-m' or '-M' option, <branch> will be renamed to <newbranch>.\n+If <branch> had a corresponding reflog, it is renamed to match\n <newbranch>, and a reflog entry is created to remember the branch\n renaming. If <newbranch> exists, -M must be used to force the rename\n to happen.\n \n-With a `-d` or `-D` option, `<branchname>` will be deleted.  You may\n+With a `-d` or `-D` option, `<branch>` will be deleted.  You may\n specify more than one branch for deletion.  If the branch currently\n has a reflog then the reflog will also be deleted.\n \n@@ -69,7 +65,7 @@ OPTIONS\n -l::\n \tCreate the branch's reflog.  This activates recording of\n \tall changes made to the branch ref, enabling use of date\n-\tbased sha1 expressions such as \"<branchname>@\\{yesterday}\".\n+\tbased sha1 expressions such as \"<branch>@\\{yesterday}\".\n \n -f::\n \tForce the creation of a new branch even if it means deleting\n@@ -105,38 +101,31 @@ 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 the new branch's configuration so that linkgit:git-pull[1]\n+\twill appropriately merge from the start point when run without\n+\targuments while in the new branch. `--track` is the default behavior\n+\twhen the start point is a remote branch. See the documentation for\n+\tthe `branch.autosetupmerge` configuration variable in\n+\tlinkgit:git-config[1] for how to modify the default.\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. The new\n+\tbranch will not be setup for automatic merging.\n \n-<branchname>::\n-\tThe name of the branch to create or delete.\n+<newbranch>::\n+\tThe name of the branch to create or rename to.\n \tThe new branch name must pass all checks defined by\n \tlinkgit:git-check-ref-format[1].  Some of these checks\n \tmay restrict the characters allowed in a branch name.\n \n <start-point>::\n \tThe new branch will be created with a HEAD equal to this.  It may\n-\tbe given as a branch name, a commit-id, or a tag.  If this option\n-\tis omitted, the current branch is assumed.\n+\tbe given as a branch name, a commit-id, or a tag.  Defaults\n+\tto the current HEAD.\n \n-<oldbranch>::\n-\tThe name of an existing branch to rename.\n+<branch>::\n+\tThe name of an existing branch to rename or delete.\n \n-<newbranch>::\n-\tThe new name for an existing branch. The same restrictions as for\n-\t<branchname> applies.\n \n \n Examples\ndiff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\nindex b4cfa04..fd862b4 100644\n--- a/Documentation/git-checkout.txt\n+++ b/Documentation/git-checkout.txt\n@@ -8,25 +8,27 @@ git-checkout - Checkout and switch to a branch\n SYNOPSIS\n --------\n [verse]\n-'git-checkout' [-q] [-f] [[--track | --no-track] -b <new_branch> [-l]] [-m] [<branch>]\n+'git-checkout' [-q] [-f] [-m] <branch>\n+'git-checkout' [-q] [-f] [-m] [-l] [--track | --no-track] -b <newbranch> [<start-point>]\n 'git-checkout' [<tree-ish>] <paths>...\n \n DESCRIPTION\n -----------\n \n-When <paths> are not given, this command switches branches by\n-updating the index and working tree to reflect the specified\n-branch, <branch>, and updating HEAD to be <branch> or, if\n-specified, <new_branch>.  Using -b will cause <new_branch> to\n-be created; in this case you can use the --track or --no-track\n-options, which will be passed to `git branch`.\n+It its first form this command switches branches by updating the\n+index and working tree to reflect <branch> and updating HEAD to\n+<branch>.\n \n-When <paths> are given, this command does *not* switch\n+In its second form this command optionally switches to <start-point>\n+by updating the index and working tree to reflect <start-point>.\n+<newbranch> is then created and HEAD is updated to it. The new\n+branch may optionally be configured for use with linkgit:git-pull[1]\n+-- see `--track` and `--no-track` in the OPTIONS section below.\n+\n+In its third form, this command does *not* switch\n branches.  It updates the named paths in the working tree from\n the index file (i.e. it runs `git-checkout-index -f -u`), or\n-from a named commit.  In\n-this case, the `-f` and `-b` options are meaningless and giving\n-either of them results in an error.  <tree-ish> argument can be\n+from a named commit. The optional <tree-ish> argument can be\n used to specify a specific tree-ish (i.e. commit, tag or tree)\n to update the index for the given paths before updating the\n working tree.\n@@ -42,27 +44,23 @@ OPTIONS\n \tfrom HEAD.  This is used to throw away local changes.\n \n -b::\n-\tCreate a new branch named <new_branch> and start it at\n-\t<branch>.  The new branch name must pass all checks defined\n-\tby linkgit:git-check-ref-format[1].  Some of these checks\n-\tmay restrict the characters allowed in a branch name.\n+\tCreate a new branch named <newbranch> and start it at the optional\n+\t<start-point> (the currently checked out branch if not given). The\n+\tnew branch name must pass all checks defined by\n+\tlinkgit:git-check-ref-format[1]. Some of these checks may restrict\n+\tthe 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+\tSet up the new branch's configuration so that linkgit:git-pull[1]\n+\twill appropriately merge from the start point when run without\n+\targuments while in the new branch. `--track` is the default behavior\n+\twhen the start point is a remote branch. See the documentation for\n+\tthe `branch.autosetupmerge` configuration variable in\n+\tlinkgit:git-config[1] for how to modify the default.\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. The new\n+\tbranch will not be setup for automatic merging.\n \n -l::\n \tCreate the new branch's reflog.  This activates recording of\n@@ -83,9 +81,14 @@ paths are left unmerged, and you need to resolve the conflicts\n and mark the resolved paths with `git add` (or `git rm` if the merge\n should result in deletion of the path).\n \n-<new_branch>::\n+<newbranch>::\n \tName for the new branch.\n \n+<start-point>::\n+\tThe new branch will be created with a HEAD equal to this.  It may\n+\tbe given as a branch name, a commit-id, or a tag.  Defaults\n+\tto the current HEAD.\n+\n <branch>::\n \tBranch to checkout; may be any object ID that resolves to a\n \tcommit.  Defaults to HEAD.\ndiff --git a/branch.c b/branch.c\nindex 1fc8788..9d7585e 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -37,7 +37,8 @@ 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,\n+                          enum branch_track track)\n {\n \tchar key[1024];\n \tstruct tracking tracking;\n@@ -48,10 +49,14 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)\n \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+\tif (for_each_remote(find_tracked_branch, &tracking))\n \t\treturn 1;\n \n+\tif (!tracking.matches && track == BRANCH_TRACK_ALWAYS) {\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 \t\t\t\torig_ref);\n@@ -62,8 +67,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 +77,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 +136,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);\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..bcc2354 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,16 @@ 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))\",\n+\t\t\tBRANCH_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 +454,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..3c17e2c 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_NEVER = 0,\n+\tBRANCH_TRACK_REMOTE,\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..6739a3f 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_REMOTE;\n \n /* This is set by setup_git_dir_gently() and/or git_default_config() */\n char *git_work_tree_cfg;\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex d21081d..94e4dc6 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -15,6 +15,9 @@ test_expect_success \\\n     'echo Hello > A &&\n      git update-index --add A &&\n      git-commit -m \"Initial commit.\" &&\n+     echo World >> A &&\n+     git update-index --add A &&\n+     git-commit -m \"Second commit.\" &&\n      HEAD=$(git rev-parse --verify HEAD)'\n \n test_expect_success \\\n@@ -161,7 +164,7 @@ test_expect_success 'avoid ambiguous track' '\n '\n \n test_expect_success 'test overriding tracking setup via --no-track' \\\n-    'git config branch.autosetupmerge true &&\n+    'git config branch.autosetupmerge always &&\n      git config remote.local.url . &&\n      git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&\n      (git show-ref -q refs/remotes/local/master || git-fetch local) &&\n@@ -171,7 +174,9 @@ test_expect_success 'test overriding tracking setup via --no-track' \\\n      ! test \"$(git config branch.my2.merge)\" = refs/heads/master'\n \n test_expect_success 'no tracking without .fetch entries' \\\n-    'git branch --track my6 s &&\n+    'git config branch.autosetupmerge true &&\n+     git branch my6 s &&\n+     git config branch.automsetupmerge false &&\n      test -z \"$(git config branch.my6.remote)\" &&\n      test -z \"$(git config branch.my6.merge)\"'\n \n@@ -192,14 +197,33 @@ test_expect_success 'test deleting branch without config' \\\n     'git branch my7 s &&\n      test \"$(git branch -d my7 2>&1)\" = \"Deleted branch my7.\"'\n \n-# Keep this test last, as it changes the current branch\n+test_expect_success 'test tracking without .fetch entries w/--track given' \\\n+    'git branch --track my8 &&\n+     test \"$(git config branch.my8.remote)\" &&\n+     test \"$(git config branch.my8.merge)\"'\n+\n+test_expect_success \\\n+    'no tracking entries from non-branch HEAD even w/autosetupmerge=always)' \\\n+    'git config branch.autosetupmerge always &&\n+     git branch my9 HEAD^ &&\n+     git config branch.autosetupmerge false &&\n+     test -z \"$(git config branch.my9.remote)\" &&\n+     test -z \"$(git config branch.my9.merge)\"'\n+\n+test_expect_success \\\n+    'no tracking entries from non-branch HEAD even w/--track' \\\n+    'git branch --track my10 HEAD^ &&\n+     test -z \"$(git config branch.my10.remote)\" &&\n+     test -z \"$(git config branch.my10.merge)\"'\n+\n+# Keep this test last, as they change the current branch\n cat >expect <<EOF\n 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000\tbranch: Created from master\n EOF\n test_expect_success \\\n     'git checkout -b g/h/i -l should create a branch and a log' \\\n \t'GIT_COMMITTER_DATE=\"2005-05-26 23:30\" \\\n-     git-checkout -b g/h/i -l master &&\n+     git checkout -b g/h/i -l master &&\n \t test -f .git/refs/heads/g/h/i &&\n \t test -f .git/logs/refs/heads/g/h/i &&\n \t diff expect .git/logs/refs/heads/g/h/i'\ndiff --git a/t/t7201-co.sh b/t/t7201-co.sh\nindex 06959d9..384e3be 100755\n--- a/t/t7201-co.sh\n+++ b/t/t7201-co.sh\n@@ -279,4 +279,12 @@ test_expect_success 'checkout with ambiguous tag/branch names' '\n \n '\n \n+test_expect_success \\\n+    'checkout w/--track sets up tracking w/autosetupmerge=false' '\n+    git config branch.autosetupmerge false &&\n+    git checkout -f master && git clean -f &&\n+    git checkout --track -b track &&\n+    test \"$(git config branch.track.remote)\" &&\n+    test \"$(git config branch.track.merge)\"'\n+\n test_done\n-- \n1.5.4.2.203.gf8d86\n"},{"id":"69223","messageId":"76718490802181819o4cf742edi92bbcd9039f0cdac@mail.gmail.com","threadId":"12185","inReplyTo":"1203386832-43969-1-git-send-email-jaysoffian@gmail.com","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-19T02:19:43Z","receivedAt":"2008-02-19T02:19:43Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Feb 18, 2008 9:07 PM, Jay Soffian <jaysoffian@gmail.com> wrote:\n> diff --git a/branch.c b/branch.c\n> index 1fc8788..9d7585e 100644\n> --- a/branch.c\n> +++ b/branch.c\n> @@ -37,7 +37,8 @@ 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,\n> +                          enum branch_track track)\n>  {\n>         char key[1024];\n>         struct tracking tracking;\n> @@ -48,10 +49,14 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)\n>\n>         memset(&tracking, 0, sizeof(tracking));\n>         tracking.spec.dst = (char *)orig_ref;\n> -       if (for_each_remote(find_tracked_branch, &tracking) ||\n> -                       !tracking.matches)\n> +       if (for_each_remote(find_tracked_branch, &tracking))\n>                 return 1;\n>\n> +       if (!tracking.matches && track == BRANCH_TRACK_ALWAYS) {\n> +               tracking.matches = 1;\n> +               tracking.src = xstrdup(orig_ref);\n> +       }\n> +\n\nWell that's obviously wrong (though it causes no problems, setup_tracking()\nwould return 0 when it should return 1, but its return value is currently\nignored). I changed it to:\n\n\tif (!tracking.matches) {\n\t\tif (track != BRANCH_TRACK_ALWAYS)\n\t\t\treturn 1;\n\t\ttracking.matches = 1;\n\t\ttracking.src = xstrdup(orig_ref);\n\t}\n\nj.\n"},{"id":"69234","messageId":"7vprutlchh.fsf@gitster.siamese.dyndns.org","threadId":"12185","inReplyTo":"1203386832-43969-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-19T05:52:10Z","receivedAt":"2008-02-19T05:52:10Z","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..fd4904f 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -378,11 +378,16 @@ apply.whitespace::\n>  \tas the '--whitespace' option. See linkgit:git-apply[1].\n>  \n>  branch.autosetupmerge::\n> ...\n> +\tWhen setting up new branch <name> from existing branch\n> +\t<starting-point>, tells linkgit:git-branch[1] and\n> +\tlinkgit:git-checkout[1] to configure branch.<name>.remote and\n> +\tbranch.<name>.merge for use with linkgit:git-fetch[1] and\n> +\tlinkgit:git-pull[1]. There are three valid settings: `false` -- no\n> +\tautomatic setup; `true` -- automatic setup when <starting-poiint> is\n> +\ta remote branch; `always` -- automatic setup when <starting-point>\n> +\tis either a local or remote branch. The `--track` and `--no-track`\n> +\toptions to linkgit:git-branch[1] and linkgit:git-checkout[1] always\n> +\toverride this setting. The default is `true`.\n\nThree issues.\n\n (1) \"tells X and Y to configure\" is bad.  We may later want to\n     add a command that forks a new branch from an existing one,\n     and you sure do want it to honor this variable.  Better not\n     list the commands but tell the reader that it applies to\n     the act of forking a new branch based on an existing one.\n\n (2) \"configure X and Y\" is bad.  We may later want to add new\n     configuration variables to facilitate marking a branch that\n     builds on top of another in addition to the existing remote\n     and merge, and you sure do want them to be also set up\n     appropriately.\n\n (3) \"for use with X and Y\" is bad.  We may later want to add\n     new commands that you would use to work with a branch that\n     builds on top of another, and you sure do want them to\n     honor the configuration variables this automatically sets\n     up.\n\nSo, how about...\n\n        When creating a new branch starting at an existing 'upstream'\n        branch, the new branch can be marked as building on top of the\n        'upstream' branch, by setting a few configuration variables\n        (e.g. branch.<name>.remote and branch.<name>.merge).  This can\n        be explicitly asked for by giving `--track` (and turned off by\n        giving `--no-track`) option to commands that create a new branch\n        (e.g.  linkgit:git-branch[1]); this variable is consulted when\n        neither option is given.  \n+\nWhen set to `true`, act as if `--track` is given only if 'upstream' is a\nremote tracking branch.  When set to `always`, act as if `--track` is\ngiven even if 'upstream' is a local branch.  When set to `false`, no\nsuch extra configuration is made.  Defaults to `true`.\n\n> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\n> index 7e8874a..3ad9dc0 100644\n> --- a/Documentation/git-branch.txt\n> +++ b/Documentation/git-branch.txt\n> @@ -11,9 +11,9 @@ SYNOPSIS\n>  'git-branch' [--color | --no-color] [-r | -a]\n>  \t   [-v [--abbrev=<length> | --no-abbrev]]\n>  \t   [--contains <commit>]\n> -'git-branch' [--track | --no-track] [-l] [-f] <branchname> [<start-point>]\n> -'git-branch' (-m | -M) [<oldbranch>] <newbranch>\n> -'git-branch' (-d | -D) [-r] <branchname>...\n> +'git-branch' [--track | --no-track] [-l] [-f] <newbranch> [<start-point>]\n> +'git-branch' (-m | -M) [<branch>] <newbranch>\n> +'git-branch' (-d | -D) [-r] <branch>...\n\nLooks more-or-less unnecessary churn to me.  If you have to rename the\nplaceholders, I would say:\n\n\tgit branch <branch> [<start-point>]\n        git branch -m [<old>] <new>\n        git branch -d <branch>\n\nwould be short, sweet and sufficient.\n\n>  DESCRIPTION\n>  -----------\n> @@ -25,29 +25,25 @@ With `--contains <commit>`, shows only the branches that\n>  contains the named commit (in other words, the branches whose\n>  tip commits are descendant of the named commit).\n>  \n> -In its second form, a new branch named <branchname> will be created.\n> -It will start out with a head equal to the one given as <start-point>.\n> -If no <start-point> is given, the branch will be created with a head\n> -equal to that of the currently checked out branch.\n> +In its second form, a new branch named <newbranch> will be created.\n> +It will start out with a head equal to <start-point>. If no\n> +<start-point> is given, it is assumed to be the currently checked\n> +out branch. The new branch may optionally be configured for use with\n> +linkgit:git-pull[1] -- see `--track` and `--no-track` in the OPTIONS\n> +section below.\n\nDrop all the changes except for the last sentence.\n\n>  Note that this will create the new branch, but it will not switch the\n>  working tree to it; use \"git checkout <newbranch>\" to switch to the\n> -new branch.\n> +new branch. (As a shortcut consider using \"git checkout [--track | \n> +--notrack ] -b <newbranch>\" instead.)\n\nHinting an alternative is good but is too verbose.\n\n\t\"git checkout -b\" can be used to create and switch in one step.\n\nwould be short, sweet and sufficient.\n\n> -When a local branch is started off a remote branch, git sets up the\n> -branch so that linkgit:git-pull[1] will appropriately merge from that\n> -remote branch.  If this behavior is not desired, it is possible to\n> -disable it using the global `branch.autosetupmerge` configuration\n> -flag.  That setting can be overridden by using the `--track`\n> -and `--no-track` options.\n\nWhy remove this?\n\n> @@ -105,38 +101,31 @@ 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 the new branch's configuration so that linkgit:git-pull[1]\n> +\twill appropriately merge from the start point when run without\n\n\"from the start point\" is misleading.\n\n> +\targuments while in the new branch. `--track` is the default behavior\n> +\twhen the start point is a remote branch. See the documentation for\n> +\tthe `branch.autosetupmerge` configuration variable in\n> +\tlinkgit:git-config[1] for how to modify the default.\n\nHow about\n\n\tWhen <start-point> is a name of an existing branch (either local\n\tor remote tracking branch), treat the <start-point> branch as\n\tthe upstream branch for the new branch (i.e. the new branch is\n\tmarked to build on top of the branch) by setting a few extra\n\tconfiguration variables to cause \"git pull\" without repository\n\tand refspec parameters to fetch and merge (or rebase) from the\n\tupstream branch.  By default, this happens when forking from a\n\tremote tracking branch without this option.  This default can be \n\tmodified by the `branch.autosetupmerge` configuration variable.\n\nBy the way, I think the existing code is buggy.  When you say:\n\n\t$ git branch --track new $(git rev-parse --verify HEAD~12)\n\nthe command should barf, saying \"Starting point is not a branch; it\nis impossible to set up a tracking information\", perhaps without even\ncreating the \"new\" branch.  Instead, it silently creates a new branch.\n\n>  --no-track::\n> +\tIgnore the `branch.autosetupmerge` configuration variable. The new\n> +\tbranch will not be setup for automatic merging.\n\nThis is much better than the original text.\n\n>  <start-point>::\n>  \tThe new branch will be created with a HEAD equal to this.  It may\n> -\tbe given as a branch name, a commit-id, or a tag.  If this option\n> -\tis omitted, the current branch is assumed.\n> +\tbe given as a branch name, a commit-id, or a tag.  Defaults\n> +\tto the current HEAD.\n\nI do not think this is what _you_ want (although I do not personally\ncare).  Defaulting to HEAD means <start-point> is not a name of the\nbranch in such a case.  I suspect that you would want this to create a\nnew branch that follows your current branch (assuming your HEAD is not\ndetached):\n\n\t$ git branch --track new\n\nwouldn't you?\n\n> diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\n> index b4cfa04..fd862b4 100644\n> --- a/Documentation/git-checkout.txt\n> +++ b/Documentation/git-checkout.txt\n> @@ -8,25 +8,27 @@ git-checkout - Checkout and switch to a branch\n>  SYNOPSIS\n>  --------\n>  [verse]\n> -'git-checkout' [-q] [-f] [[--track | --no-track] -b <new_branch> [-l]] [-m] [<branch>]\n> +'git-checkout' [-q] [-f] [-m] <branch>\n> +'git-checkout' [-q] [-f] [-m] [-l] [--track | --no-track] -b <newbranch> [<start-point>]\n>  'git-checkout' [<tree-ish>] <paths>...\n>\n>  DESCRIPTION\n>  -----------\n>  \n> -When <paths> are not given, this command switches branches by\n> -updating the index and working tree to reflect the specified\n> -branch, <branch>, and updating HEAD to be <branch> or, if\n> -specified, <new_branch>.  Using -b will cause <new_branch> to\n> -be created; in this case you can use the --track or --no-track\n> -options, which will be passed to `git branch`.\n> +It its first form this command switches branches by updating the\n> +index and working tree to reflect <branch> and updating HEAD to\n> +<branch>.\n\nNow this is getting tiresome.  The rewrite might be a good change for\nreadability but this does not have anything to do with --track.  The\nreview process of such a rewrite should be done as an independent\ntopic.\n\nI give up (for now).\n"},{"id":"69244","messageId":"20080219074423.GA3982@steel.home","threadId":"12185","inReplyTo":"1203386832-43969-1-git-send-email-jaysoffian@gmail.com","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-02-19T07:44:23Z","receivedAt":"2008-02-19T07:44:23Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Jay Soffian, Tue, Feb 19, 2008 03:07:12 +0100:\n> diff --git a/cache.h b/cache.h\n> index 2b59c44..3c17e2c 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_NEVER = 0,\n\nenums start at 0 anyway, don't they?\n\n> +\tBRANCH_TRACK_REMOTE,\n> +\tBRANCH_TRACK_ALWAYS,\n> +};\n"},{"id":"69249","messageId":"alpine.LSU.1.00.0802191054070.30505@racer.site","threadId":"12185","inReplyTo":"76718490802181819o4cf742edi92bbcd9039f0cdac@mail.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-19T10:55:21Z","receivedAt":"2008-02-19T10:55:21Z","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> On Feb 18, 2008 9:07 PM, Jay Soffian <jaysoffian@gmail.com> wrote:\n> > diff --git a/branch.c b/branch.c\n> > index 1fc8788..9d7585e 100644\n> > --- a/branch.c\n> > +++ b/branch.c\n> > @@ -37,7 +37,8 @@ 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,\n> > +                          enum branch_track track)\n> >  {\n> >         char key[1024];\n> >         struct tracking tracking;\n> > @@ -48,10 +49,14 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)\n> >\n> >         memset(&tracking, 0, sizeof(tracking));\n> >         tracking.spec.dst = (char *)orig_ref;\n> > -       if (for_each_remote(find_tracked_branch, &tracking) ||\n> > -                       !tracking.matches)\n> > +       if (for_each_remote(find_tracked_branch, &tracking))\n> >                 return 1;\n> >\n> > +       if (!tracking.matches && track == BRANCH_TRACK_ALWAYS) {\n> > +               tracking.matches = 1;\n> > +               tracking.src = xstrdup(orig_ref);\n> > +       }\n> > +\n> \n> Well that's obviously wrong (though it causes no problems, setup_tracking()\n> would return 0 when it should return 1, but its return value is currently\n> ignored). I changed it to:\n> \n> \tif (!tracking.matches) {\n> \t\tif (track != BRANCH_TRACK_ALWAYS)\n> \t\t\treturn 1;\n> \t\ttracking.matches = 1;\n> \t\ttracking.src = xstrdup(orig_ref);\n> \t}\n\nAh, yes.  But I still maintain that xstrdup()ing orig_ref only to free it \nlater is ugly.  Why not have the \"tracking.src ? tracking.src : orig_ref\" \nas I suggested?  The free() obviously can stay, since it will say \n\"free(NULL)\" in the case of tracking.matches == 0.\n\nCiao,\nDscho\n"},{"id":"69260","messageId":"76718490802190540i50cefe15ja8f18e4a397f151d@mail.gmail.com","threadId":"12185","inReplyTo":"7vprutlchh.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-19T13:40:47Z","receivedAt":"2008-02-19T13:40:47Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Feb 19, 2008 12:52 AM, Junio C Hamano <gitster@pobox.com> wrote:\n\n> Three issues.\n>\n>  (1) \"tells X and Y to configure\" is bad.  We may later want to\n>      add a command that forks a new branch from an existing one,\n>      and you sure do want it to honor this variable.  Better not\n>      list the commands but tell the reader that it applies to\n>      the act of forking a new branch based on an existing one.\n>\n>  (2) \"configure X and Y\" is bad.  We may later want to add new\n>      configuration variables to facilitate marking a branch that\n>      builds on top of another in addition to the existing remote\n>      and merge, and you sure do want them to be also set up\n>      appropriately.\n>\n>  (3) \"for use with X and Y\" is bad.  We may later want to add\n>      new commands that you would use to work with a branch that\n>      builds on top of another, and you sure do want them to\n>      honor the configuration variables this automatically sets\n>      up.\n>\n> So, how about...\n>\n>         When creating a new branch starting at an existing 'upstream'\n>         branch, the new branch can be marked as building on top of the\n>         'upstream' branch, by setting a few configuration variables\n>         (e.g. branch.<name>.remote and branch.<name>.merge).  This can\n>         be explicitly asked for by giving `--track` (and turned off by\n>         giving `--no-track`) option to commands that create a new branch\n>         (e.g.  linkgit:git-branch[1]); this variable is consulted when\n>         neither option is given.\n\nI disagree. I think explicit is better than implicit and if a new\ncommand or config variable is added, then the docs should be similarly\nupdated.\n\n> Looks more-or-less unnecessary churn to me.\n\nI was trying to make git-branch(1) and git-checkout(1) consistent.\n\n> > -When a local branch is started off a remote branch, git sets up the\n> > -branch so that linkgit:git-pull[1] will appropriately merge from that\n> > -remote branch.  If this behavior is not desired, it is possible to\n> > -disable it using the global `branch.autosetupmerge` configuration\n> > -flag.  That setting can be overridden by using the `--track`\n> > -and `--no-track` options.\n>\n> Why remove this?\n\nBecause --track and --no-track are documented in the OPTIONS section, so there\nis no reason to document them up top as well. None of the other options [-l],\n[-q], [-f] are documented in the intro.\n\n> By the way, I think the existing code is buggy.  When you say:\n>\n>         $ git branch --track new $(git rev-parse --verify HEAD~12)\n>\n> the command should barf, saying \"Starting point is not a branch; it\n> is impossible to set up a tracking information\", perhaps without even\n> creating the \"new\" branch.  Instead, it silently creates a new branch.\n\nThat's what it did before I started touching any code. Perhaps it\nshould be a separate cleanup patch.\n\n> >  <start-point>::\n> >       The new branch will be created with a HEAD equal to this.  It may\n> > -     be given as a branch name, a commit-id, or a tag.  If this option\n> > -     is omitted, the current branch is assumed.\n> > +     be given as a branch name, a commit-id, or a tag.  Defaults\n> > +     to the current HEAD.\n>\n> I do not think this is what _you_ want (although I do not personally\n> care).  Defaulting to HEAD means <start-point> is not a name of the\n> branch in such a case.\n\nOkay, that's a subtle difference. The existing documentation conflates (I think)\n\"HEAD\" with \"current branch\". I see now they are different.\n\n> Now this is getting tiresome.  The rewrite might be a good change for\n> readability but this does not have anything to do with --track.  The\n> review process of such a rewrite should be done as an independent\n> topic.\n>\n> I give up (for now).\n\n<grumble>\nI will rip all the documentation changes out of this patch and do them\nseparately at a later time if at all. The current documentation has lots of\nareas for improvement. It's hard to touch it w/o realizing you've made a clean\nspot and then wanting to rewrite whole swaths. I happen to think I'm a decent\ntechnical writer (no, it's not my day job) and I thought the changes I was\nmaking, from the perspective of a new set of eyes, made things more clear. I\ngive up on that for now.\n\n\t\nI too find it tiresome trying to get this patch into git. As a newbie\ncontributor, I'm beginning to find this very discouraging. I appreciate that\nchanges need a lot of scrutiny, but if the same amount of scrutiny were applied\nto the existing code it would never get through.\n\nWhich is not to say that I don't appreciate your feedback and work on git.\n</grumble>\nj.\n"},{"id":"69261","messageId":"76718490802190542l7fb58d58l29d7b18fb62fd8e2@mail.gmail.com","threadId":"12185","inReplyTo":"alpine.LSU.1.00.0802191054070.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-19T13:42:32Z","receivedAt":"2008-02-19T13:42:32Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Feb 19, 2008 5:55 AM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>\n> On Mon, 18 Feb 2008, Jay Soffian wrote:\n>\n> >\n> >       if (!tracking.matches) {\n> >               if (track != BRANCH_TRACK_ALWAYS)\n> >                       return 1;\n> >               tracking.matches = 1;\n> >               tracking.src = xstrdup(orig_ref);\n> >       }\n>\n> Ah, yes.  But I still maintain that xstrdup()ing orig_ref only to free it\n> later is ugly.  Why not have the \"tracking.src ? tracking.src : orig_ref\"\n> as I suggested?\n\nSorry, I'd missed that. Good idea, will do.\n\nj.\n"},{"id":"69262","messageId":"76718490802190549p549a34afo913efefebaf5fa97@mail.gmail.com","threadId":"12185","inReplyTo":"20080219074423.GA3982@steel.home","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-19T13:49:17Z","receivedAt":"2008-02-19T13:49:17Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Feb 19, 2008 2:44 AM, Alex Riesen <raa.lkml@gmail.com> wrote:\n> Jay Soffian, Tue, Feb 19, 2008 03:07:12 +0100:\n> > +enum branch_track {\n> > +     BRANCH_TRACK_NEVER = 0,\n>\n> enums start at 0 anyway, don't they?\n\nI don't know, but guys, give me a break on the enums already. What's\nthe preferred syntax already because the existing code is not\nconsistent:\n\nenum color_branch {\n\tCOLOR_BRANCH_RESET = 0,\n\tCOLOR_BRANCH_PLAIN = 1,\n\tCOLOR_BRANCH_REMOTE = 2,\n\tCOLOR_BRANCH_LOCAL = 3,\n\tCOLOR_BRANCH_CURRENT = 4,\n};\n\nenum {\n\tTAGS_UNSET = 0,\n\tTAGS_DEFAULT = 1,\n\tTAGS_SET = 2\n};\n\nenum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;\n\nenum exist_status {\n\tindex_nonexistent = 0,\n\tindex_directory,\n\tindex_gitdir,\n};\n\nenum CAPABILITY {\n\tNOLOGIN = 0,\n\tUIDPLUS,\n\tLITERALPLUS,\n\tNAMESPACE,\n};\n\nj.\n"},{"id":"69263","messageId":"alpine.LSU.1.00.0802191352360.30505@racer.site","threadId":"12185","inReplyTo":"76718490802190549p549a34afo913efefebaf5fa97@mail.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-19T13:53:53Z","receivedAt":"2008-02-19T13:53:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 19 Feb 2008, Jay Soffian wrote:\n\n> On Feb 19, 2008 2:44 AM, Alex Riesen <raa.lkml@gmail.com> wrote:\n> > Jay Soffian, Tue, Feb 19, 2008 03:07:12 +0100:\n> > > +enum branch_track {\n> > > +     BRANCH_TRACK_NEVER = 0,\n> >\n> > enums start at 0 anyway, don't they?\n> \n> I don't know, but guys, give me a break on the enums already.\n\nHeh.\n\nDon't be discouraged.  I think you help educating me here, too:\n\n> What's the preferred syntax already because the existing code is not \n> consistent: [...]\n\nI had the impression that the first was set to \"= 0\", and the rest was not \nexplicitely set.  But I was obviously wrong.\n\nCiao,\nDscho\n"},{"id":"69264","messageId":"76718490802190559m3f5def8ej667d4d4a1ae8e6c7@mail.gmail.com","threadId":"12185","inReplyTo":"alpine.LSU.1.00.0802191054070.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-19T13:59:22Z","receivedAt":"2008-02-19T13:59:22Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Feb 19, 2008 5:55 AM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>\n> Ah, yes.  But I still maintain that xstrdup()ing orig_ref only to free it\n> later is ugly.  Why not have the \"tracking.src ? tracking.src : orig_ref\"\n> as I suggested?  The free() obviously can stay, since it will say\n> \"free(NULL)\" in the case of tracking.matches == 0.\n\nHow about this?\n\nstatic int setup_tracking(const char *new_ref, const char *orig_ref,\n                          enum branch_track track)\n{\n\tchar key[1024];\n\tstruct tracking tracking;\n\n\tif (strlen(new_ref) > 1024 - 7 - 7 - 1)\n\t\treturn error(\"Tracking not set up: name too long: %s\",\n\t\t\t\tnew_ref);\n\n\tmemset(&tracking, 0, sizeof(tracking));\n\ttracking.spec.dst = (char *)orig_ref;\n\tif (for_each_remote(find_tracked_branch, &tracking))\n\t\treturn 1;\n\n\tif (!tracking.matches && track != BRANCH_TRACK_ALWAYS)\n\t\treturn 1;\n\n\tif (tracking.matches > 1)\n\t\treturn error(\"Not tracking: ambiguous information for ref %s\",\n\t\t\t\torig_ref);\n\n\tsprintf(key, \"branch.%s.remote\", new_ref);\n\tgit_config_set(key, tracking.remote ?  tracking.remote : \".\");\n\tsprintf(key, \"branch.%s.merge\", new_ref);\n\tgit_config_set(key, tracking.src ? tracking.src : orig_ref);\n\tfree(tracking.src);\n\tprintf(\"Branch %s set up to track %s branch %s.\\n\", new_ref,\n\t\ttracking.remote ? \"remote\" : \"local\", orig_ref);\n\n\treturn 0;\n}\n\nj.\n"},{"id":"69265","messageId":"alpine.LSU.1.00.0802191400560.30505@racer.site","threadId":"12185","inReplyTo":"76718490802190559m3f5def8ej667d4d4a1ae8e6c7@mail.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-19T14:01:17Z","receivedAt":"2008-02-19T14:01:17Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 19 Feb 2008, Jay Soffian wrote:\n\n> On Feb 19, 2008 5:55 AM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> >\n> > Ah, yes.  But I still maintain that xstrdup()ing orig_ref only to free \n> > it later is ugly.  Why not have the \"tracking.src ? tracking.src : \n> > orig_ref\" as I suggested?  The free() obviously can stay, since it \n> > will say \"free(NULL)\" in the case of tracking.matches == 0.\n> \n> How about this?\n> \n> static int setup_tracking(const char *new_ref, const char *orig_ref,\n>                           enum branch_track track)\n> {\n> \tchar key[1024];\n> \tstruct tracking tracking;\n> \n> \tif (strlen(new_ref) > 1024 - 7 - 7 - 1)\n> \t\treturn error(\"Tracking not set up: name too long: %s\",\n> \t\t\t\tnew_ref);\n> \n> \tmemset(&tracking, 0, sizeof(tracking));\n> \ttracking.spec.dst = (char *)orig_ref;\n> \tif (for_each_remote(find_tracked_branch, &tracking))\n> \t\treturn 1;\n> \n> \tif (!tracking.matches && track != BRANCH_TRACK_ALWAYS)\n> \t\treturn 1;\n> \n> \tif (tracking.matches > 1)\n> \t\treturn error(\"Not tracking: ambiguous information for ref %s\",\n> \t\t\t\torig_ref);\n> \n> \tsprintf(key, \"branch.%s.remote\", new_ref);\n> \tgit_config_set(key, tracking.remote ?  tracking.remote : \".\");\n> \tsprintf(key, \"branch.%s.merge\", new_ref);\n> \tgit_config_set(key, tracking.src ? tracking.src : orig_ref);\n> \tfree(tracking.src);\n> \tprintf(\"Branch %s set up to track %s branch %s.\\n\", new_ref,\n> \t\ttracking.remote ? \"remote\" : \"local\", orig_ref);\n> \n> \treturn 0;\n> }\n\nI like it.\n\nCiao,\nDscho\n"},{"id":"69340","messageId":"20080220001339.GA16574@steel.home","threadId":"12185","inReplyTo":"76718490802190549p549a34afo913efefebaf5fa97@mail.gmail.com","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-02-20T00:13:39Z","receivedAt":"2008-02-20T00:13:39Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Jay Soffian, Tue, Feb 19, 2008 14:49:17 +0100:\n> On Feb 19, 2008 2:44 AM, Alex Riesen <raa.lkml@gmail.com> wrote:\n> > Jay Soffian, Tue, Feb 19, 2008 03:07:12 +0100:\n> > > +enum branch_track {\n> > > +     BRANCH_TRACK_NEVER = 0,\n> >\n> > enums start at 0 anyway, don't they?\n> \n> I don't know, but guys, give me a break on the enums already. What's\n> the preferred syntax already because the existing code is not\n> consistent:\n\nWell, it could also mean that there is no rules yet, and you can\ndo the next sane thing of your choice.\n\n> enum color_branch {\n> \tCOLOR_BRANCH_RESET = 0,\n> \tCOLOR_BRANCH_PLAIN = 1,\n> \tCOLOR_BRANCH_REMOTE = 2,\n> \tCOLOR_BRANCH_LOCAL = 3,\n> \tCOLOR_BRANCH_CURRENT = 4,\n> };\n>\n> enum {\n> \tTAGS_UNSET = 0,\n> \tTAGS_DEFAULT = 1,\n> \tTAGS_SET = 2\n> };\n\nWhich is just as useless. It is not useful even for documentation,\nas the verbatim values are not used anywere else (i.e. they are not\na part of file format, where they could stand out as the numbers\nlisted).\n\nIt looks like someone was just too paranoid or suffered a mental\ndamage from too long exposure to proprietary code.\n\n> enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;\n> \n> enum exist_status {\n> \tindex_nonexistent = 0,\n> \tindex_directory,\n> \tindex_gitdir,\n> };\n> \n> enum CAPABILITY {\n> \tNOLOGIN = 0,\n> \tUIDPLUS,\n> \tLITERALPLUS,\n> \tNAMESPACE,\n> };\n\nAll the same...\n"},{"id":"69343","messageId":"7v4pc4fo6y.fsf@gitster.siamese.dyndns.org","threadId":"12185","inReplyTo":"20080220001339.GA16574@steel.home","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-20T00:48:05Z","receivedAt":"2008-02-20T00:48:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> Well, it could also mean that there is no rules yet, and you can\n> do the next sane thing of your choice.\n>\n>> enum color_branch {\n>> \tCOLOR_BRANCH_RESET = 0,\n>> \tCOLOR_BRANCH_PLAIN = 1,\n>> \tCOLOR_BRANCH_REMOTE = 2,\n>> \tCOLOR_BRANCH_LOCAL = 3,\n>> \tCOLOR_BRANCH_CURRENT = 4,\n>> };\n\nThis enum is used as an index into branch_colors[] array.  Of\ncourse, by omitting everything you will get the default \"start\nwith 0, incrementing by 1\" which will be the right assignment\nanyway.  But we would want to leave a clue for people who would\nwant to touch this later that individual values have some\nmeaning, more than just that they have to be distinct.\n\n>> enum {\n>> \tTAGS_UNSET = 0,\n>> \tTAGS_DEFAULT = 1,\n>> \tTAGS_SET = 2\n>> };\n\nThis one can be made unspecified or even shuffled, because\nnobody does:\n\n\tint function_that_acts_on_tag_setting(int tag) {\n                if (!tag) {\n                        ... do something ...\n                }\n                if (TAGS_DEFAULT <= tag) {\n                        ... do something else ...\n                }\n                return some_array[tag];\n\t}\n\nSo there is no reason to spell out any of the values.\n\n>> enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;\n\nLikewise.\n\n>> enum exist_status {\n>> \tindex_nonexistent = 0,\n>> \tindex_directory,\n>> \tindex_gitdir,\n>> };\n\nLikewise, modulo that making \"nonexistent\" explicitly to 0 is a\nvery sensible thing whoever wrote that code has done.  This is\nused as a type of directory_exists_in_index() function, and\ncallers can say:\n\n       \tif (!directory_exists_in_index(dirname)) {\n        \t... ah, there is no such directory ...\n\t} else {\n        \t... something exists, but I do not care what kind ...\n\t}\n\nSo spelling out that \"nonexistent MUST BE 0\" (even though C\nlanguage will give value 0 to it anyway) is a good convention.\n\n>> enum CAPABILITY {\n>> \tNOLOGIN = 0,\n>> \tUIDPLUS,\n>> \tLITERALPLUS,\n>> \tNAMESPACE,\n>> };\n\nThis seems to be meant to match the order in the corresponding\ncap_list[] array, so this cannot be reshuffled (iow, it is\nsimilar to color_branch).\n\nIf you do not need to have any specific value assigned nor order\namong the enum tokens, (i.e. somebody later can add a new enum\nanywhere in the decl or even reshuffle the existing ones without\nbreaking your code), it is a good idea to hint that fact by not\nhaving any \"= value\" in the decl.  If you do rely on specific\none being zero (see \"exist_status\" example above), it is better\nto spell it out that it has to be zero even if it is the first\nentry to hint that fact.  Of course, if you need a set of values\nthat are not sequential, you would need to spell out each and\nevery one of them.\n"},{"id":"69345","messageId":"7vzltwe9a4.fsf@gitster.siamese.dyndns.org","threadId":"12185","inReplyTo":"7v4pc4fo6y.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] branch: optionally setup branch.*.merge from upstream local branches","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-20T00:55:31Z","receivedAt":"2008-02-20T00:55:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Alex Riesen <raa.lkml@gmail.com> writes:\n>\n>> Well, it could also mean that there is no rules yet, and you can\n>> do the next sane thing of your choice.\n>>\n>>> enum color_branch {\n>>> \tCOLOR_BRANCH_RESET = 0,\n>>> \tCOLOR_BRANCH_PLAIN = 1,\n>>> \tCOLOR_BRANCH_REMOTE = 2,\n>>> \tCOLOR_BRANCH_LOCAL = 3,\n>>> \tCOLOR_BRANCH_CURRENT = 4,\n>>> };\n>\n> This enum is used as an index into branch_colors[] array.  ...\n> ...  But we would want to leave a clue for people who would\n> want to touch this later that individual values have some\n> meaning, more than just that they have to be distinct.\n> ...\n>>> enum CAPABILITY {\n>>> \tNOLOGIN = 0,\n>>> \tUIDPLUS,\n>>> \tLITERALPLUS,\n>>> \tNAMESPACE,\n>>> };\n>\n> This seems to be meant to match the order in the corresponding\n> cap_list[] array, so this cannot be reshuffled (iow, it is\n> similar to color_branch).\n\nSide note.  My preference for enum that indexes an array is to\nuse the latter, not spelling everything out like \"color_branch\"\ndoes.  The first one being 0 and everybody else increments by 1\nis a good enough clue that you cannot arbitrarily reshuffle them\n(as opposed to everbody left to the default).  After being\nwarned with the clue, somebody who is adding new elements to the\narray and defining a symbolic index to the element will know to\nappend to the list, not just insert into an arbitrary place.\nSpelling out all the rest explicitly like \"color_branch\" one\ndoes is wasteful (new entries would need to carry \"= (n+1)\"),\npointless (you cannot write anything but \"= (n+1)\" because it is\nan array index), and misleading (it makes you wonder if the\nspecific values have meaning other than being used for an array\nindex).\n"}]}