{"thread":{"id":"27029","subject":"[PATCH] merge: allow \"-\" as a short-hand for \"previous branch\"","startedAt":"2011-04-07T23:03:14Z","lastAt":"2011-04-08T18:43:38Z","messageCount":5,"participants":["Junio C Hamano","Thomas Adam","Michael J Gruber"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"165384","messageId":"7vmxk164wd.fsf@alter.siamese.dyndns.org","threadId":"27029","inReplyTo":null,"subject":"[PATCH] merge: allow \"-\" as a short-hand for \"previous branch\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-07T23:03:14Z","receivedAt":"2011-04-07T23:03:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Just like \"git checkout -\" is a short-hand for \"git checkout @{-1}\" to\nconveniently switch back to the previous branch, \"git merge -\" is a\nshort-hand for \"git merge @{-1}\" to conveniently merge the previous branch.\n\nIt will allow me to say:\n\n    $ git checkout -b au/topic\n    $ git am -s ./+au-topic.mbox\n    $ git checkout pu\n    $ git merge -\n\nwhich is an extremely typical and repetitive operation during my git day.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/merge.c |    9 ++++++---\n 1 files changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex d54e7dd..0bdd19a 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1062,9 +1062,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \tif (!allow_fast_forward && fast_forward_only)\n \t\tdie(_(\"You cannot combine --no-ff with --ff-only.\"));\n \n-\tif (!argc && !abort_current_merge && default_to_upstream)\n-\t\targc = setup_with_upstream(&argv);\n-\n+\tif (!abort_current_merge) {\n+\t\tif (!argc && default_to_upstream)\n+\t\t\targc = setup_with_upstream(&argv);\n+\t\telse if (argc == 1 && !strcmp(argv[0], \"-\"))\n+\t\t\targv[0] = \"@{-1}\";\n+\t}\n \tif (!argc)\n \t\tusage_with_options(builtin_merge_usage,\n \t\t\tbuiltin_merge_options);\n-- \n1.7.5.rc1\n"},{"id":"165386","messageId":"BANLkTikA3dFQpZWC=TC3+zp2FS=uBBxf0Q@mail.gmail.com","threadId":"27029","inReplyTo":"7vmxk164wd.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] merge: allow \"-\" as a short-hand for \"previous branch\"","fromName":"Thomas Adam","fromEmail":"thomas@xteddy.org","sentAt":"2011-04-07T23:13:30Z","receivedAt":"2011-04-07T23:13:30Z","isPatch":true,"sender":{"key":"thomas@xteddy.org","avatar":"https://gravatar.com/avatar/e7256db4738e501e5d2e84f00bb0bd99503165729573848a03330301fc2adc4a?d=mp&s=160"},"body":"Hi,\n\nOn 8 April 2011 00:03, Junio C Hamano <gitster@pobox.com> wrote:\n> Just like \"git checkout -\" is a short-hand for \"git checkout @{-1}\" to\n> conveniently switch back to the previous branch, \"git merge -\" is a\n> short-hand for \"git merge @{-1}\" to conveniently merge the previous branch.\n>\n> It will allow me to say:\n>\n>    $ git checkout -b au/topic\n>    $ git am -s ./+au-topic.mbox\n>    $ git checkout pu\n>    $ git merge -\n\nI agree this is is useful, but is there a danger of this being a\ncommon typo, and people merging in previous branches a lot more often\nthan they ever intended?  In the case of \"git checkout -\" that's not\nas fatal, but if I ever mistype \"git merge -\" -- I'm now left with an\nunraveling exercise to do.\n\nHopefully it won't be an issue, as it's no worse than mistyping branch\nnames -- I suppose it's the sheer length of \"-\" in this case which\nleads to more potential for problems.\n\n-- Thomas Adam\n"},{"id":"165390","messageId":"7vbp0h63sw.fsf@alter.siamese.dyndns.org","threadId":"27029","inReplyTo":"BANLkTikA3dFQpZWC=TC3+zp2FS=uBBxf0Q@mail.gmail.com","subject":"Re: [PATCH] merge: allow \"-\" as a short-hand for \"previous branch\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-07T23:26:55Z","receivedAt":"2011-04-07T23:26:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Adam <thomas@xteddy.org> writes:\n\n> I agree this is is useful, but is there a danger of this being a\n> common typo, and people merging in previous branches a lot more often\n> than they ever intended?  In the case of \"git checkout -\" that's not\n> as fatal, but if I ever mistype \"git merge -\" -- I'm now left with an\n> unraveling exercise to do.\n\nJust like you can checkout the previous branch back if you found you\nchecked out a wrong branch by a typo, if you found that you merged a wrong\nbranch, you can just reset it away back to ORIG_HEAD, no?\n\nOr am I missing something more obvious?\n"},{"id":"165412","messageId":"4D9ED5AC.3050106@drmicha.warpmail.net","threadId":"27029","inReplyTo":"7vbp0h63sw.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] merge: allow \"-\" as a short-hand for \"previous branch\"","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-04-08T09:30:20Z","receivedAt":"2011-04-08T09:30:20Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Junio C Hamano venit, vidit, dixit 08.04.2011 01:26:\n> Thomas Adam <thomas@xteddy.org> writes:\n> \n>> I agree this is is useful, but is there a danger of this being a\n>> common typo, and people merging in previous branches a lot more often\n>> than they ever intended?  In the case of \"git checkout -\" that's not\n>> as fatal, but if I ever mistype \"git merge -\" -- I'm now left with an\n>> unraveling exercise to do.\n> \n> Just like you can checkout the previous branch back if you found you\n> checked out a wrong branch by a typo, if you found that you merged a wrong\n> branch, you can just reset it away back to ORIG_HEAD, no?\n> \n> Or am I missing something more obvious?\n\nOnly tests and doc :)\n\nSeriously, I like that. If there are more places where this makes sense\n(I haven't looked) we might even factor it out. In principle it makes\nsense everywhere where a branch name makes sense, e.g.:\n\ngit branch -D foo\n#...can't delete the current branch\ngit checkout whatever\ngit branch -D -\n\nIn this case, shell history is faster, of course.\n\nMichael\n"},{"id":"165435","messageId":"7vipuo4m91.fsf@alter.siamese.dyndns.org","threadId":"27029","inReplyTo":"4D9ED5AC.3050106@drmicha.warpmail.net","subject":"Re: [PATCH] merge: allow \"-\" as a short-hand for \"previous branch\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-08T18:43:38Z","receivedAt":"2011-04-08T18:43:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> ... In principle it makes\n> sense everywhere where a branch name makes sense, e.g.:\n>\n> git branch -D foo\n> #...can't delete the current branch\n> git checkout whatever\n> git branch -D -\n>\n> In this case, shell history is faster, of course.\n\nYeah, and \"branch -[dD]\" is truly destructive, so...\n"}]}