{"thread":{"id":"30955","subject":"[PATCH] branch: add -u as a shortcut for --set-upstream","startedAt":"2012-07-05T07:57:15Z","lastAt":"2012-07-08T05:48:15Z","messageCount":3,"participants":["Carlos Martín Nieto","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"194648","messageId":"1341475035-14310-1-git-send-email-cmn@elego.de","threadId":"30955","inReplyTo":null,"subject":"[PATCH] branch: add -u as a shortcut for --set-upstream","fromName":"Carlos Martín Nieto","fromEmail":"cmn@elego.de","sentAt":"2012-07-05T07:57:15Z","receivedAt":"2012-07-05T07:57:15Z","isPatch":true,"sender":{"key":"cmn@elego.de","avatar":"https://avatars.githubusercontent.com/u/335443?v=4"},"body":"Add this shortcut just like git-push has it.\n\nSigned-off-by: Carlos Martín Nieto <cmn@elego.de>\n---\n\nI've seen threads commenting how it's odd that this doesn't exist[0],\nbut nobody seems to have done anything about it yet.\n\nThis may need some updates to the shell completions, but I've no idea\nhow those work and I'd rather not change things randomly.\n\n[0] see e.g. http://thread.gmane.org/gmane.comp.version-control.git/165794/focus=165856\n\n Documentation/git-branch.txt | 1 +\n builtin/branch.c             | 2 +-\n 2 files changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 47235be..447325f 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -167,6 +167,7 @@ start-point is either a local or remote-tracking branch.\n \tDo not set up \"upstream\" configuration, even if the\n \tbranch.autosetupmerge configuration variable is true.\n \n+-u::\n --set-upstream::\n \tIf specified branch does not exist yet or if `--force` has been\n \tgiven, acts exactly like `--track`. Otherwise sets up configuration\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 0e060f2..9f2bb6f 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -724,7 +724,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tOPT__QUIET(&quiet, \"suppress informational messages\"),\n \t\tOPT_SET_INT('t', \"track\",  &track, \"set up tracking mode (see git-pull(1))\",\n \t\t\tBRANCH_TRACK_EXPLICIT),\n-\t\tOPT_SET_INT( 0, \"set-upstream\",  &track, \"change upstream info\",\n+\t\tOPT_SET_INT('u', \"set-upstream\",  &track, \"change upstream info\",\n \t\t\tBRANCH_TRACK_OVERRIDE),\n \t\tOPT__COLOR(&branch_use_color, \"use colored output\"),\n \t\tOPT_SET_INT('r', \"remotes\",     &kinds, \"act on remote-tracking branches\",\n-- \n1.7.11.1.104.ge7b44f1\n"},{"id":"194723","messageId":"20120706153239.GA29362@burratino","threadId":"30955","inReplyTo":"1341475035-14310-1-git-send-email-cmn@elego.de","subject":"Re: [PATCH] branch: add -u as a shortcut for --set-upstream","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-07-06T15:32:39Z","receivedAt":"2012-07-06T15:32:39Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Carlos,\n\nCarlos Martín Nieto wrote:\n\n> Add this shortcut just like git-push has it.\n[...]\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -724,7 +724,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n>  \t\tOPT__QUIET(&quiet, \"suppress informational messages\"),\n>  \t\tOPT_SET_INT('t', \"track\",  &track, \"set up tracking mode (see git-pull(1))\",\n>  \t\t\tBRANCH_TRACK_EXPLICIT),\n> -\t\tOPT_SET_INT( 0, \"set-upstream\",  &track, \"change upstream info\",\n> +\t\tOPT_SET_INT('u', \"set-upstream\",  &track, \"change upstream info\",\n>  \t\t\tBRANCH_TRACK_OVERRIDE),\n\nI think this is a bad idea.  The --set-upstream option is confusing:\n\n\t$ git branch --set-upstream=foo\n\terror: option 'set-upstream' takes no value\n\t$ ???\n\n-u to set the corresponding upstream branch at the same time as\ncreating a branch, analagous to \"git push -u\" might seem intuitive:\n\n\t# create foo branch, setting its upstream at the same time\n\tgit branch -u foo origin/foo\n\nBut that is what --track does and is not what --set-upstream is for.\n\nUnlike --track, I don't think --set-upstream is a common enough\noperation to deserve a one-letter synonym.\n\nInstead, I'd suggest the following changes:\n\n 1) Add support for\n\n\t# change upstream info\n\tgit branch --set-upstream=origin/foo foo\n\n    for existing branches only.\n\n 2) Introduce an --unset-upstream option which removes the\n    \"corresponding upstream branch\" configuration for an existing\n    branch.\n\n 3) Warn on\n\n\t# acts just like --track\n\tgit branch --set-upstream foo origin/foo\n\n    for branches that do not exist yet.  Plan to make this a hard\n    error in the future.\n\n 4) Warn on\n\n\t# sets upstream for \"foo\" to the current branch\n\tgit branch --set-upstream foo\n\n    and plan to make it a hard error in the future.\n\n 5) Warn on\n\n\tgit branch --set-upstream origin/foo foo\n\n  which is almost certainly a typo for\n\n\tgit branch --set-upstream=origin/foo foo\n\n 6) Perhaps, make -u a synonym for -t for consistency with \"git push\".\n\nWhat do you think?\nJonathan\n"},{"id":"194780","messageId":"1341726495.10752.78.camel@flaca.cmartin.tk","threadId":"30955","inReplyTo":"20120706153239.GA29362@burratino","subject":"Re: [PATCH] branch: add -u as a shortcut for --set-upstream","fromName":"Carlos Martín Nieto","fromEmail":"cmn@elego.de","sentAt":"2012-07-08T05:48:15Z","receivedAt":"2012-07-08T05:48:15Z","isPatch":true,"sender":{"key":"cmn@elego.de","avatar":"https://avatars.githubusercontent.com/u/335443?v=4"},"body":"On Fri, 2012-07-06 at 10:32 -0500, Jonathan Nieder wrote:\n> Hi Carlos,\n> \n> Carlos Martín Nieto wrote:\n> \n> > Add this shortcut just like git-push has it.\n> [...]\n> > --- a/builtin/branch.c\n> > +++ b/builtin/branch.c\n> > @@ -724,7 +724,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n> >  \t\tOPT__QUIET(&quiet, \"suppress informational messages\"),\n> >  \t\tOPT_SET_INT('t', \"track\",  &track, \"set up tracking mode (see git-pull(1))\",\n> >  \t\t\tBRANCH_TRACK_EXPLICIT),\n> > -\t\tOPT_SET_INT( 0, \"set-upstream\",  &track, \"change upstream info\",\n> > +\t\tOPT_SET_INT('u', \"set-upstream\",  &track, \"change upstream info\",\n> >  \t\t\tBRANCH_TRACK_OVERRIDE),\n> \n> I think this is a bad idea.  The --set-upstream option is confusing:\n> \n> \t$ git branch --set-upstream=foo\n> \terror: option 'set-upstream' takes no value\n> \t$ ???\n\nIt is confusing, see the other thread (about making --set-upstream\nbehave more sanely) for the second part of this. I wanted to add a hack\nso\n\n    git branch --set-upstream foo\n\nwould set the current branch to track foo.\n\n> \n> -u to set the corresponding upstream branch at the same time as\n> creating a branch, analagous to \"git push -u\" might seem intuitive:\n> \n> \t# create foo branch, setting its upstream at the same time\n> \tgit branch -u foo origin/foo\n> \n> But that is what --track does and is not what --set-upstream is for.\n\nRight, it's for altering the configuration after the branch has already\nbeen created. I wasn't thinking about creating the branch. That usage of\n--set-upstream seems unintuitive to me, but changing the upstream for a\nbranch that already exists is quite intuitive and what push -u does.\n\n> \n> Unlike --track, I don't think --set-upstream is a common enough\n> operation to deserve a one-letter synonym.\n\nI find myself using it surprisingly often, though it's certainly still\nnot in the top-10.\n\n> \n> Instead, I'd suggest the following changes:\n> \n>  1) Add support for\n> \n> \t# change upstream info\n> \tgit branch --set-upstream=origin/foo foo\n> \n>     for existing branches only.\n\nI submitted the patch I mentioned above which changes --set-upstream to\nsomething closer to what the user probably expects, which behaves mostly\nlike this, except that you'd have to omit the '=' as it still expected\nthe branch as an argument to the command. Not the cleanest wrt how\noptions should take arguments, but it got the job done without much code\nchurn.\n\nHowever, Junio doesn't like that it changes existing behaviour which is\neven consistent (as long as you know that --set-upstream is a flag,\nrather than an option with an argument) and some people might depend on\nit behaving like it does with a single argument. He'd accept a\n--set-upstream-to that behaves just like you describe. This could do\nwith having a short alias, as the name is quite long-winded. Another\nreason for adding -u is that it would add confusion if --set-upstream\nhas the short alias -u in push, but it means something else in branch,\neven though they have the same option (though it would be\n--set-upstream-to here, but we'll end up deprecating --set-upstream, so\nit works out in the long run).\n\n> \n>  2) Introduce an --unset-upstream option which removes the\n>     \"corresponding upstream branch\" configuration for an existing\n>     branch.\n\nThis is a good idea. I'll add it to the patch series.\n\n> \n>  3) Warn on\n> \n> \t# acts just like --track\n> \tgit branch --set-upstream foo origin/foo\n> \n>     for branches that do not exist yet.  Plan to make this a hard\n>     error in the future.\n> \n>  4) Warn on\n> \n> \t# sets upstream for \"foo\" to the current branch\n> \tgit branch --set-upstream foo\n> \n>     and plan to make it a hard error in the future.\n> \n>  5) Warn on\n> \n> \tgit branch --set-upstream origin/foo foo\n> \n>   which is almost certainly a typo for\n> \n> \tgit branch --set-upstream=origin/foo foo\n\nThis is roughly what Junio suggested. His proposal was to also show how\nto undo the --set-upstream if it was invoked the wrong way.\n\n> \n>  6) Perhaps, make -u a synonym for -t for consistency with \"git push\".\n\nI don't really see -u and -t being consistent with push -u. The push\nmight create a branch, but that would be in another repository. I look\nat it as modifying the upstream information for an existing branch in\nthe local repository, and -t does not do that, --set-upstream(-to) does\nthat. It can also create a new local branch, but that's another bug in\nthe interface.\n\n   cmn\n"}]}