Hi,

Carlos Martín Nieto wrote:

> The existing --set-uptream option can cause confusion, as it uses the
> usual branch convention of assuming a starting point of HEAD if none
> is specified, causing
>
>     git branch --set-upstream origin/master
>
> to create a new local branch 'origin/master' that tracks the current
> branch. As --set-upstream already exists, we can't simply change its
> behaviour. To work around this, introduce --set-upstream-to which
> accepts a compulsory argument

Thanks.  A part of me really dislikes this --set-upstream-to which
is named more awkwardly than the deprecated mistake it replaces,
though.

Here's a patch on top to play with that names the new option
"--set-upstream=".  Untested.

Signed-off-by: Jonathan Nieder <jrnie...@gmail.com>
---
diff --git i/Documentation/git-branch.txt w/Documentation/git-branch.txt
index f572913f..57935a64 100644
--- i/Documentation/git-branch.txt
+++ w/Documentation/git-branch.txt
@@ -49,7 +49,7 @@ branch so that 'git pull' will appropriately merge from
 the remote-tracking branch. This behavior may be changed via the global
 `branch.autosetupmerge` configuration flag. That setting can be
 overridden by using the `--track` and `--no-track` options, and
-changed later using `git branch --set-upstream-to`.
+changed later using `git branch --set-upstream`.
 
 With a `-m` or `-M` option, <oldbranch> will be renamed to <newbranch>.
 If <oldbranch> had a corresponding reflog, it is renamed to match
@@ -174,11 +174,13 @@ start-point is either a local or remote-tracking branch.
        like `--track` would when creating the branch, except that where
        branch points to is not changed.
 
--u <upstream>::
---set-upstream-to=<upstream>::
+--set-upstream=<upstream>::
        Set up <branchname>'s tracking information so <upstream> is
        considered <branchname>'s upstream branch. If no branch is
        specified it defaults to the current branch.
++
+If no argument is attached, for historical reasons the meaning is
+different.  See above.
 
 --edit-description::
        Open an editor and edit the text to explain what the branch is
diff --git i/builtin/branch.c w/builtin/branch.c
index c886fc06..0d705790 100644
--- i/builtin/branch.c
+++ w/builtin/branch.c
@@ -669,6 +669,31 @@ static int opt_parse_merge_filter(const struct option 
*opt, const char *arg, int
        return 0;
 }
 
+struct set_upstream_params {
+       enum branch_track *track;
+       const char **new_upstream;
+};
+static int parse_opt_set_upstream(const struct option *opt, const char *arg, 
int unset)
+{
+       struct set_upstream_params *o = opt->value;
+
+       if (unset) {    /* --no-set-upstream */
+               *o->track = BRANCH_TRACK_NEVER;
+               *o->new_upstream = NULL;
+               return 0;
+       }
+
+       *o->track = BRANCH_TRACK_OVERRIDE;
+       if (!arg)       /* --set-upstream <branchname> <start-point> */
+               *o->new_upstream = NULL;
+       else    /* --set-upstream=<upstream> <branchname> */
+               *o->new_upstream = arg;
+       return 0;
+}
+#define OPT_SET_UPSTREAM(s, l, v) \
+       { OPTION_CALLBACK, (s), (l), (v), "upstream", "change upstream info", \
+         PARSE_OPT_OPTARG, &parse_opt_set_upstream }
+
 static const char edit_description[] = "BRANCH_DESCRIPTION";
 
 static int edit_branch_description(const char *branch_name)
@@ -716,6 +741,7 @@ int cmd_branch(int argc, const char **argv, const char 
*prefix)
        const char *new_upstream = NULL;
        enum branch_track track;
        int kinds = REF_LOCAL_BRANCH;
+       struct set_upstream_params set_upstream_args = { &track, &new_upstream 
};
        struct commit_list *with_commit = NULL;
 
        struct option options[] = {
@@ -725,9 +751,7 @@ int cmd_branch(int argc, const char **argv, const char 
*prefix)
                OPT__QUIET(&quiet, "suppress informational messages"),
                OPT_SET_INT('t', "track",  &track, "set up tracking mode (see 
git-pull(1))",
                        BRANCH_TRACK_EXPLICIT),
-               OPT_SET_INT( 0, "set-upstream",  &track, "change upstream info",
-                       BRANCH_TRACK_OVERRIDE),
-               OPT_STRING('u', "set-upstream-to", &new_upstream, "upstream", 
"change the upstream info"),
+               OPT_SET_UPSTREAM(0, "set-upstream", &set_upstream_args),
                OPT__COLOR(&branch_use_color, "use colored output"),
                OPT_SET_INT('r', "remotes",     &kinds, "act on remote-tracking 
branches",
                        REF_REMOTE_BRANCH),
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to