{"thread":{"id":"41630","subject":"[PATCH] Allow \"-\" as a short-hand for \"@{-1}\" in \"git branch -d @{-1}\"","startedAt":"2016-03-06T12:48:13Z","lastAt":"2016-03-06T21:09:29Z","messageCount":4,"participants":["Dinesh Polathula","Eric Sunshine","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"280293","messageId":"1457268494-8394-1-git-send-email-dpdineshp2@gmail.com","threadId":"41630","inReplyTo":null,"subject":"[PATCH] Allow \"-\" as a short-hand for \"@{-1}\" in \"git branch -d @{-1}\"","fromName":"Dinesh Polathula","fromEmail":"dpdineshp2@gmail.com","sentAt":"2016-03-06T12:48:13Z","receivedAt":"2016-03-06T12:48:13Z","isPatch":true,"sender":{"key":"dpdineshp2@gmail.com","avatar":null},"body":"From: Dinesh <dpdineshp2@gmail.com>\n\nThis patch allows the usage of \"-\" as a short-hand for \"@{-1}\" in \n\"git branch -d  <at> {-1}\".\n\nNote : This is a microproject that is part of the Google Summer of \nCode application process.\nI am interested in working on the git Beginner mode implementation as \npart of Google Summer of Code. The mentor details for this particular \nproject are not available on the Ideas page. The mentors are likely on \nthis mailing list, so I request the mentors to drop me a mail so I can \nget in contact with you to further discuss the git Beginner mode project.\n\nDinesh (1):\n  Allow \"-\" as a short-hand for \"@{-1}\" in \"git branch -d @{-1}\"\n\n builtin/branch.c | 11 ++++++++---\n 1 file changed, 8 insertions(+), 3 deletions(-)\n\n-- \n2.8.0.rc0\n"},{"id":"280294","messageId":"1457268494-8394-2-git-send-email-dpdineshp2@gmail.com","threadId":"41630","inReplyTo":"1457268494-8394-1-git-send-email-dpdineshp2@gmail.com","subject":"[PATCH] Allow \"-\" as a short-hand for \"@{-1}\" in \"git branch -d @{-1}\"","fromName":"Dinesh Polathula","fromEmail":"dpdineshp2@gmail.com","sentAt":"2016-03-06T12:48:14Z","receivedAt":"2016-03-06T12:48:14Z","isPatch":true,"sender":{"key":"dpdineshp2@gmail.com","avatar":null},"body":"From: Dinesh <dpdineshp2@gmail.com>\n\nThe \"-\" shorthand can be used as a replacement for \"@{-1}\" to refer\nto the previous branch the user was on in the \"git branch -d @{-1}\"\ncommand.\nReplace \"-\" argument with \"@{-1}\" when the command line arguments\nare parsed.\n\nSigned-off-by: Dinesh Polathula<dpdineshp2@gmail.com>\n---\n builtin/branch.c | 11 ++++++++---\n 1 file changed, 8 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 7b45b6b..98d2c4b 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -24,7 +24,7 @@\n static const char * const builtin_branch_usage[] = {\n \tN_(\"git branch [<options>] [-r | -a] [--merged | --no-merged]\"),\n \tN_(\"git branch [<options>] [-l] [-f] <branch-name> [<start-point>]\"),\n-\tN_(\"git branch [<options>] [-r] (-d | -D) <branch-name>...\"),\n+\tN_(\"git branch [<options>] [-r] (-d | -D) [-] <branch-name>...\"),\n \tN_(\"git branch [<options>] (-m | -M) [<old-branch>] <new-branch>\"),\n \tN_(\"git branch [<options>] [-r | -a] [--points-at]\"),\n \tNULL\n@@ -658,8 +658,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \tfilter.abbrev = -1;\n \n \tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n-\t\tusage_with_options(builtin_branch_usage, options);\n-\n+\t{\n+\t\tusage_with_options(builtin_branch_usage, options);\t\n+\t}\n+\tif (argc == 3 && !strcmp(argv[2], \"-\"))\n+\t{\n+\t    argv[2] = \"@{-1}\";\t\n+\t}\n \tgit_config(git_branch_config, NULL);\n \n \ttrack = git_branch_track;\n-- \n2.8.0.rc0\n"},{"id":"280299","messageId":"CAPig+cTHBLGjn_tnAKE2i_zv9TRxdVbNfONpxg=ZvRSz9-4t=Q@mail.gmail.com","threadId":"41630","inReplyTo":"1457268494-8394-2-git-send-email-dpdineshp2@gmail.com","subject":"Re: [PATCH] Allow \"-\" as a short-hand for \"@{-1}\" in \"git branch -d @{-1}\"","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-03-06T19:35:55Z","receivedAt":"2016-03-06T19:35:55Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Mar 6, 2016 at 7:48 AM, Dinesh Polathula <dpdineshp2@gmail.com> wrote:\n> From: Dinesh <dpdineshp2@gmail.com>\n\nYou can drop this line and let git-am pick up your name and address\nfrom the email envelope.\n\n> Allow \"-\" as a short-hand for \"@{-1}\" in \"git branch -d @{-1}\"\n\n    branch: -d/-D: recognize \"-\" as short-hand for @{-1}\n\n> The \"-\" shorthand can be used as a replacement for \"@{-1}\" to refer\n> to the previous branch the user was on in the \"git branch -d @{-1}\"\n> command.\n\nDoes/should this also apply to -D?\n\n> Replace \"-\" argument with \"@{-1}\" when the command line arguments\n> are parsed.\n\nThis final sentence isn't really needed, as it's just repeating what\nthe patch itself already says.\n\n> Signed-off-by: Dinesh Polathula<dpdineshp2@gmail.com>\n> ---\n>  builtin/branch.c | 11 ++++++++---\n>  1 file changed, 8 insertions(+), 3 deletions(-)\n\nDoes this need a documentation update? Is \"-\" documented for other\ncommands which recognize it specially or is knowledge of \"-\" implicit?\n\nThis change probably does deserve a new test or two.\n\n> diff --git a/builtin/branch.c b/builtin/branch.c\n> index 7b45b6b..98d2c4b 100644\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -24,7 +24,7 @@\n>  static const char * const builtin_branch_usage[] = {\n>         N_(\"git branch [<options>] [-r | -a] [--merged | --no-merged]\"),\n>         N_(\"git branch [<options>] [-l] [-f] <branch-name> [<start-point>]\"),\n> -       N_(\"git branch [<options>] [-r] (-d | -D) <branch-name>...\"),\n> +       N_(\"git branch [<options>] [-r] (-d | -D) [-] <branch-name>...\"),\n>         N_(\"git branch [<options>] (-m | -M) [<old-branch>] <new-branch>\"),\n>         N_(\"git branch [<options>] [-r | -a] [--points-at]\"),\n>         NULL\n> @@ -658,8 +658,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n>         filter.abbrev = -1;\n>\n>         if (argc == 2 && !strcmp(argv[1], \"-h\"))\n> -               usage_with_options(builtin_branch_usage, options);\n> -\n> +       {\n> +               usage_with_options(builtin_branch_usage, options);\n> +       }\n\nWhy add unnecessary braces (making the diff noisier, as well)?\n\n> +       if (argc == 3 && !strcmp(argv[2], \"-\"))\n\nThe commit message talks about this applying only to -d (and\npresumably -D), however, there doesn't seem to be any constraint\nenforcing that.\n\nWon't this logic fail if the user passes other options accepted by\ngit-branch, such as --quite (for instance, \"git branch --quiet -d -\")?\nHow do other Git commands which recognize \"-\" as alias for @{-1} deal\nwith this? Have you checked their implementations?\n\nTo address these issues, it seems like a more correct place to\nrecognize \"-\" as an alias would be somewhere within\nbuiltin/branch.d:delete_branches().\n\n> +       {\n> +           argv[2] = \"@{-1}\";\n> +       }\n\nStyle: Unnecessary braces.\n\n>         git_config(git_branch_config, NULL);\n>\n>         track = git_branch_track;\n> --\n> 2.8.0.rc0\n"},{"id":"280301","messageId":"xmqqa8mbtit2.fsf@gitster.mtv.corp.google.com","threadId":"41630","inReplyTo":"CAPig+cTHBLGjn_tnAKE2i_zv9TRxdVbNfONpxg=ZvRSz9-4t=Q@mail.gmail.com","subject":"Re: [PATCH] Allow \"-\" as a short-hand for \"@{-1}\" in \"git branch -d @{-1}\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-06T21:09:29Z","receivedAt":"2016-03-06T21:09:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n>> +       if (argc == 3 && !strcmp(argv[2], \"-\"))\n> ...\n> To address these issues, it seems like a more correct place to\n> recognize \"-\" as an alias would be somewhere within\n> builtin/branch.d:delete_branches().\n\nI agree with all your review comments, and the above would also\ncover another issue you did not mention above: \"git branch -d/-D\"\nactually takes one or more branches to delete.\n\nAnother issue to consider is if we get a sensible error message.\n\nWhat should the error message say if a user did these in a freshly\ncreated empty repository?\n\n    $ git commit --allow-empty -m initial\n    $ git commit --allow-empty -m second\n    $ git branch side master^\n    $ git branch -d -\n\nCurrently, you would get\n\n    $ git branch -d -\n    error: branch '-' not found.\n\nIs it OK to say\n\n    error: branch '@{-1}' not found.\n\nwhen the user never said '@{-1}' from the command line?\n\nI am not saying it _is_ a problem--it may very well be acceptable,\nas long as the users understand that '-' is merely a short-hand for\n'@{-1}'.  Either way, the log message needs to have some evidence\nthat the patch author thought about the issue, the resolution the\npatch author chose for the issue, and the reason why a particular\nresolution was chosen.\n\nThanks.\n"}]}