{"thread":{"id":"53351","subject":"[PATCH] branch: add '-' to delete previous branch","startedAt":"2020-04-29T13:02:15Z","lastAt":"2020-05-01T22:22:32Z","messageCount":25,"participants":["Ivan Tham","Sergey Organov","Taylor Blau","Eric Sunshine","Junio C Hamano","Randall S. Becker","Konstantin Khomoutov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"396552","messageId":"20200429130133.520981-1-pickfire@riseup.net","threadId":"53351","inReplyTo":null,"subject":"[PATCH] branch: add '-' to delete previous branch","fromName":"Ivan Tham","fromEmail":"pickfire@riseup.net","sentAt":"2020-04-29T13:01:33Z","receivedAt":"2020-04-29T13:02:15Z","isPatch":true,"sender":{"key":"pickfire@riseup.net","avatar":null},"body":"Add support to delete previous branch from git checkout/switch to have\nfeature parity with git switch -.\n\nSigned-off-by: Ivan Tham <pickfire@riseup.net>\n---\n Documentation/git-branch.txt | 10 ++++++++++\n builtin/branch.c             |  6 +++++-\n t/t3200-branch.sh            |  7 +++++++\n 3 files changed, 22 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 135206ff4a..37e7cbbc52 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -265,6 +265,10 @@ start-point is either a local or remote-tracking branch.\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+You can use the `@{-N}` syntax to refer to the N-th last branch checked out\n+using \"git checkout\" operation. You may also specify `-` which is synonymous to\n+`@{-1}`.\n \n <start-point>::\n \tThe new branch head will point to this commit.  It may be\n@@ -334,6 +338,12 @@ $ git branch -D test                                    <2>\n <2> Delete the \"test\" branch even if the \"master\" branch (or whichever branch\n     is currently checked out) does not have all commits from the test branch.\n \n+To delete the previous branch::\n++\n+------------\n+$ git branch -D -\n+------------\n+\n Listing branches from a specific remote::\n +\n ------------\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex d8297f80ff..5537f819a6 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -227,9 +227,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t}\n \tfor (i = 0; i < argc; i++, strbuf_reset(&bname)) {\n \t\tchar *target = NULL;\n+\t\tconst char *arg = argv[i];\n \t\tint flags = 0;\n \n-\t\tstrbuf_branchname(&bname, argv[i], allowed_interpret);\n+\t\tif (!strcmp(arg, \"-\"))\n+\t\t\targ = \"@{-1}\";\n+\n+\t\tstrbuf_branchname(&bname, arg, allowed_interpret);\n \t\tfree(name);\n \t\tname = mkpathdup(fmt, bname.buf);\n \ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 411a70b0ce..6819107c1d 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -1387,4 +1387,11 @@ test_expect_success 'invalid sort parameter in configuration' '\n \t)\n '\n \n+test_expect_success 'delete previous branch' '\n+\tgit checkout -b a &&\n+\tgit checkout -b b &&\n+\tgit branch -D - &&\n+\ttest_path_is_missing .git/refs/heads/a\n+'\n+\n test_done\n-- \n2.26.2\n\n"},{"id":"396556","messageId":"877dxyo1k8.fsf@osv.gnss.ru","threadId":"53351","inReplyTo":"20200429130133.520981-1-pickfire@riseup.net","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2020-04-29T13:37:27Z","receivedAt":"2020-04-29T13:37:36Z","isPatch":true,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Ivan Tham <pickfire@riseup.net> writes:\n\n> Add support to delete previous branch from git checkout/switch to have\n> feature parity with git switch -.\n\nMaybe I'm late on this, but to me, who leaves in the Linux world,\n\"a_command -\" strongly suggests a_command will read further input\nfrom stdin.\n\n[...]\n\n> +To delete the previous branch::\n> ++\n> +------------\n> +$ git branch -D -\n\n... so this suggests that the command, when used like this:\n\n$ echo \"branch_name\" | git branch -D -\n\nwill delete \"branch_name\" rather than some \"previous\" branch, whatever\nthat means.\n\nIs this short-cut /that/ important to create yet another confusion?\n\n-- Sergey\n"},{"id":"396587","messageId":"20200429185851.GF83442@syl.local","threadId":"53351","inReplyTo":"20200429130133.520981-1-pickfire@riseup.net","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-04-29T18:58:51Z","receivedAt":"2020-04-29T18:58:55Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Apr 29, 2020 at 09:01:33PM +0800, Ivan Tham wrote:\n> Add support to delete previous branch from git checkout/switch to have\n> feature parity with git switch -.\n>\n> Signed-off-by: Ivan Tham <pickfire@riseup.net>\n> ---\n>  Documentation/git-branch.txt | 10 ++++++++++\n>  builtin/branch.c             |  6 +++++-\n>  t/t3200-branch.sh            |  7 +++++++\n>  3 files changed, 22 insertions(+), 1 deletion(-)\n>\n> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\n> index 135206ff4a..37e7cbbc52 100644\n> --- a/Documentation/git-branch.txt\n> +++ b/Documentation/git-branch.txt\n> @@ -265,6 +265,10 @@ start-point is either a local or remote-tracking branch.\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> +You can use the `@{-N}` syntax to refer to the N-th last branch checked out\n> +using \"git checkout\" operation. You may also specify `-` which is synonymous to\n> +`@{-1}`.\n\nInteresting; we're already using strbuf_branchname, so the first part of\nthis documentation was true even before this commit. Would you consider\nsplitting this into two patches?\n\nThe first should include the first sentence of this documentation, an\nadditional test in t3200 exercising an explicit 'git branch -D @{-N}'\nfor some 'N', but no changes in builtin/branch.c. The second patch would\nthen make '-' a synonym for '@{-1}'.\n\n>  <start-point>::\n>  \tThe new branch head will point to this commit.  It may be\n> @@ -334,6 +338,12 @@ $ git branch -D test                                    <2>\n>  <2> Delete the \"test\" branch even if the \"master\" branch (or whichever branch\n>      is currently checked out) does not have all commits from the test branch.\n>\n> +To delete the previous branch::\n> ++\n> +------------\n> +$ git branch -D -\n> +------------\n> +\n>  Listing branches from a specific remote::\n>  +\n>  ------------\n> diff --git a/builtin/branch.c b/builtin/branch.c\n> index d8297f80ff..5537f819a6 100644\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -227,9 +227,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n>  \t}\n>  \tfor (i = 0; i < argc; i++, strbuf_reset(&bname)) {\n>  \t\tchar *target = NULL;\n> +\t\tconst char *arg = argv[i];\n>  \t\tint flags = 0;\n>\n> -\t\tstrbuf_branchname(&bname, argv[i], allowed_interpret);\n> +\t\tif (!strcmp(arg, \"-\"))\n> +\t\t\targ = \"@{-1}\";\n> +\n> +\t\tstrbuf_branchname(&bname, arg, allowed_interpret);\n>  \t\tfree(name);\n>  \t\tname = mkpathdup(fmt, bname.buf);\n>\n> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\n> index 411a70b0ce..6819107c1d 100755\n> --- a/t/t3200-branch.sh\n> +++ b/t/t3200-branch.sh\n> @@ -1387,4 +1387,11 @@ test_expect_success 'invalid sort parameter in configuration' '\n>  \t)\n>  '\n>\n> +test_expect_success 'delete previous branch' '\n> +\tgit checkout -b a &&\n> +\tgit checkout -b b &&\n> +\tgit branch -D - &&\n> +\ttest_path_is_missing .git/refs/heads/a\n\nThis assertion is a little uncommon in t3200 for this style of test.\nPlease use the more-standard:\n\n  git branch >actual &&\n  cat >expect <<-\\EOF &&\n     master\n   * b\n  EOF\n  test_cmp expect actual\n\nSubstituting the body of the heredoc for the actual state of things.\nThis form makes it a little clearer what branches should and shouldn't\nexist.\n\n> +'\n> +\n>  test_done\n> --\n> 2.26.2\n>\n\nThanks,\nTaylor\n"},{"id":"396588","messageId":"20200429190013.GG83442@syl.local","threadId":"53351","inReplyTo":"877dxyo1k8.fsf@osv.gnss.ru","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-04-29T19:00:13Z","receivedAt":"2020-04-29T19:00:18Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Apr 29, 2020 at 04:37:27PM +0300, Sergey Organov wrote:\n> Ivan Tham <pickfire@riseup.net> writes:\n>\n> > Add support to delete previous branch from git checkout/switch to have\n> > feature parity with git switch -.\n>\n> Maybe I'm late on this, but to me, who leaves in the Linux world,\n> \"a_command -\" strongly suggests a_command will read further input\n> from stdin.\n>\n> [...]\n>\n> > +To delete the previous branch::\n> > ++\n> > +------------\n> > +$ git branch -D -\n>\n> ... so this suggests that the command, when used like this:\n>\n> $ echo \"branch_name\" | git branch -D -\n>\n> will delete \"branch_name\" rather than some \"previous\" branch, whatever\n> that means.\n>\n> Is this short-cut /that/ important to create yet another confusion?\n\nI think that it may be causing more confusion now than it would be after\nIvan's patch. 'git checkout', for example, also treats '-' as a synonym\nfor '@{-1}'.\n\nIn my opinion, it is fairly clear that 'git branch -D -' means \"delete\nthe last branch\", and not \"delete a list of branches from stdin.\n\n> -- Sergey\n\nThanks,\nTaylor\n"},{"id":"396589","messageId":"CAPig+cT7sBn58THC_PGw-xoSH3BmZiiO31yJwOL-TV3gAhATHQ@mail.gmail.com","threadId":"53351","inReplyTo":"20200429190013.GG83442@syl.local","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-04-29T19:06:31Z","receivedAt":"2020-04-29T19:06:47Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Apr 29, 2020 at 3:00 PM Taylor Blau <me@ttaylorr.com> wrote:\n> On Wed, Apr 29, 2020 at 04:37:27PM +0300, Sergey Organov wrote:\n> > Ivan Tham <pickfire@riseup.net> writes:\n> > > Add support to delete previous branch from git checkout/switch to have\n> > > feature parity with git switch -.\n> >\n> > Maybe I'm late on this, but to me, who leaves in the Linux world,\n> > \"a_command -\" strongly suggests a_command will read further input\n> > from stdin.\n> >\n> > Is this short-cut /that/ important to create yet another confusion?\n>\n> I think that it may be causing more confusion now than it would be after\n> Ivan's patch. 'git checkout', for example, also treats '-' as a synonym\n> for '@{-1}'.\n>\n> In my opinion, it is fairly clear that 'git branch -D -' means \"delete\n> the last branch\", and not \"delete a list of branches from stdin.\n\nI can't find the discussion right now, but I have a recollection that\n\"git branch -D -\" was explicitly rejected when \"-\" was being added as\nan alias for @{-1} to other modes and other commands. The reason for\nthe rejection was that branch deletion is a destructive operation (the\nref-log, in particular, is gone after deletion), and \"-\" alone\nprovides no clues and no context that you're deleting the branch you\nintend to delete. (The lack of clues and context isn't a big deal for\nnon-destructive commands, such as git-switch.)\n"},{"id":"396591","messageId":"xmqqk11yw0r9.fsf@gitster.c.googlers.com","threadId":"53351","inReplyTo":"877dxyo1k8.fsf@osv.gnss.ru","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-29T19:27:38Z","receivedAt":"2020-04-29T19:27:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sergey Organov <sorganov@gmail.com> writes:\n\n> Ivan Tham <pickfire@riseup.net> writes:\n>\n>> Add support to delete previous branch from git checkout/switch to have\n>> feature parity with git switch -.\n> ...\n> Is this short-cut /that/ important to create yet another confusion?\n\nI do not think it is that important, but I do not think \"cd -\" is so\nimportant, either.\n"},{"id":"396592","messageId":"03f601d61e5c$d32d6380$79882a80$@nexbridge.com","threadId":"53351","inReplyTo":"xmqqk11yw0r9.fsf@gitster.c.googlers.com","subject":"RE: [PATCH] branch: add '-' to delete previous branch","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2020-04-29T19:31:41Z","receivedAt":"2020-04-29T19:32:07Z","isPatch":true,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On April 29, 2020 3:28 PM, Junio wrote:\n> Sergey Organov <sorganov@gmail.com> writes:\n> > Ivan Tham <pickfire@riseup.net> writes:\n> >\n> >> Add support to delete previous branch from git checkout/switch to\n> >> have feature parity with git switch -.\n> > ...\n> > Is this short-cut /that/ important to create yet another confusion?\n> \n> I do not think it is that important, but I do not think \"cd -\" is so\nimportant,\n> either.\n\nI wouldn't mind a switch - to the previously switched-out branch rather than\nsupporting this for delete. Alternatively, what about a switch --push and a\nswitch --pop like something out of bash pushd/popd.\n\nRegards,\nRandall\n\n\n\n"},{"id":"396594","messageId":"87v9likr5a.fsf@osv.gnss.ru","threadId":"53351","inReplyTo":"20200429190013.GG83442@syl.local","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2020-04-29T19:50:41Z","receivedAt":"2020-04-29T19:50:47Z","isPatch":true,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n[...]\n\n> In my opinion, it is fairly clear that 'git branch -D -' means \"delete\n> the last branch\", and not \"delete a list of branches from stdin.\n\nHonestly, I'd never guess it'd \"delete the last branch\". No way.\n\n\"-\" standing by itself in a command means stdin, stdout, or otherwise a\ntypo. Using it for any other meaning is a blasphemy. Sure, nobody will\ndie because of this, but it's /extremely/ confusing!\n\nBTW, what about mistyping:\n\n$ git branch -d - f my_branch\n\nfor\n\n$ git branch -d -f my_branch\n\nor some such?\n\nNo, it still doesn't look like a good idea to use isolated '-' as\nsuggested by the patch.\n\nOTOH, for otherwise unusual @{-1}, @{-}, or @- I'd immediately realize I\nmust consult the manual, so these would be fine with me.\n\nThanks,\n-- Sergey\n"},{"id":"396595","messageId":"87pnbqkqx2.fsf@osv.gnss.ru","threadId":"53351","inReplyTo":"xmqqk11yw0r9.fsf@gitster.c.googlers.com","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2020-04-29T19:55:37Z","receivedAt":"2020-04-29T19:55:42Z","isPatch":true,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Sergey Organov <sorganov@gmail.com> writes:\n>\n>> Ivan Tham <pickfire@riseup.net> writes:\n>>\n>>> Add support to delete previous branch from git checkout/switch to have\n>>> feature parity with git switch -.\n>> ...\n>> Is this short-cut /that/ important to create yet another confusion?\n>\n> I do not think it is that important, but I do not think \"cd -\" is so\n> important, either.\n\nSure, and git shouldn't need to repeat other's mistakes.\n\n-- Sergey\n"},{"id":"396596","messageId":"20200429195745.GC3920@syl.local","threadId":"53351","inReplyTo":"87v9likr5a.fsf@osv.gnss.ru","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-04-29T19:57:45Z","receivedAt":"2020-04-29T19:57:49Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Apr 29, 2020 at 10:50:41PM +0300, Sergey Organov wrote:\n> Taylor Blau <me@ttaylorr.com> writes:\n>\n> [...]\n>\n> > In my opinion, it is fairly clear that 'git branch -D -' means \"delete\n> > the last branch\", and not \"delete a list of branches from stdin.\n>\n> Honestly, I'd never guess it'd \"delete the last branch\". No way.\n\nI'm having trouble understanding why. This is how 'git checkout -'\nbehaves, so I have no idea why 'git branch' wouldn't work the same way.\n\n> \"-\" standing by itself in a command means stdin, stdout, or otherwise a\n> typo. Using it for any other meaning is a blasphemy. Sure, nobody will\n> die because of this, but it's /extremely/ confusing!\n\nAgain, not sure that this is always the case. This *is* how 'git\ncheckout' works.\n\n> BTW, what about mistyping:\n>\n> $ git branch -d - f my_branch\n>\n> for\n>\n> $ git branch -d -f my_branch\n>\n> or some such?\n>\n> No, it still doesn't look like a good idea to use isolated '-' as\n> suggested by the patch.\n\nFrankly, I do not find this compelling. Does that mean that '/' as a\ndirectory separator is dangerous, too, because you can accidentally\nwrite 'rm -rf / foo/bar/baz'?\n\n> OTOH, for otherwise unusual @{-1}, @{-}, or @- I'd immediately realize I\n> must consult the manual, so these would be fine with me.\n>\n> Thanks,\n> -- Sergey\n\nThanks,\nTaylor\n"},{"id":"396598","messageId":"xmqqa72uvy7n.fsf@gitster.c.googlers.com","threadId":"53351","inReplyTo":"20200429195745.GC3920@syl.local","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-29T20:22:36Z","receivedAt":"2020-04-29T20:22:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> Again, not sure that this is always the case. This *is* how 'git\n> checkout' works.\n\nTo be honest, I am somewhat sympathetic to those who find \"-\" ==\n\"@{-1}\" unless it is used as an argument to \"git checkout/switch\".\nThe use of \"-\" in \"checkout\" is the exception, not the norm, and it\nwas sort of justifiable due to similarity to \"cd -\".  Both are\ncommands to the computer you give to \"go to the previous place\".\n\n\"git merge -\", \"git branch -d -\" etc. are not about *going* to the\nprevious place, and declaring the \"-\" is \"previous place\" is taking\nit a bit too far, at least to my taste.\n\nOh, I do not like those who advocate \"@\" as a synonym for \"HEAD\",\neither.  If there is one simple thing I want to get rid of from the\nsystem, that's it ;-).\n\nAnyway...\n\n"},{"id":"396599","messageId":"87imhihwbw.fsf@osv.gnss.ru","threadId":"53351","inReplyTo":"20200429195745.GC3920@syl.local","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2020-04-29T20:26:59Z","receivedAt":"2020-04-29T20:27:04Z","isPatch":true,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> On Wed, Apr 29, 2020 at 10:50:41PM +0300, Sergey Organov wrote:\n>> Taylor Blau <me@ttaylorr.com> writes:\n>>\n>> [...]\n>>\n>> > In my opinion, it is fairly clear that 'git branch -D -' means \"delete\n>> > the last branch\", and not \"delete a list of branches from stdin.\n>>\n>> Honestly, I'd never guess it'd \"delete the last branch\". No way.\n>\n> I'm having trouble understanding why. This is how 'git checkout -'\n> behaves, so I have no idea why 'git branch' wouldn't work the same\n> way.\n\nWell, if I knew 'git checkout -' does this, then yes, it'd be obvious.\nThe problem is that I didn't. Well, then, as I said in my original\nreaction, I'm probably too late on this.\n\nBTW, it was not that easy to find it in the \"git help checkout\" even\nwhen I was specifically looking for it.\n\nThanks,\n-- Sergey\n"},{"id":"396600","messageId":"20200429203508.GA7899@syl.local","threadId":"53351","inReplyTo":"xmqqa72uvy7n.fsf@gitster.c.googlers.com","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-04-29T20:35:08Z","receivedAt":"2020-04-29T20:35:14Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Apr 29, 2020 at 01:22:36PM -0700, Junio C Hamano wrote:\n> Taylor Blau <me@ttaylorr.com> writes:\n>\n> > Again, not sure that this is always the case. This *is* how 'git\n> > checkout' works.\n>\n> To be honest, I am somewhat sympathetic to those who find \"-\" ==\n> \"@{-1}\" unless it is used as an argument to \"git checkout/switch\".\n> The use of \"-\" in \"checkout\" is the exception, not the norm, and it\n> was sort of justifiable due to similarity to \"cd -\".  Both are\n> commands to the computer you give to \"go to the previous place\".\n>\n> \"git merge -\", \"git branch -d -\" etc. are not about *going* to the\n> previous place, and declaring the \"-\" is \"previous place\" is taking\n> it a bit too far, at least to my taste.\n\nOK, I could sympathize with that as well. I still think that my\nsuggestion from earlier about documenting the fact that 'git branch -D'\nalready understands '@{-N}' as a separate first patch is valid.\n\nIf I were the author, I'd cut that as a first patch, and discard the\nremainder if it sounds like we don't want to go with 'git branch -D -',\nwhich is fine by me. (I don't really care either way, and I can\nunderstand the arguments in both directions).\n\n> Oh, I do not like those who advocate \"@\" as a synonym for \"HEAD\",\n> either.  If there is one simple thing I want to get rid of from the\n> system, that's it ;-).\n>\n> Anyway...\n\nThanks,\nTaylor\n"},{"id":"396604","messageId":"xmqq5zdivxiq.fsf@gitster.c.googlers.com","threadId":"53351","inReplyTo":"xmqqa72uvy7n.fsf@gitster.c.googlers.com","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-29T20:37:33Z","receivedAt":"2020-04-29T20:37:42Z","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> Taylor Blau <me@ttaylorr.com> writes:\n>\n>> Again, not sure that this is always the case. This *is* how 'git\n>> checkout' works.\n>\n> To be honest, I am somewhat sympathetic to those who find \"-\" ==\n> \"@{-1}\" unless it is used as an argument to \"git checkout/switch\".\n\nInsert \"confusing\" before \"unless\".  Sorry about the typo.\n\n\n> The use of \"-\" in \"checkout\" is the exception, not the norm, and it\n> was sort of justifiable due to similarity to \"cd -\".  Both are\n> commands to the computer you give to \"go to the previous place\".\n>\n> \"git merge -\", \"git branch -d -\" etc. are not about *going* to the\n> previous place, and declaring the \"-\" is \"previous place\" is taking\n> it a bit too far, at least to my taste.\n>\n> Oh, I do not like those who advocate \"@\" as a synonym for \"HEAD\",\n> either.  If there is one simple thing I want to get rid of from the\n> system, that's it ;-).\n>\n> Anyway...\n"},{"id":"396605","messageId":"xmqq1ro6vxg7.fsf@gitster.c.googlers.com","threadId":"53351","inReplyTo":"20200429203508.GA7899@syl.local","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-29T20:39:04Z","receivedAt":"2020-04-29T20:39:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> OK, I could sympathize with that as well. I still think that my\n> suggestion from earlier about documenting the fact that 'git branch -D'\n> already understands '@{-N}' as a separate first patch is valid.\n\nNo question about that ;-)\n\n> If I were the author, I'd cut that as a first patch, and discard the\n> remainder if it sounds like we don't want to go with 'git branch -D -',\n> which is fine by me. (I don't really care either way, and I can\n> understand the arguments in both directions).\n\nYup, that would be what I would do, too, whether I wanted \"-d -\" or not.\n"},{"id":"396651","messageId":"20200430034323.wwsxzru7pcw2xsju@arch","threadId":"53351","inReplyTo":"87v9likr5a.fsf@osv.gnss.ru","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Ivan Tham","fromEmail":"pickfire@riseup.net","sentAt":"2020-04-30T03:43:23Z","receivedAt":"2020-04-30T03:43:31Z","isPatch":true,"sender":{"key":"pickfire@riseup.net","avatar":null},"body":"On Wed, Apr 29, 2020 at 10:50:41PM +0300, Sergey Organov wrote:\n>Taylor Blau <me@ttaylorr.com> writes:\n>\n>> In my opinion, it is fairly clear that 'git branch -D -' means \"delete\n>> the last branch\", and not \"delete a list of branches from stdin.\n>\n>Honestly, I'd never guess it'd \"delete the last branch\". No way.\n>\n>\"-\" standing by itself in a command means stdin, stdout, or otherwise a\n>typo. Using it for any other meaning is a blasphemy. Sure, nobody will\n>die because of this, but it's /extremely/ confusing!\n>\n>BTW, what about mistyping:\n>\n>$ git branch -d - f my_branch\n>\n>for\n>\n>$ git branch -d -f my_branch\n>\n>or some such?\n\nI already knew `git checkout -` and `git switch -` exists and have been\nusing them quite frequently as my workflow, but when I wanted to go back\nto my original branch and delete the branch, I tried `git branch -D -`\nquite a few times and I am surprised it does not work as expected.\n\nYes, that typo would have deleted a branch but it could be restored from\nreflog at the very least.\n\n>No, it still doesn't look like a good idea to use isolated '-' as\n>suggested by the patch.\n>\n>OTOH, for otherwise unusual @{-1}, @{-}, or @- I'd immediately realize I\n>must consult the manual, so these would be fine with me.\n\nBut yes, I didn't know @{-1} or @{-} or @- exists before I was sending\nthis patch, I only know I can use - which is very simple.\n"},{"id":"396662","messageId":"20200430145221.z3lpgjstybqztfqb@arch","threadId":"53351","inReplyTo":"20200429185851.GF83442@syl.local","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Ivan Tham","fromEmail":"pickfire@riseup.net","sentAt":"2020-04-30T14:52:21Z","receivedAt":"2020-04-30T14:52:28Z","isPatch":true,"sender":{"key":"pickfire@riseup.net","avatar":null},"body":"On Wed, Apr 29, 2020 at 12:58:51PM -0600, Taylor Blau wrote:\n>On Wed, Apr 29, 2020 at 09:01:33PM +0800, Ivan Tham wrote:\n>> Add support to delete previous branch from git checkout/switch to have\n>> feature parity with git switch -.\n>>\n>> Signed-off-by: Ivan Tham <pickfire@riseup.net>\n>> ---\n>>  Documentation/git-branch.txt | 10 ++++++++++\n>>  builtin/branch.c             |  6 +++++-\n>>  t/t3200-branch.sh            |  7 +++++++\n>>  3 files changed, 22 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\n>> index 135206ff4a..37e7cbbc52 100644\n>> --- a/Documentation/git-branch.txt\n>> +++ b/Documentation/git-branch.txt\n>> @@ -265,6 +265,10 @@ start-point is either a local or remote-tracking branch.\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>> +You can use the `@{-N}` syntax to refer to the N-th last branch checked out\n>> +using \"git checkout\" operation. You may also specify `-` which is synonymous to\n>> +`@{-1}`.\n>\n>Interesting; we're already using strbuf_branchname, so the first part of\n>this documentation was true even before this commit. Would you consider\n>splitting this into two patches?\n>\n>The first should include the first sentence of this documentation, an\n>additional test in t3200 exercising an explicit 'git branch -D @{-N}'\n>for some 'N', but no changes in builtin/branch.c. The second patch would\n>then make '-' a synonym for '@{-1}'.\n\nIs not this already true? Why do we need to split it? Currently using\n'@{-N}' to delete branch already works.\n"},{"id":"396667","messageId":"20200430155904.GA30682@syl.local","threadId":"53351","inReplyTo":"20200430145221.z3lpgjstybqztfqb@arch","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-04-30T15:59:04Z","receivedAt":"2020-04-30T15:59:09Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi Ivan,\n\nOn Thu, Apr 30, 2020 at 10:52:21PM +0800, Ivan Tham wrote:\n> On Wed, Apr 29, 2020 at 12:58:51PM -0600, Taylor Blau wrote:\n> > On Wed, Apr 29, 2020 at 09:01:33PM +0800, Ivan Tham wrote:\n> > > Add support to delete previous branch from git checkout/switch to have\n> > > feature parity with git switch -.\n> > >\n> > > Signed-off-by: Ivan Tham <pickfire@riseup.net>\n> > > ---\n> > >  Documentation/git-branch.txt | 10 ++++++++++\n> > >  builtin/branch.c             |  6 +++++-\n> > >  t/t3200-branch.sh            |  7 +++++++\n> > >  3 files changed, 22 insertions(+), 1 deletion(-)\n> > >\n> > > diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\n> > > index 135206ff4a..37e7cbbc52 100644\n> > > --- a/Documentation/git-branch.txt\n> > > +++ b/Documentation/git-branch.txt\n> > > @@ -265,6 +265,10 @@ start-point is either a local or remote-tracking branch.\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> > > +You can use the `@{-N}` syntax to refer to the N-th last branch checked out\n> > > +using \"git checkout\" operation. You may also specify `-` which is synonymous to\n> > > +`@{-1}`.\n> >\n> > Interesting; we're already using strbuf_branchname, so the first part of\n> > this documentation was true even before this commit. Would you consider\n> > splitting this into two patches?\n> >\n> > The first should include the first sentence of this documentation, an\n> > additional test in t3200 exercising an explicit 'git branch -D @{-N}'\n> > for some 'N', but no changes in builtin/branch.c. The second patch would\n> > then make '-' a synonym for '@{-1}'.\n>\n> Is not this already true? Why do we need to split it? Currently using\n> '@{-N}' to delete branch already works.\n\nIt is the case that 'git branch -D @{-N}' already works, which was\nsurprising to me. I am suggesting that you make documenting the existent\nbehavior a new first patch.\n\nOf course, that might be the only patch that you end up sending in v2,\nsince it seems that consensus has formed around not supposing '-' as a\nshorthand for '@{-1}' with 'git branch -D'.\n\nThanks,\nTaylor\n"},{"id":"396671","messageId":"20200430162753.pg6kpm6jlubotjlk@carbon","threadId":"53351","inReplyTo":"87imhihwbw.fsf@osv.gnss.ru","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Konstantin Khomoutov","fromEmail":"kostix@bswap.ru","sentAt":"2020-04-30T16:27:53Z","receivedAt":"2020-04-30T16:58:14Z","isPatch":true,"sender":{"key":"kostix@bswap.ru","avatar":null},"body":"On Wed, Apr 29, 2020 at 11:26:59PM +0300, Sergey Organov wrote:\n\n[...]\n> >> > In my opinion, it is fairly clear that 'git branch -D -' means \"delete\n> >> > the last branch\", and not \"delete a list of branches from stdin.\n> >>\n> >> Honestly, I'd never guess it'd \"delete the last branch\". No way.\n> >\n> > I'm having trouble understanding why. This is how 'git checkout -'\n> > behaves, so I have no idea why 'git branch' wouldn't work the same\n> > way.\n> \n> Well, if I knew 'git checkout -' does this, then yes, it'd be obvious.\n> The problem is that I didn't. Well, then, as I said in my original\n> reaction, I'm probably too late on this.\n> \n> BTW, it was not that easy to find it in the \"git help checkout\" even\n> when I was specifically looking for it.\n\nI would speculate that `git checkout -` may have learned about \"-\"\nsimply from the `cd -` form of the standard Unix shell (also codified by\nPOSIX [1]) which behaved that way - change the current directory to the\nprevious one - since forever. ;-)\n\n1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html\n\n"},{"id":"396689","messageId":"xmqqftcksqea.fsf@gitster.c.googlers.com","threadId":"53351","inReplyTo":"20200430155904.GA30682@syl.local","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-30T19:51:57Z","receivedAt":"2020-04-30T19:52:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> It is the case that 'git branch -D @{-N}' already works, which was\n> surprising to me. I am suggesting that you make documenting the existent\n> behavior a new first patch.\n>\n> Of course, that might be the only patch that you end up sending in v2,\n> since it seems that consensus has formed around not supposing '-' as a\n> shorthand for '@{-1}' with 'git branch -D'.\n\nThanks for concisely summarizing the current status of the\ndiscussion.\n"},{"id":"396691","messageId":"xmqqbln8sqcv.fsf@gitster.c.googlers.com","threadId":"53351","inReplyTo":"20200430162753.pg6kpm6jlubotjlk@carbon","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-30T19:52:48Z","receivedAt":"2020-04-30T19:52:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Konstantin Khomoutov <kostix@bswap.ru> writes:\n\n> I would speculate that `git checkout -` may have learned about \"-\"\n> simply from the `cd -` ...\n\nYou do not have to speculate.  You only need to read what has been\nalready said in the thread ;-).\n\n"},{"id":"396736","messageId":"87zhas3teg.fsf@osv.gnss.ru","threadId":"53351","inReplyTo":"xmqqbln8sqcv.fsf@gitster.c.googlers.com","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2020-05-01T09:18:31Z","receivedAt":"2020-05-01T09:18:36Z","isPatch":true,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Konstantin Khomoutov <kostix@bswap.ru> writes:\n>\n>> I would speculate that `git checkout -` may have learned about \"-\"\n>> simply from the `cd -` ...\n>\n> You do not have to speculate.  You only need to read what has been\n> already said in the thread ;-).\n\nShould I expect \"git checkout ~\" to get me to my \"home\" branch then? ;-)\n\nActually, that could be a good idea. I mean, to have \"home\" branch\nnotion and a short-cut for it.\n\n-- Sergey\n"},{"id":"396738","messageId":"20200501094432.u3bl24qou5sgbgxk@carbon","threadId":"53351","inReplyTo":"87zhas3teg.fsf@osv.gnss.ru","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Konstantin Khomoutov","fromEmail":"kostix@bswap.ru","sentAt":"2020-05-01T09:44:32Z","receivedAt":"2020-05-01T09:44:48Z","isPatch":true,"sender":{"key":"kostix@bswap.ru","avatar":null},"body":"On Fri, May 01, 2020 at 12:18:31PM +0300, Sergey Organov wrote:\n\n[...]\n> >> I would speculate that `git checkout -` may have learned about \"-\"\n> >> simply from the `cd -` ...\n> >\n> > You do not have to speculate.  You only need to read what has been\n> > already said in the thread ;-).\n> \n> Should I expect \"git checkout ~\" to get me to my \"home\" branch then? ;-)\n\nHeh, no you shouldn't: the '~' is expanded by the shell itself according\nto its parameter expansion rules, so `cd` never sees the bare tilde\nin this case ;-)\n\n> Actually, that could be a good idea. I mean, to have \"home\" branch\n> notion and a short-cut for it.\n\nI have no say for the idea per se but you would have hard time using\nbare tilda character for that precisely because of it being special to\nUnix shells - you'd need to escape it all the time (though something\nlike unquoted @{~} would work just OK).\n\n"},{"id":"396740","messageId":"87r1w43qfy.fsf@osv.gnss.ru","threadId":"53351","inReplyTo":"20200501094432.u3bl24qou5sgbgxk@carbon","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2020-05-01T10:22:25Z","receivedAt":"2020-05-01T10:22:35Z","isPatch":true,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Konstantin Khomoutov <kostix@bswap.ru> writes:\n\n> On Fri, May 01, 2020 at 12:18:31PM +0300, Sergey Organov wrote:\n>\n> [...]\n>> >> I would speculate that `git checkout -` may have learned about \"-\"\n>> >> simply from the `cd -` ...\n>> >\n>> > You do not have to speculate.  You only need to read what has been\n>> > already said in the thread ;-).\n>> \n>> Should I expect \"git checkout ~\" to get me to my \"home\" branch then? ;-)\n>\n> Heh, no you shouldn't: the '~' is expanded by the shell itself according\n> to its parameter expansion rules, so `cd` never sees the bare tilde\n> in this case ;-)\n\nYeah, but then git could compare its argument to $HOME and \"do the right\nthing\" ;-) Just kidding, obviously.\n\nThat said, bare \"cd\" also changes to home directory, so bare \"git\ncheckout\" could become as useful.\n\n>\n>> Actually, that could be a good idea. I mean, to have \"home\" branch\n>> notion and a short-cut for it.\n>\n> I have no say for the idea per se but you would have hard time using\n> bare tilda character for that precisely because of it being special to\n> Unix shells - you'd need to escape it all the time (though something\n> like unquoted @{~} would work just OK).\n\nYes, plain '~' won't do.\n\n-- Sergey\n"},{"id":"396795","messageId":"20200501222227.GE41612@syl.local","threadId":"53351","inReplyTo":"87r1w43qfy.fsf@osv.gnss.ru","subject":"Re: [PATCH] branch: add '-' to delete previous branch","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-05-01T22:22:27Z","receivedAt":"2020-05-01T22:22:32Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, May 01, 2020 at 01:22:25PM +0300, Sergey Organov wrote:\n> Konstantin Khomoutov <kostix@bswap.ru> writes:\n>\n> > On Fri, May 01, 2020 at 12:18:31PM +0300, Sergey Organov wrote:\n> >\n> > [...]\n> >> >> I would speculate that `git checkout -` may have learned about \"-\"\n> >> >> simply from the `cd -` ...\n> >> >\n> >> > You do not have to speculate.  You only need to read what has been\n> >> > already said in the thread ;-).\n> >>\n> >> Should I expect \"git checkout ~\" to get me to my \"home\" branch then? ;-)\n> >\n> > Heh, no you shouldn't: the '~' is expanded by the shell itself according\n> > to its parameter expansion rules, so `cd` never sees the bare tilde\n> > in this case ;-)\n>\n> Yeah, but then git could compare its argument to $HOME and \"do the right\n> thing\" ;-) Just kidding, obviously.\n>\n> That said, bare \"cd\" also changes to home directory, so bare \"git\n> checkout\" could become as useful.\n\nMy qualms about the general usefulness of a bare 'git checkout' going to\nsome bookmarked branch aside, this won't work, since a bare 'git\ncheckout' already sets HEAD to the currently checked-out branch.\n\nThat said, I am not at all sold on this being a good idea.\n\n> >\n> >> Actually, that could be a good idea. I mean, to have \"home\" branch\n> >> notion and a short-cut for it.\n> >\n> > I have no say for the idea per se but you would have hard time using\n> > bare tilda character for that precisely because of it being special to\n> > Unix shells - you'd need to escape it all the time (though something\n> > like unquoted @{~} would work just OK).\n>\n> Yes, plain '~' won't do.\n>\n> -- Sergey\n\nThanks,\nTaylor\n"}]}