{"thread":{"id":"41777","subject":"[PATCH v2] branch -D: allow - as abbreviation of '@{-1}'","startedAt":"2016-03-22T08:24:16Z","lastAt":"2016-03-24T13:00:04Z","messageCount":6,"participants":["Elena Petrashen","Matthieu Moy","Junio C Hamano","Eric Sunshine","elena petrashen"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"281418","messageId":"1458635056-26633-1-git-send-email-elena.petrashen@gmail.com","threadId":"41777","inReplyTo":null,"subject":"[PATCH v2] branch -D: allow - as abbreviation of '@{-1}'","fromName":"Elena Petrashen","fromEmail":"elena.petrashen@gmail.com","sentAt":"2016-03-22T08:24:16Z","receivedAt":"2016-03-22T08:24:16Z","isPatch":true,"sender":{"key":"elena.petrashen@gmail.com","avatar":"https://gravatar.com/avatar/a2fd27bdf84eb2b7fc7b034a358aa6777fe86d5a9ac9339f122aea2b6b7689d4?d=mp&s=160"},"body":"Signed-off-by: Elena Petrashen <elena.petrashen@gmail.com>\n---\nThis micro-patch is meant to allow “-“ as a short-hand for\n“@{-1} for branch -D (Cf. $gmane/230828):\n\n* based on the discussion on the previous version of the patch,\nadded the advice on how to restore the deleted branch using\ngit branch deleted_name sha1 - to ensure safety and \nnewbie-friendliness\n\n* git branch (-d | -D) is not supposed to accept any other\narguments except for branch name so it makes sense to replace\nthe argv[i] with @{-1}. We will not lose the opportunity to\nuse it for something different for other git branch uses if\nwe will decide it’s required.\n\n* the small expand_dash_shortcut function can be reused to teach\ngit branch -m or other modifications to allow “-“ as a short-hand\nfor “@{-1}  as well and possibly makes it easy to understand what’s\ngoing on in the code\n\n* if there’s no previous branch in the repository yet, a\nspecific warning message is given\n\nThank you! Looking forward to any feedback.\n Documentation/git-branch.txt |  2 ++\n builtin/branch.c             | 26 ++++++++++++++++++++++----\n t/t3200-branch.sh            | 16 ++++++++++++++++\n 3 files changed, 40 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 4a7037f..42b96ed 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -65,6 +65,8 @@ to happen.\n With a `-d` or `-D` option, `<branchname>` 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+The \"@{-N}\" syntax for the N-th last branch deletes the specified branch.\n+You may also specify - which is synonymous with \"@{-1}\".\n \n Use `-r` together with `-d` to delete remote-tracking branches. Note, that it\n only makes sense to delete remote-tracking branches if they no longer exist\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 7b45b6b..8b33533 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -178,6 +178,15 @@ static void delete_branch_config(const char *branchname)\n \tstrbuf_release(&buf);\n }\n \n+static int expand_dash_shortcut(const char **argv, int dash_position)\n+{\n+\tif (!strcmp(argv[dash_position], \"-\")){\n+\t\targv[dash_position] = \"@{-1}\";\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\t\t   int quiet)\n {\n@@ -187,6 +196,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \tconst char *fmt;\n \tint i;\n \tint ret = 0;\n+\tint dash_shortcut = 0;\n \tint remote_branch = 0;\n \tstruct strbuf bname = STRBUF_INIT;\n \n@@ -213,7 +223,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \tfor (i = 0; i < argc; i++, strbuf_release(&bname)) {\n \t\tconst char *target;\n \t\tint flags = 0;\n-\n+\t\tif (expand_dash_shortcut (argv, i))\n+\t\t\tdash_shortcut = 1;\n \t\tstrbuf_branchname(&bname, argv[i]);\n \t\tif (kinds == FILTER_REFS_BRANCHES && !strcmp(head, bname.buf)) {\n \t\t\terror(_(\"Cannot delete the branch '%s' \"\n@@ -231,9 +242,12 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\t\t\t\t    | RESOLVE_REF_ALLOW_BAD_NAME,\n \t\t\t\t\t    sha1, &flags);\n \t\tif (!target) {\n-\t\t\terror(remote_branch\n-\t\t\t      ? _(\"remote-tracking branch '%s' not found.\")\n-\t\t\t      : _(\"branch '%s' not found.\"), bname.buf);\n+\t\t\terror(dash_shortcut\n+\t\t\t\t? _(\"There is no previous branch that could be\"\n+\t\t\t\t\t\" referred to at the moment.\")\n+\t\t\t\t: remote_branch\n+\t\t\t\t\t? _(\"remote-tracking branch '%s' not found.\")\n+\t\t\t\t\t: _(\"branch '%s' not found.\"), bname.buf);\n \t\t\tret = 1;\n \t\t\tcontinue;\n \t\t}\n@@ -262,6 +276,10 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\t\t       (flags & REF_ISBROKEN) ? \"broken\"\n \t\t\t       : (flags & REF_ISSYMREF) ? target\n \t\t\t       : find_unique_abbrev(sha1, DEFAULT_ABBREV));\n+\t\t\tif (dash_shortcut == 1)\n+\t\t\t       printf( _(\"\\nIf that happened by mistake, you may want to restore\"\n+\t\t\t\t\" it with:\\n\\ngit branch %s %s\\n\"), bname.buf,\n+\t\t\t\tfind_unique_abbrev(sha1, DEFAULT_ABBREV));\n \t\t}\n \t\tdelete_branch_config(bname.buf);\n \t}\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex a897248..535a507 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -403,6 +403,22 @@ test_expect_success 'test deleting branch without config' '\n \ttest_i18ncmp expect actual\n '\n \n+test_expect_success 'test deleting \"-\" deletes previous branch' '\n+\tgit checkout -b prev &&\n+\ttest_commit prev &&\n+\tgit checkout master &&\n+\tgit branch -D - >actual &&\n+\tsha1=$(git rev-parse --short prev) &&\n+\tcat >expected <<EOF &&\n+Deleted branch prev (was $sha1).\n+\n+If that happened by mistake, you may want to restore it with:\n+\n+git branch prev $sha1\n+EOF\n+\ttest_cmp expected actual\n+'\n+\n test_expect_success 'test --track without .fetch entries' '\n \tgit branch --track my8 &&\n \ttest \"$(git config branch.my8.remote)\" &&\n-- \n2.8.0.rc3.12.g047057b.dirty\n"},{"id":"281426","messageId":"vpqegb2omrb.fsf@anie.imag.fr","threadId":"41777","inReplyTo":"1458635056-26633-1-git-send-email-elena.petrashen@gmail.com","subject":"Re: [PATCH v2] branch -D: allow - as abbreviation of '@{-1}'","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2016-03-22T10:00:40Z","receivedAt":"2016-03-22T10:00:40Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Hi, and thanks for the quick reroll.\n\nA small advice: don't hesitate to reply to reviewers in the thread for\nv1. As a reviewer, I appreciate a quick reply like \"OK, will do in v2\",\nor even \"I disagree, I think my version is better because: ...\" (I'm not\n_always_ right ;-) ).\n\nElena Petrashen <elena.petrashen@gmail.com> writes:\n\n> Signed-off-by: Elena Petrashen <elena.petrashen@gmail.com>\n> ---\n> This micro-patch is meant to allow “-“ as a short-hand for\n> “@{-1} for branch -D (Cf. $gmane/230828):\n>\n> * based on the discussion on the previous version of the patch,\n> added the advice on how to restore the deleted branch using\n> git branch deleted_name sha1 - to ensure safety and \n> newbie-friendliness\n>\n> * git branch (-d | -D) is not supposed to accept any other\n> arguments except for branch name so it makes sense to replace\n> the argv[i] with @{-1}. We will not lose the opportunity to\n> use it for something different for other git branch uses if\n> we will decide it’s required.\n\nAs much as possible, try to distinguish new things in this version and\ngeneral remarks on your patch. Here, the first point is new and could\nappear below \"Changes since v1\". The second is not new, I think you can\neither consider that it is a followup to previous discussion (as Eric\ninterpreted it in v1) and remove the comment from v2, or consider it as\na justification of why your patch is sensible and include it in the\ncommit message (what I suggested in v1, but Eric more or less convinced\nme that I was wrong).\n\n> * if there’s no previous branch in the repository yet, a\n> specific warning message is given\n\nAs I said in v1, I think this is a separate topic and should be moved to\na separate patch. As I said above, you are free to disagree (and it's\nnot terribly important), but avoid leaving discussions open.\n\nOne point in favor of splitting the patch is that it's a good exercice\nfor a newcommer ;-).\n> +\tif (!strcmp(argv[dash_position], \"-\")){\n\nStyle: space between ) and {.\n\n> @@ -213,7 +223,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n>  \tfor (i = 0; i < argc; i++, strbuf_release(&bname)) {\n>  \t\tconst char *target;\n>  \t\tint flags = 0;\n> -\n> +\t\tif (expand_dash_shortcut (argv, i))\n> +\t\t\tdash_shortcut = 1;\n\nNit: the blank line removal is not needed.\n\n> +\t\t\tif (dash_shortcut == 1)\n> +\t\t\t       printf( _(\"\\nIf that happened by mistake, you may want to restore\"\n\nStyle: no space after (.\n\n> +\t\t\t\t\" it with:\\n\\ngit branch %s %s\\n\"), bname.buf,\n> +\t\t\t\tfind_unique_abbrev(sha1, DEFAULT_ABBREV));\n\nI think the message is overly long (4 '\\n', and I think \"If that\nhappened by mistake\" is not needed, just \"to restore the branch,\nrun ...\" would be enough).\n\nA rule that is usually applied for messages with Git:\n\n* If the message is triggered by a user-error, then it's OK to have a\n  long and possibly scary message: advanced users are not supposed to\n  see it.\n\n* If the message is seen by normal users in daily usage, then\n\n  - we try to keep it as short as possible.\n\n  - if it's not short enough, we allow disabling it with an advice.*\n    configuration variable.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"281441","messageId":"xmqq1t72jvac.fsf@gitster.mtv.corp.google.com","threadId":"41777","inReplyTo":"1458635056-26633-1-git-send-email-elena.petrashen@gmail.com","subject":"Re: [PATCH v2] branch -D: allow - as abbreviation of '@{-1}'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-22T17:07:39Z","receivedAt":"2016-03-22T17:07:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elena Petrashen <elena.petrashen@gmail.com> writes:\n\n> +static int expand_dash_shortcut(const char **argv, int dash_position)\n> +{\n> +\tif (!strcmp(argv[dash_position], \"-\")){\n> +\t\targv[dash_position] = \"@{-1}\";\n> +\t\treturn 1;\n> +\t}\n> +\treturn 0;\n> +}\n>  \tint i;\n>  \tint ret = 0;\n> +\tint dash_shortcut = 0;\n>  \tint remote_branch = 0;\n>  \tstruct strbuf bname = STRBUF_INIT;\n>  \n> @@ -213,7 +223,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n>  \tfor (i = 0; i < argc; i++, strbuf_release(&bname)) {\n>  \t\tconst char *target;\n>  \t\tint flags = 0;\n> -\n> +\t\tif (expand_dash_shortcut (argv, i))\n> +\t\t\tdash_shortcut = 1;\n>  \t\tstrbuf_branchname(&bname, argv[i]);\n\nI think this code special cases \"-\" too much.  Have you considered\ndoing this without \"dash_shortcut\" variable?  With that variable,\nyour code says \"there is no previous\" when the user says \"-\", but\nisn't that message also appropriate when she says \"@{-1}\" on the\ncommand line?  Furthermore, wouldn't the same apply to the case in\nwhich she said \"@{-4}\"?\n\nI suspect that you can check that condition immediately after\ncalling expand-dash-shortcut and then strbuf-branchname, in other\nwords, right here.  And if there is not enough branch switches, you\ncan say something like \"you gave me @{-4} but you haven't made that\nmany branch switches\" and continue the loop.\n\nI _think_ strbuf_branchname() leaves \"@{-<N>}\" when you do not have\nenough branch switches in the reflog, so perhaps\n\n\tstrbuf_branchname(&bname, (!strcmp(argv[i], \"-\") ? \"@{-1}\" : argv[i]));\n\tif (starts_with(bname.buf, \"@{-\")) {\n\t\t... say \"you do not have enough branch switches\" here.\n\t\t... when adjusting the message to end-user input,\n\t\t... you can look at argv[i] to notice that the original\n                ... input was \"-\".\n\t\terror(...);\n\t\tcontinue;\n\t}\n\nor something?\n\nThat way, there is no change necessary below this line, i.e. from\nhere...\n\n>  \t\tif (kinds == FILTER_REFS_BRANCHES && !strcmp(head, bname.buf)) {\n>  \t\t\terror(_(\"Cannot delete the branch '%s' \"\n> @@ -231,9 +242,12 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n>  \t\t\t\t\t    | RESOLVE_REF_ALLOW_BAD_NAME,\n>  \t\t\t\t\t    sha1, &flags);\n>  \t\tif (!target) {\n> -\t\t\terror(remote_branch\n> -\t\t\t      ? _(\"remote-tracking branch '%s' not found.\")\n> -\t\t\t      : _(\"branch '%s' not found.\"), bname.buf);\n> +\t\t\terror(dash_shortcut\n> +\t\t\t\t? _(\"There is no previous branch that could be\"\n> +\t\t\t\t\t\" referred to at the moment.\")\n> +\t\t\t\t: remote_branch\n> +\t\t\t\t\t? _(\"remote-tracking branch '%s' not found.\")\n> +\t\t\t\t\t: _(\"branch '%s' not found.\"), bname.buf);\n>  \t\t\tret = 1;\n>  \t\t\tcontinue;\n>  \t\t}\n> @@ -262,6 +276,10 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n>  \t\t\t       (flags & REF_ISBROKEN) ? \"broken\"\n>  \t\t\t       : (flags & REF_ISSYMREF) ? target\n>  \t\t\t       : find_unique_abbrev(sha1, DEFAULT_ABBREV));\n\n... to here.\n\n\n> +\t\t\tif (dash_shortcut == 1)\n> +\t\t\t       printf( _(\"\\nIf that happened by mistake, you may want to restore\"\n> +\t\t\t\t\" it with:\\n\\ngit branch %s %s\\n\"), bname.buf,\n> +\t\t\t\tfind_unique_abbrev(sha1, DEFAULT_ABBREV));\n\nThis change can be justified only if we believe that people who say\n\n    $ git branch -D -\n\nby mistake are much less clueful than those who say\n\n    $ git branch -D @{-1}\n    $ git branch -D a-misspelled-branch-name\n\nby mistake and need extra help recovering.  Is there an evidence to\nsupport such an assumption?\n\nI would actually understand it if this were more like\n\n\tif (advice_mistaken_branch_deletion)\n        \tprintf(_(\"If you deleted the branch by mistake, you can...\"));\n\nso that everybody who ran \"git branch -D\" on a (wrong) branch by\nmistake can get the extra help.\n"},{"id":"281443","messageId":"xmqqwpouigin.fsf@gitster.mtv.corp.google.com","threadId":"41777","inReplyTo":"xmqq1t72jvac.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2] branch -D: allow - as abbreviation of '@{-1}'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-22T17:12:00Z","receivedAt":"2016-03-22T17:12:00Z","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> I _think_ strbuf_branchname() leaves \"@{-<N>}\" when you do not have\n> enough branch switches in the reflog, so perhaps ...\n\nThis is a tangent, but the value returned from strbuf_branchname()\nis not well documented, and nobody looks at it.  It might not be a\nbad idea to change the return value from the function in such a way\nthat it can signal \"I saw @{-<N>} syntax but there weren't enough\nbranch switches\" and also \"I saw branch@{upstream} syntax but that\nbranch does not have an upstream configured for it\" to its callers.\n\nThat way, the suggested \"perhaps like this...\" patch does not have\nto do an ugly hack: if (starts_with(bname.buf, \"@{-\")).\n"},{"id":"281468","messageId":"CAPig+cSuRkBxUNY_nA4Ha6g3k-8VtmfFM80+gTmdM23n4e6Uxg@mail.gmail.com","threadId":"41777","inReplyTo":"xmqqwpouigin.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2] branch -D: allow - as abbreviation of '@{-1}'","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-22T18:57:35Z","receivedAt":"2016-03-22T18:57:35Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 22, 2016 at 1:12 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Junio C Hamano <gitster@pobox.com> writes:\n>> I _think_ strbuf_branchname() leaves \"@{-<N>}\" when you do not have\n>> enough branch switches in the reflog, so perhaps ...\n>\n> This is a tangent, but the value returned from strbuf_branchname()\n> is not well documented, and nobody looks at it.  It might not be a\n> bad idea to change the return value from the function in such a way\n> that it can signal \"I saw @{-<N>} syntax but there weren't enough\n> branch switches\" and also \"I saw branch@{upstream} syntax but that\n> branch does not have an upstream configured for it\" to its callers.\n>\n> That way, the suggested \"perhaps like this...\" patch does not have\n> to do an ugly hack: if (starts_with(bname.buf, \"@{-\")).\n\nIn case it's not clear, when Junio says \"this is a tangent\", he is not\nsaying that he expects you to make this change as part of your\nmicroproject. Rather, he's just putting it out there as \"low hanging\nfruit\" if someone wants a small project to tackle (and indeed, it\nmight make a reasonable microproject itself).\n"},{"id":"281668","messageId":"CAJPOeMdB+3fKa93cbcJRRA6CHg1C4reEZt_sVwv=2qCWfoHATw@mail.gmail.com","threadId":"41777","inReplyTo":"xmqq1t72jvac.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2] branch -D: allow - as abbreviation of '@{-1}'","fromName":"elena petrashen","fromEmail":"elena.petrashen@gmail.com","sentAt":"2016-03-24T13:00:04Z","receivedAt":"2016-03-24T13:00:04Z","isPatch":true,"sender":{"key":"elena.petrashen@gmail.com","avatar":"https://gravatar.com/avatar/a2fd27bdf84eb2b7fc7b034a358aa6777fe86d5a9ac9339f122aea2b6b7689d4?d=mp&s=160"},"body":"On Tue, Mar 22, 2016 at 8:07 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Elena Petrashen <elena.petrashen@gmail.com> writes:\n>\n>> +static int expand_dash_shortcut(const char **argv, int dash_position)\n>> +{\n>> +     if (!strcmp(argv[dash_position], \"-\")){\n>> +             argv[dash_position] = \"@{-1}\";\n>> +             return 1;\n>> +     }\n>> +     return 0;\n>> +}\n>>       int i;\n>>       int ret = 0;\n>> +     int dash_shortcut = 0;\n>>       int remote_branch = 0;\n>>       struct strbuf bname = STRBUF_INIT;\n>>\n>> @@ -213,7 +223,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n>>       for (i = 0; i < argc; i++, strbuf_release(&bname)) {\n>>               const char *target;\n>>               int flags = 0;\n>> -\n>> +             if (expand_dash_shortcut (argv, i))\n>> +                     dash_shortcut = 1;\n>>               strbuf_branchname(&bname, argv[i]);\n>\n> I think this code special cases \"-\" too much.  Have you considered\n> doing this without \"dash_shortcut\" variable?  With that variable,\n> your code says \"there is no previous\" when the user says \"-\", but\n> isn't that message also appropriate when she says \"@{-1}\" on the\n> command line?  Furthermore, wouldn't the same apply to the case in\n> which she said \"@{-4}\"?\n>\n> I suspect that you can check that condition immediately after\n> calling expand-dash-shortcut and then strbuf-branchname, in other\n> words, right here.  And if there is not enough branch switches, you\n> can say something like \"you gave me @{-4} but you haven't made that\n> many branch switches\" and continue the loop.\n>\n> I _think_ strbuf_branchname() leaves \"@{-<N>}\" when you do not have\n> enough branch switches in the reflog, so perhaps\n>\n>         strbuf_branchname(&bname, (!strcmp(argv[i], \"-\") ? \"@{-1}\" : argv[i]));\n>         if (starts_with(bname.buf, \"@{-\")) {\n>                 ... say \"you do not have enough branch switches\" here.\n>                 ... when adjusting the message to end-user input,\n>                 ... you can look at argv[i] to notice that the original\n>                 ... input was \"-\".\n>                 error(...);\n>                 continue;\n>         }\n>\n> or something?\n>\n> That way, there is no change necessary below this line, i.e. from\n> here...\n>\n>>               if (kinds == FILTER_REFS_BRANCHES && !strcmp(head, bname.buf)) {\n>>                       error(_(\"Cannot delete the branch '%s' \"\n>> @@ -231,9 +242,12 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n>>                                           | RESOLVE_REF_ALLOW_BAD_NAME,\n>>                                           sha1, &flags);\n>>               if (!target) {\n>> -                     error(remote_branch\n>> -                           ? _(\"remote-tracking branch '%s' not found.\")\n>> -                           : _(\"branch '%s' not found.\"), bname.buf);\n>> +                     error(dash_shortcut\n>> +                             ? _(\"There is no previous branch that could be\"\n>> +                                     \" referred to at the moment.\")\n>> +                             : remote_branch\n>> +                                     ? _(\"remote-tracking branch '%s' not found.\")\n>> +                                     : _(\"branch '%s' not found.\"), bname.buf);\n>>                       ret = 1;\n>>                       continue;\n>>               }\n>> @@ -262,6 +276,10 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n>>                              (flags & REF_ISBROKEN) ? \"broken\"\n>>                              : (flags & REF_ISSYMREF) ? target\n>>                              : find_unique_abbrev(sha1, DEFAULT_ABBREV));\n\nRight, thank you for the idea and the detailed explanation! I will try\nto implement the \"not enough switches\" message for the v3 version\nof the patch the, along with the necessary style corrections that\nMatthieu pointed out above.\n\n>\n> ... to here.\n>\n>\n>> +                     if (dash_shortcut == 1)\n>> +                            printf( _(\"\\nIf that happened by mistake, you may want to restore\"\n>> +                             \" it with:\\n\\ngit branch %s %s\\n\"), bname.buf,\n>> +                             find_unique_abbrev(sha1, DEFAULT_ABBREV));\n>\n> This change can be justified only if we believe that people who say\n>\n>     $ git branch -D -\n>\n> by mistake are much less clueful than those who say\n>\n>     $ git branch -D @{-1}\n>     $ git branch -D a-misspelled-branch-name\n>\n> by mistake and need extra help recovering.  Is there an evidence to\n> support such an assumption?\n\nI'd think it's a little bit more likely to be the \"I thought the\nprevious branch is \"foo\" but turns out it's \"bar\" which I didn't\nmean to delete\" case for -/@{-1}. case, then just misspelling.\nThe idea of the warning message was brought up because of\nthis I think? If we allow deleting via - or even @{-1}, which is\ncurrently possible, it might make sense to additionally enable\nthe user to recover if she deleted the wrong branch instead of\nthe required one.\n\n>\n> I would actually understand it if this were more like\n>\n>         if (advice_mistaken_branch_deletion)\n>                 printf(_(\"If you deleted the branch by mistake, you can...\"));\n>\n> so that everybody who ran \"git branch -D\" on a (wrong) branch by\n> mistake can get the extra help.\n\nWould you think this is actually a welcome addition - a (suppressable)\nwarning for every type of deletion, regardless of whether the shortcuts\nare used? There seems to be quite a lot of topics in google where people\nare asking how to restore a branch they accidentally deleted. Or that\nwould be not really consistent with the other situations when people can\ndelete something (like reset a commit), and they are not immediately\ntold how can they remedy a situation if that was a mistake?\n"}]}