{"thread":{"id":"38772","subject":"[PATCH v3 1/2] reset: enable '-' short-hand for previous branch","startedAt":"2015-03-10T10:52:07Z","lastAt":"2015-03-13T10:27:46Z","messageCount":13,"participants":["Sudhanshu Shekhar","Matthieu Moy","Eric Sunshine"],"isPatch":true,"patchVersion":3,"patchTotal":2},"messages":[{"id":"257460","messageId":"1425984728-27996-1-git-send-email-sudshekhar02@gmail.com","threadId":"38772","inReplyTo":null,"subject":"[PATCH v3 1/2] reset: enable '-' short-hand for previous branch","fromName":"Sudhanshu Shekhar","fromEmail":"sudshekhar02@gmail.com","sentAt":"2015-03-10T10:52:07Z","receivedAt":"2015-03-10T10:52:07Z","isPatch":true,"sender":{"key":"sudshekhar02@gmail.com","avatar":null},"body":"'git reset -' will reset to the previous branch. It will behave similar\nto @{-1} except when a file named '@{-1}' is present. To refer to a file\nnamed '-', use ./- or the -- flag.\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nHelped-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>\nSigned-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n---\nThank you all for your feedback. I have made changes and I hope this patch meets community standards. Please let me know if any further changes are required.\n\nRegards,\nSudhanshu\n\n builtin/reset.c | 13 ++++++++++++-\n 1 file changed, 12 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 4c08ddc..8abd300 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -192,6 +192,7 @@ static void parse_args(struct pathspec *pathspec,\n {\n \tconst char *rev = \"HEAD\";\n \tunsigned char unused[20];\n+\tint substituted_minus = 0;\n \t/*\n \t * Possible arguments are:\n \t *\n@@ -205,6 +206,10 @@ static void parse_args(struct pathspec *pathspec,\n \t */\n \n \tif (argv[0]) {\n+\t\tif (!strcmp(argv[0], \"-\")) {\n+\t\t\targv[0] = \"@{-1}\";\n+\t\t\tsubstituted_minus = 1;\n+\t\t}\n \t\tif (!strcmp(argv[0], \"--\")) {\n \t\t\targv++; /* reset to HEAD, possibly with paths */\n \t\t} else if (argv[1] && !strcmp(argv[1], \"--\")) {\n@@ -222,15 +227,21 @@ static void parse_args(struct pathspec *pathspec,\n \t\t\t * Ok, argv[0] looks like a commit/tree; it should not\n \t\t\t * be a filename.\n \t\t\t */\n+\t\t\tif (substituted_minus)\n+\t\t\t\targv[0] = \"-\";\n \t\t\tverify_non_filename(prefix, argv[0]);\n+\t\t\tif (substituted_minus)\n+\t\t\t\targv[0] = \"@{-1}\";\n \t\t\trev = *argv++;\n \t\t} else {\n+\t\t\t/* We were treating \"-\" as a commit and not a file */\n+\t\t\tif (substituted_minus)\n+\t\t\t\targv[0] = \"-\";\n \t\t\t/* Otherwise we treat this as a filename */\n \t\t\tverify_filename(prefix, argv[0], 1);\n \t\t}\n \t}\n \t*rev_ret = rev;\n-\n \tif (read_cache() < 0)\n \t\tdie(_(\"index file corrupt\"));\n \n-- \n2.3.1.279.gd534259\n"},{"id":"257461","messageId":"1425984728-27996-2-git-send-email-sudshekhar02@gmail.com","threadId":"38772","inReplyTo":"1425984728-27996-1-git-send-email-sudshekhar02@gmail.com","subject":"[PATCH v3 2/2] Added tests for reset -","fromName":"Sudhanshu Shekhar","fromEmail":"sudshekhar02@gmail.com","sentAt":"2015-03-10T10:52:08Z","receivedAt":"2015-03-10T10:52:08Z","isPatch":true,"sender":{"key":"sudshekhar02@gmail.com","avatar":null},"body":"Added the following test cases:\n    1) Confirm error message when git reset is used with no previous branch\n    2) Confirm git reset - works like git reset @{-1}\n    3) Confirm \"-\" is always treated as a commit unless the -- file option\n    is specified\n    4) Confirm \"git reset -\" works normally even when a file named @{-1} is\n    present\n\nHelped-by: David Aguilar <davvid@gmail.com>\nSigned-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n---\nI have tried to keep each test self sufficient. Please let me know if any changes are required.\nThank you!\n\n t/t7102-reset.sh | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 139 insertions(+)\n\ndiff --git a/t/t7102-reset.sh b/t/t7102-reset.sh\nindex 98bcfe2..0faf241 100755\n--- a/t/t7102-reset.sh\n+++ b/t/t7102-reset.sh\n@@ -568,4 +568,143 @@ test_expect_success 'reset --mixed sets up work tree' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'reset - with no previous branch' '\n+\tgit init no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\ttest_must_fail git reset - 2>output\n+\t) &&\n+\ttest_i18ngrep \"bad flag\" no_previous/output\n+'\n+\n+test_expect_success 'reset - while having file named - and no previous branch' '\n+\tgit init no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\t>./- &&\n+\t\ttest_must_fail git reset - 2>output\n+\t) &&\n+\ttest_i18ngrep \"bad flag\" no_previous/output\n+'\n+\n+\n+test_expect_success 'reset - in the presence of file named - with previous branch' '\n+\techo \"Unstaged changes after reset:\" >expect &&\n+\techo \"M\t-\" >>expect &&\n+\techo \"M\t1\" >>expect &&\n+\tgit init no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\t>./- &&\n+\t\t>1 &&\n+\t\tgit add 1 - &&\n+\t\tgit commit -m \"add base files\" &&\n+\t\tgit checkout -b new_branch &&\n+\t\techo \"random\" >./- &&\n+\t\techo \"wow\" >1 &&\n+\t\tgit add 1 - &&\n+\t\tgit reset - >../output\n+\t) &&\n+\trm -rf no_previous &&\n+\ttest_cmp output expect\n+'\n+test_expect_success 'reset - in the presence of file named - with -- option' '\n+\techo \"Unstaged changes after reset:\" >expect &&\n+\techo \"M\t-\" >>expect &&\n+\techo \"M\t1\" >>expect &&\n+\tgit init no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\t>./- &&\n+\t\t>1 &&\n+\t\tgit add 1 - &&\n+\t\tgit commit -m \"add base files\" &&\n+\t\tgit checkout -b new_branch &&\n+\t\techo \"random\" >./- &&\n+\t\techo \"wow\" >1 &&\n+\t\tgit add 1 - &&\n+\t\tgit reset - -- >../output\n+\t) &&\n+\trm -rf no_previous &&\n+\ttest_cmp output expect\n+'\n+\n+test_expect_success 'reset - in the presence of file named - with -- file option' '\n+\techo \"Unstaged changes after reset:\" >expect &&\n+\techo \"M\t-\" >>expect &&\n+\tgit init no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\t>./- &&\n+\t\t>1 &&\n+\t\tgit add 1 - &&\n+\t\tgit commit -m \"add base files\" &&\n+\t\tgit checkout -b new_branch &&\n+\t\techo \"random\" >./- &&\n+\t\techo \"wow\" >1 &&\n+\t\tgit add 1 - &&\n+\t\tgit reset -- - >../output\n+\t) &&\n+\trm -rf no_previous\n+\ttest_cmp output expect\n+'\n+test_expect_success 'reset - in the presence of file named - with both pre and post -- option' '\n+\techo \"Unstaged changes after reset:\" >expect &&\n+\techo \"M\t-\" >>expect &&\n+\tgit init no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\t>./- &&\n+\t\t>1 &&\n+\t\tgit add 1 - &&\n+\t\tgit commit -m \"add base files\" &&\n+\t\tgit checkout -b new_branch &&\n+\t\techo \"random\" >./- &&\n+\t\techo \"wow\" >1 &&\n+\t\tgit add 1 - &&\n+\t\tgit reset - -- - >../output\n+\t) &&\n+\trm -rf no_previous\n+\ttest_cmp output expect\n+'\n+\n+test_expect_success 'reset - works same as reset @{-1}' '\n+\tgit init no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\techo \"random\" >random &&\n+\t\tgit add random &&\n+\t\tgit commit -m \"base commit\" &&\n+\t\tgit checkout -b temp &&\n+\t\techo new-file >new-file &&\n+\t\tgit add new-file &&\n+\t\tgit commit -m \"added new-file\" &&\n+\t\tgit reset - &&\n+\t\tgit status --porcelain >../first &&\n+\t\tgit add new-file &&\n+\t\tgit commit -m \"added new-file\" &&\n+\t\tgit reset @{-1} &&\n+\t\tgit status --porcelain >../second\n+\t) &&\n+\ttest_cmp first second\n+'\n+\n+test_expect_success 'reset - with file named @{-1}' '\n+\techo \"Unstaged changes after reset:\" >expect &&\n+\techo \"M\t@{-1}\" >>expect &&\n+\tgit init no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\techo \"random\" >./@{-1} &&\n+\t\tgit add ./@{-1} &&\n+\t\tgit commit -m \"base commit\" &&\n+\t\tgit checkout -b new_branch &&\n+\t\techo \"additional stuff\" >>./@{-1} &&\n+\t\tgit add ./@{-1} &&\n+\t\tgit reset - >../output\n+\t) &&\n+\trm -rf no_previous &&\n+\ttest_cmp output expect\n+'\n+\n test_done\n-- \n2.3.1.279.gd534259\n"},{"id":"257466","messageId":"vpqioe9xa83.fsf@anie.imag.fr","threadId":"38772","inReplyTo":"1425984728-27996-1-git-send-email-sudshekhar02@gmail.com","subject":"Re: [PATCH v3 1/2] reset: enable '-' short-hand for previous branch","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2015-03-10T13:17:48Z","receivedAt":"2015-03-10T13:17:48Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Sudhanshu Shekhar <sudshekhar02@gmail.com> writes:\n\n>  \t*rev_ret = rev;\n> -\n>  \tif (read_cache() < 0)\n\nPlease don't make whitespace-only changes like this in your patches.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"257467","messageId":"vpqa8zlx9td.fsf@anie.imag.fr","threadId":"38772","inReplyTo":"1425984728-27996-2-git-send-email-sudshekhar02@gmail.com","subject":"Re: [PATCH v3 2/2] Added tests for reset -","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2015-03-10T13:26:38Z","receivedAt":"2015-03-10T13:26:38Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Sudhanshu Shekhar <sudshekhar02@gmail.com> writes:\n\n> +test_expect_success 'reset - while having file named - and no previous branch' '\n\nI like having the expected behavior in the test name too. e.g. add\n\"fails\" at the end of the sentence.\n\n> +test_expect_success 'reset - in the presence of file named - with previous branch' '\n> +\techo \"Unstaged changes after reset:\" >expect &&\n> +\techo \"M\t-\" >>expect &&\n> +\techo \"M\t1\" >>expect &&\n\nHere and elsewhere: why not\n\n\tcat >expect <<-EOF\n\tUnstaged changes after reset:\n\tM -\n\tM 1\n\n?\n\n> +\trm -rf no_previous &&\n\nThat would be best done in a test_when_finished, so that the directory\nis removed regardless of whether the test failed before this line or\nnot.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"257484","messageId":"CAODo60p_2deueOS5nYfHPTMas=GcHR4n8dNs8HJt-ZR+2SifzA@mail.gmail.com","threadId":"38772","inReplyTo":"vpqa8zlx9td.fsf@anie.imag.fr","subject":"Re: [PATCH v3 2/2] Added tests for reset -","fromName":"Sudhanshu Shekhar","fromEmail":"sudshekhar02@gmail.com","sentAt":"2015-03-10T17:52:07Z","receivedAt":"2015-03-10T17:52:07Z","isPatch":true,"sender":{"key":"sudshekhar02@gmail.com","avatar":null},"body":"Hi,\n\nOn Tue, Mar 10, 2015 at 6:56 PM, Matthieu Moy\n<Matthieu.Moy@grenoble-inp.fr> wrote:\n> Sudhanshu Shekhar <sudshekhar02@gmail.com> writes:\n>\n>> +test_expect_success 'reset - while having file named - and no previous branch' '\n>\n> I like having the expected behavior in the test name too. e.g. add\n> \"fails\" at the end of the sentence.\n>\nSure. I will update this in the next patch.\n\n>> +test_expect_success 'reset - in the presence of file named - with previous branch' '\n>> +     echo \"Unstaged changes after reset:\" >expect &&\n>> +     echo \"M -\" >>expect &&\n>> +     echo \"M 1\" >>expect &&\n>\n> Here and elsewhere: why not\n>\n>         cat >expect <<-EOF\n>         Unstaged changes after reset:\n>         M -\n>         M 1\n>\n> ?\n\nI was confused whether to use cat or echo. I thought using cat will\ndisrupt the indentation as the EOF needs to be on a single line. This\nis why I chose echo. Please let me know your thoughts on this.\n\n>> +     rm -rf no_previous &&\n>\n> That would be best done in a test_when_finished, so that the directory\n> is removed regardless of whether the test failed before this line or\n> not.\nThanks for pointing this out. I will update this accordingly.\n>\n> --\n> Matthieu Moy\n> http://www-verimag.imag.fr/~moy/\n\nRegards,\nSudhanshu\n"},{"id":"257485","messageId":"CAPig+cSqJcfNRXmLdHXvHvUiv1NFgXA6cZ4YFyxoWuyivjWUEQ@mail.gmail.com","threadId":"38772","inReplyTo":"CAODo60p_2deueOS5nYfHPTMas=GcHR4n8dNs8HJt-ZR+2SifzA@mail.gmail.com","subject":"Re: [PATCH v3 2/2] Added tests for reset -","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2015-03-10T18:05:37Z","receivedAt":"2015-03-10T18:05:37Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 10, 2015 at 1:52 PM, Sudhanshu Shekhar\n<sudshekhar02@gmail.com> wrote:\n> On Tue, Mar 10, 2015 at 6:56 PM, Matthieu Moy\n> <Matthieu.Moy@grenoble-inp.fr> wrote:\n>> Sudhanshu Shekhar <sudshekhar02@gmail.com> writes:\n>>> +test_expect_success 'reset - in the presence of file named - with previous branch' '\n>>> +     echo \"Unstaged changes after reset:\" >expect &&\n>>> +     echo \"M -\" >>expect &&\n>>> +     echo \"M 1\" >>expect &&\n>>\n>> Here and elsewhere: why not\n>>\n>>         cat >expect <<-EOF\n>>         Unstaged changes after reset:\n>>         M -\n>>         M 1\n>>\n>> ?\n> I was confused whether to use cat or echo. I thought using cat will\n> disrupt the indentation as the EOF needs to be on a single line. This\n> is why I chose echo. Please let me know your thoughts on this.\n\nHere-docs are easier to compose and read than individual 'echo'\nstatements for multi-line content.\n\nThe '-' in front of EOF allows you to indent the entire body. Even\nbetter, use -\\EOF to signify that you don't expect any interpolation\nto occur within the body.\n"},{"id":"257487","messageId":"CAPig+cSU7X=1Ket8bAXU2JivaSVWw7C_M9ttAhJ_gQur3utsUA@mail.gmail.com","threadId":"38772","inReplyTo":"1425984728-27996-2-git-send-email-sudshekhar02@gmail.com","subject":"Re: [PATCH v3 2/2] Added tests for reset -","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2015-03-10T18:29:00Z","receivedAt":"2015-03-10T18:29:00Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 10, 2015 at 6:52 AM, Sudhanshu Shekhar\n<sudshekhar02@gmail.com> wrote:\n> Added tests for reset -\n\nMention the area of the project you are changing, followed by a colon,\nfollowed by a short summary of the change. Drop capitalization. Write\nin imperative mood.\n\n    t7102: add 'reset -' tests\n\n> Added the following test cases:\n\nImperative mood: \"Add test cases:\"\n\n>     1) Confirm error message when git reset is used with no previous branch\n>     2) Confirm git reset - works like git reset @{-1}\n>     3) Confirm \"-\" is always treated as a commit unless the -- file option\n>     is specified\n>     4) Confirm \"git reset -\" works normally even when a file named @{-1} is\n>     present\n>\n> Helped-by: David Aguilar <davvid@gmail.com>\n> Signed-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n> ---\n> diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh\n> index 98bcfe2..0faf241 100755\n> --- a/t/t7102-reset.sh\n> +++ b/t/t7102-reset.sh\n> @@ -568,4 +568,143 @@ test_expect_success 'reset --mixed sets up work tree' '\n>         test_cmp expect actual\n>  '\n>\n> +test_expect_success 'reset - in the presence of file named - with previous branch' '\n> +       echo \"Unstaged changes after reset:\" >expect &&\n> +       echo \"M -\" >>expect &&\n> +       echo \"M 1\" >>expect &&\n\nMentioned by Matthieu: Use \"cat <<-\\EOF\".\n\n> +       git init no_previous &&\n> +       (\n> +               cd no_previous &&\n> +               >./- &&\n\nUnnecessarily complex \">./-\" when \">-\" will suffice.\n\n> +               >1 &&\n> +               git add 1 - &&\n> +               git commit -m \"add base files\" &&\n> +               git checkout -b new_branch &&\n> +               echo \"random\" >./- &&\n> +               echo \"wow\" >1 &&\n> +               git add 1 - &&\n> +               git reset - >../output\n\nSince you will be comparing this output with \"expected\" output, it is\ncustomary to name this file \"actual\".\n\n> +       ) &&\n> +       rm -rf no_previous &&\n\nMentioned by Matthieu: Use test_when_finished(). You want this cleanup\naction invoked even if any part of the test fails, so register it as\nearly as possible for it to be effective; either just before or after\ngit-init.\n\n> +       test_cmp output expect\n\nWhen test_cmp() detects a difference in the expected and actual\noutput, it dumps the difference (in 'diff' format) as debugging\noutput. It's easier to read 'diff' output, and matches our\nexpectations more closely, if 'expect' is mentioned before 'actual',\nso:\n\n    test_cmp expect actual\n\n> +'\n> +test_expect_success 'reset - in the presence of file named - with -- file option' '\n> +       echo \"Unstaged changes after reset:\" >expect &&\n> +       echo \"M -\" >>expect &&\n> +       git init no_previous &&\n> +       (\n> +               cd no_previous &&\n> +               >./- &&\n> +               >1 &&\n> +               git add 1 - &&\n> +               git commit -m \"add base files\" &&\n> +               git checkout -b new_branch &&\n> +               echo \"random\" >./- &&\n> +               echo \"wow\" >1 &&\n> +               git add 1 - &&\n> +               git reset -- - >../output\n> +       ) &&\n> +       rm -rf no_previous\n\nBroken &&-chain.\n\n> +       test_cmp output expect\n> +'\n> +test_expect_success 'reset - in the presence of file named - with both pre and post -- option' '\n> +       echo \"Unstaged changes after reset:\" >expect &&\n> +       echo \"M -\" >>expect &&\n> +       git init no_previous &&\n> +       (\n> +               cd no_previous &&\n> +               >./- &&\n> +               >1 &&\n> +               git add 1 - &&\n> +               git commit -m \"add base files\" &&\n> +               git checkout -b new_branch &&\n> +               echo \"random\" >./- &&\n> +               echo \"wow\" >1 &&\n> +               git add 1 - &&\n> +               git reset - -- - >../output\n> +       ) &&\n> +       rm -rf no_previous\n\nBroken &&-chain.\n\n> +       test_cmp output expect\n> +'\n> +\n> +test_expect_success 'reset - works same as reset @{-1}' '\n> +       git init no_previous &&\n> +       (\n> +               cd no_previous &&\n> +               echo \"random\" >random &&\n> +               git add random &&\n> +               git commit -m \"base commit\" &&\n> +               git checkout -b temp &&\n> +               echo new-file >new-file &&\n> +               git add new-file &&\n> +               git commit -m \"added new-file\" &&\n> +               git reset - &&\n> +               git status --porcelain >../first &&\n> +               git add new-file &&\n> +               git commit -m \"added new-file\" &&\n> +               git reset @{-1} &&\n> +               git status --porcelain >../second\n> +       ) &&\n\nIn other tests, you performed \"rm -rf no_previous &&\" cleanup at this\npoint, but it's missing here.\n\n> +       test_cmp first second\n> +'\n> +\n> +test_expect_success 'reset - with file named @{-1}' '\n> +       echo \"Unstaged changes after reset:\" >expect &&\n> +       echo \"M @{-1}\" >>expect &&\n> +       git init no_previous &&\n> +       (\n> +               cd no_previous &&\n> +               echo \"random\" >./@{-1} &&\n> +               git add ./@{-1} &&\n> +               git commit -m \"base commit\" &&\n> +               git checkout -b new_branch &&\n> +               echo \"additional stuff\" >>./@{-1} &&\n> +               git add ./@{-1} &&\n> +               git reset - >../output\n> +       ) &&\n> +       rm -rf no_previous &&\n> +       test_cmp output expect\n> +'\n> +\n>  test_done\n> --\n> 2.3.1.279.gd534259\n"},{"id":"257489","messageId":"CAPig+cQdSHQTVwOwb9hee6On_Bv4qrh0MhiR-aRDMXqhw5L9wQ@mail.gmail.com","threadId":"38772","inReplyTo":"1425984728-27996-1-git-send-email-sudshekhar02@gmail.com","subject":"Re: [PATCH v3 1/2] reset: enable '-' short-hand for previous branch","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2015-03-10T19:18:32Z","receivedAt":"2015-03-10T19:18:32Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 10, 2015 at 6:52 AM, Sudhanshu Shekhar\n<sudshekhar02@gmail.com> wrote:\n> 'git reset -' will reset to the previous branch. It will behave similar\n> to @{-1} except when a file named '@{-1}' is present. To refer to a file\n> named '-', use ./- or the -- flag.\n>\n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com>\n> Helped-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>\n> Signed-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n> ---\n> diff --git a/builtin/reset.c b/builtin/reset.c\n> index 4c08ddc..8abd300 100644\n> --- a/builtin/reset.c\n> +++ b/builtin/reset.c\n> @@ -205,6 +206,10 @@ static void parse_args(struct pathspec *pathspec,\n>          */\n>\n>         if (argv[0]) {\n> +               if (!strcmp(argv[0], \"-\")) {\n> +                       argv[0] = \"@{-1}\";\n\nIt's somewhat ugly to modify an element of argv[] since you don't own\nthe array and the contract does not particularly suggest that is\nmodifiable by you. A more serious concern is that doing so creates a\ntighter binding between parse_args() and its caller since parse_args()\ndoesn't know how the caller will be disposing of argv[] when finished\nwith it. Say, for instance, that the caller disposes of each argv[]\nelement by invoking free(argv[n]). The literal \"@{-1}\" you've assigned\nhere is not allocated on the heap, so free()ing it would be wrong.\n\nHowever, some of the other commands which alias \"-\" to \"@{-1}\" also\nmodify argv[] in this way, so we'll let it slide for the moment.\n\n> +                       substituted_minus = 1;\n> +               }\n>                 if (!strcmp(argv[0], \"--\")) {\n>                         argv++; /* reset to HEAD, possibly with paths */\n>                 } else if (argv[1] && !strcmp(argv[1], \"--\")) {\n> @@ -222,15 +227,21 @@ static void parse_args(struct pathspec *pathspec,\n>                          * Ok, argv[0] looks like a commit/tree; it should not\n>                          * be a filename.\n>                          */\n> +                       if (substituted_minus)\n> +                               argv[0] = \"-\";\n>                         verify_non_filename(prefix, argv[0]);\n> +                       if (substituted_minus)\n> +                               argv[0] = \"@{-1}\";\n\nDo you find it ugly that you have to undo and then redo your argv[]\nchange from a few lines above? Rather than jumping through such hoops,\ncan't you instead define a new variable which holds the appropriate\nvalue (\"@{-1}\"), or rework the logic to avoid such kludges altogether?\n\n>                         rev = *argv++;\n>                 } else {\n> +                       /* We were treating \"-\" as a commit and not a file */\n> +                       if (substituted_minus)\n> +                               argv[0] = \"-\";\n>                         /* Otherwise we treat this as a filename */\n>                         verify_filename(prefix, argv[0], 1);\n>                 }\n>         }\n>         *rev_ret = rev;\n> -\n\nMentioned by Matthieu: Don't sneak in unrelated changes. This change\nwas probably unintentional, but serves as a good reminder that you\nshould review the patch yourself before sending it. (And, if you do\nhave a need to make cleanups, it's typically best to do so as a\nseparate preparatory patch.)\n\n>         if (read_cache() < 0)\n>                 die(_(\"index file corrupt\"));\n>\n> --\n> 2.3.1.279.gd534259\n"},{"id":"257500","messageId":"1426025006-18669-1-git-send-email-sudshekhar02@gmail.com","threadId":"38772","inReplyTo":"CAPig+cSU7X=1Ket8bAXU2JivaSVWw7C_M9ttAhJ_gQur3utsUA@mail.gmail.com","subject":"[PATCH v3 1/2] reset: enable '-' short-hand for previous branch","fromName":"Sudhanshu Shekhar","fromEmail":"sudshekhar02@gmail.com","sentAt":"2015-03-10T22:03:26Z","receivedAt":"2015-03-10T22:03:26Z","isPatch":true,"sender":{"key":"sudshekhar02@gmail.com","avatar":null},"body":"git reset -' will reset to the previous branch. It will behave similar\nto @{-1} except when a file named '@{-1}' is present. To refer to a file\nnamed '-', use ./- or the -- flag.\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nHelped-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>\nSigned-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n---\nEric, I have added a user_input variable to record the input entered by the user. This way I can avoid the multiple 'if' clauses. Thank you for the suggestion.\nI have also removed the unrelated change that I had unintentionally committed. I am sending this patch on the thread for further review. Once both the patches are reviewed and accepted, I will create a new mail for it. Hope that is okay.\n\nRegards,\nSudhanshu\n\n builtin/reset.c | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 4c08ddc..b428241 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -192,6 +192,8 @@ static void parse_args(struct pathspec *pathspec,\n {\n \tconst char *rev = \"HEAD\";\n \tunsigned char unused[20];\n+\tint substituted_minus = 0;\n+\tchar *user_input = argv[0];\n \t/*\n \t * Possible arguments are:\n \t *\n@@ -205,6 +207,10 @@ static void parse_args(struct pathspec *pathspec,\n \t */\n \n \tif (argv[0]) {\n+\t\tif (!strcmp(argv[0], \"-\")) {\n+\t\t\targv[0] = \"@{-1}\";\n+\t\t\tsubstituted_minus = 1;\n+\t\t}\n \t\tif (!strcmp(argv[0], \"--\")) {\n \t\t\targv++; /* reset to HEAD, possibly with paths */\n \t\t} else if (argv[1] && !strcmp(argv[1], \"--\")) {\n@@ -222,9 +228,12 @@ static void parse_args(struct pathspec *pathspec,\n \t\t\t * Ok, argv[0] looks like a commit/tree; it should not\n \t\t\t * be a filename.\n \t\t\t */\n-\t\t\tverify_non_filename(prefix, argv[0]);\n+\t\t\tverify_non_filename(prefix, user_input);\n \t\t\trev = *argv++;\n \t\t} else {\n+\t\t\t/* We were treating \"-\" as a commit and not a file */\n+\t\t\tif (substituted_minus)\n+\t\t\t\targv[0] = \"-\";\n \t\t\t/* Otherwise we treat this as a filename */\n \t\t\tverify_filename(prefix, argv[0], 1);\n \t\t}\n-- \n2.3.1.278.ge5c7b1f.dirty\n"},{"id":"257502","messageId":"1426025409-18758-1-git-send-email-sudshekhar02@gmail.com","threadId":"38772","inReplyTo":"CAPig+cSU7X=1Ket8bAXU2JivaSVWw7C_M9ttAhJ_gQur3utsUA@mail.gmail.com","subject":"[PATCH v3 2/2] t7102: add 'reset -' tests","fromName":"Sudhanshu Shekhar","fromEmail":"sudshekhar02@gmail.com","sentAt":"2015-03-10T22:10:09Z","receivedAt":"2015-03-10T22:10:09Z","isPatch":true,"sender":{"key":"sudshekhar02@gmail.com","avatar":null},"body":"Add following test cases:\n\n1) Confirm error message when git reset is used with no previous branch\n2) Confirm git reset - works like git reset @{-1}\n3) Confirm \"-\" is always treated as a commit unless the -- file option is specified\n4) Confirm \"git reset -\" works normally even when a file named @{-1} is present\n\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nHelped-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>\nHelped-by: David Aguilar <davvid@gmail.com>\nSigned-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n---\nFirst of all, thank you for being so incredibly patient and helpful. I am very grateful for your remarks and reviews. I have implemented your suggestions in this patch. Please let me know if I have missed out on anything else. Also, sorry for sending PATCH 1/2 on the wrong thread, I entered the Message-ID incorrectly (still getting used to send-email :/ ).\n\nRegards,\nSudhanshu\n\n t/t7102-reset.sh | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 159 insertions(+)\n\ndiff --git a/t/t7102-reset.sh b/t/t7102-reset.sh\nindex 98bcfe2..d3a5874 100755\n--- a/t/t7102-reset.sh\n+++ b/t/t7102-reset.sh\n@@ -568,4 +568,163 @@ test_expect_success 'reset --mixed sets up work tree' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'reset - with no previous branch fails' '\n+\tgit init no_previous &&\n+\ttest_when_finished rm -rf no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\ttest_must_fail git reset - 2>actual\n+\t) &&\n+\ttest_i18ngrep \"bad flag\" no_previous/actual\n+'\n+\n+test_expect_success 'reset - while having file named - and no previous branch fails' '\n+\tgit init no_previous &&\n+\ttest_when_finished rm -rf no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\t>- &&\n+\t\ttest_must_fail git reset - 2>actual\n+\t) &&\n+\ttest_i18ngrep \"bad flag\" no_previous/actual\n+'\n+\n+test_expect_success \\\n+\t'reset - in the presence of file named - with previous branch resets commit' '\n+\tcat >expect <<-\\EOF\n+\tUnstaged changes after reset:\n+\tM\t-\n+\tM\tfile\n+\tEOF &&\n+\tgit init no_previous &&\n+\ttest_when_finished rm -rf no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\t>- &&\n+\t\t>file &&\n+\t\tgit add file - &&\n+\t\tgit commit -m \"add base files\" &&\n+\t\tgit checkout -b new_branch &&\n+\t\techo \"random\" >- &&\n+\t\techo \"wow\" >file &&\n+\t\tgit add file - &&\n+\t\tgit reset - >../actual\n+\t) &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success \\\n+\t'reset - in the presence of file named - with -- option resets commit' '\n+\tcat >expect <<-\\EOF\n+\tUnstaged changes after reset:\n+\tM\t-\n+\tM\tfile\n+\tEOF &&\n+\tgit init no_previous &&\n+\ttest_when_finished rm -rf no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\t>- &&\n+\t\t>file &&\n+\t\tgit add file - &&\n+\t\tgit commit -m \"add base files\" &&\n+\t\tgit checkout -b new_branch &&\n+\t\techo \"random\" >- &&\n+\t\techo \"wow\" >file &&\n+\t\tgit add file - &&\n+\t\tgit reset - -- >../actual\n+\t) &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'reset - in the presence of file named - with -- file option resets file' '\n+\tcat >expect <<-\\EOF\n+\tUnstaged changes after reset:\n+\tM\t-\n+\tM\tfile\n+\tEOF &&\n+\tgit init no_previous &&\n+\ttest_when_finished rm -rf no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\t>- &&\n+\t\t>file &&\n+\t\tgit add file - &&\n+\t\tgit commit -m \"add base files\" &&\n+\t\tgit checkout -b new_branch &&\n+\t\techo \"random\" >- &&\n+\t\techo \"wow\" >file &&\n+\t\tgit add file - &&\n+\t\tgit reset -- - >../actual\n+\t) &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success \\\n+\t'reset - in the presence of file named - with both pre and post -- option resets file' '\n+\tcat >expect <<-\\EOF\n+\tUnstaged changes after reset:\" >expect &&\n+\tM\t-\n+\tEOF &&\n+\tgit init no_previous &&\n+\ttest_when_finished rm -rf no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\t>- &&\n+\t\t>file &&\n+\t\tgit add file - &&\n+\t\tgit commit -m \"add base files\" &&\n+\t\tgit checkout -b new_branch &&\n+\t\techo \"random\" >- &&\n+\t\techo \"wow\" >file &&\n+\t\tgit add file - &&\n+\t\tgit reset - -- - >../actual\n+\t) &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'reset - works same as reset @{-1}' '\n+\tgit init no_previous &&\n+\ttest_when_finished rm -rf no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\techo \"file1\" >file1 &&\n+\t\tgit add file1 &&\n+\t\tgit commit -m \"base commit\" &&\n+\t\tgit checkout -b temp &&\n+\t\techo \"new file\" >file &&\n+\t\tgit add file &&\n+\t\tgit commit -m \"added file\" &&\n+\t\tgit reset - &&\n+\t\tgit status --porcelain >../actual &&\n+\t\tgit add file &&\n+\t\tgit commit -m \"added file\" &&\n+\t\tgit reset @{-1} &&\n+\t\tgit status --porcelain >../expect\n+\t) &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'reset - with file named @{-1} succeeds' '\n+\tcat >expect <<EOF\n+\tUnstaged changes after reset:\n+\tM\tfile\n+\tM\t@{-1}\n+\tEOF &&\n+\tgit init no_previous &&\n+\ttest_when_finished rm -rf no_previous &&\n+\t(\n+\t\tcd no_previous &&\n+\t\techo \"random\" >@{-1} &&\n+\t\techo \"random\" >file &&\n+\t\tgit add @{-1} file &&\n+\t\tgit commit -m \"base commit\" &&\n+\t\tgit checkout -b new_branch &&\n+\t\techo \"additional stuff\" >>file &&\n+\t\techo \"additional stuff\" >>@{-1} &&\n+\t\tgit add file @{-1} &&\n+\t\tgit reset - >../actual\n+\t) &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.3.1.278.ge5c7b1f.dirty\n"},{"id":"257503","messageId":"1426025535-18857-1-git-send-email-sudshekhar02@gmail.com","threadId":"38772","inReplyTo":"CAPig+cQdSHQTVwOwb9hee6On_Bv4qrh0MhiR-aRDMXqhw5L9wQ@mail.gmail.com","subject":"[PATCH v3 1/2] reset: enable '-' short-hand for previous branch","fromName":"Sudhanshu Shekhar","fromEmail":"sudshekhar02@gmail.com","sentAt":"2015-03-10T22:12:15Z","receivedAt":"2015-03-10T22:12:15Z","isPatch":true,"sender":{"key":"sudshekhar02@gmail.com","avatar":null},"body":"git reset -' will reset to the previous branch. It will behave similar\nto @{-1} except when a file named '@{-1}' is present. To refer to a file\nnamed '-', use ./- or the -- flag.\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nHelped-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>\nSigned-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n---\nEric, I have added a user_input variable to record the input entered by the user. This way I can avoid the multiple 'if' clauses. Thank you for the suggestion.\nI have also removed the unrelated change that I had unintentionally committed. I am sending this patch on the thread for further review. Once both the patches are reviewed and accepted, I will create a new mail for it. Hope that is okay.\n\nRegards,\nSudhanshu\n\n builtin/reset.c | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 4c08ddc..b428241 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -192,6 +192,8 @@ static void parse_args(struct pathspec *pathspec,\n {\n \tconst char *rev = \"HEAD\";\n \tunsigned char unused[20];\n+\tint substituted_minus = 0;\n+\tchar *user_input = argv[0];\n \t/*\n \t * Possible arguments are:\n \t *\n@@ -205,6 +207,10 @@ static void parse_args(struct pathspec *pathspec,\n \t */\n \n \tif (argv[0]) {\n+\t\tif (!strcmp(argv[0], \"-\")) {\n+\t\t\targv[0] = \"@{-1}\";\n+\t\t\tsubstituted_minus = 1;\n+\t\t}\n \t\tif (!strcmp(argv[0], \"--\")) {\n \t\t\targv++; /* reset to HEAD, possibly with paths */\n \t\t} else if (argv[1] && !strcmp(argv[1], \"--\")) {\n@@ -222,9 +228,12 @@ static void parse_args(struct pathspec *pathspec,\n \t\t\t * Ok, argv[0] looks like a commit/tree; it should not\n \t\t\t * be a filename.\n \t\t\t */\n-\t\t\tverify_non_filename(prefix, argv[0]);\n+\t\t\tverify_non_filename(prefix, user_input);\n \t\t\trev = *argv++;\n \t\t} else {\n+\t\t\t/* We were treating \"-\" as a commit and not a file */\n+\t\t\tif (substituted_minus)\n+\t\t\t\targv[0] = \"-\";\n \t\t\t/* Otherwise we treat this as a filename */\n \t\t\tverify_filename(prefix, argv[0], 1);\n \t\t}\n-- \n2.3.1.278.ge5c7b1f.dirty\n"},{"id":"257640","messageId":"CAPig+cQWZ7_ayMRFnm1U-Xza6FS9aTbHnyXYpAx-2-H4e6vcNA@mail.gmail.com","threadId":"38772","inReplyTo":"1426025006-18669-1-git-send-email-sudshekhar02@gmail.com","subject":"Re: [PATCH v3 1/2] reset: enable '-' short-hand for previous branch","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2015-03-13T10:11:48Z","receivedAt":"2015-03-13T10:11:48Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 10, 2015 at 6:03 PM, Sudhanshu Shekhar\n<sudshekhar02@gmail.com> wrote:\n> [PATCH v3 1/2] reset: enable '-' short-hand for previous branch\n\nThis should be v4, I think, not v3.\n\n> git reset -' will reset to the previous branch. It will behave similar\n> to @{-1} except when a file named '@{-1}' is present.\n\nThe way this is phrased, the reader is left hanging: \"What happens\nwhen a file named @{-1} is present?\"\n\n> To refer to a file named '-', use ./- or the -- flag.\n\nA documentation update to reflect this change would be appropriate.\nSee, for instance, 696acf45 (checkout: implement \"-\" abbreviation, add\ndocs and tests;  2009-01-17).\n\n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com>\n> Helped-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>\n> Signed-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n> ---\n> Eric, I have added a user_input variable to record the input entered\n> by the user. This way I can avoid the multiple 'if' clauses. Thank you\n> for the suggestion.\n>\n> I have also removed the unrelated change that I had unintentionally\n> committed. I am sending this patch on the thread for further review.\n> Once both the patches are reviewed and accepted, I will create a new\n> mail for it. Hope that is okay.\n\nPlease wrap commentary to about 72 columns, just as you would the\ncommit message, rather than typing it all on a single line. (I wrapped\nit manually here in order to reply to it.)\n\n> diff --git a/builtin/reset.c b/builtin/reset.c\n> index 4c08ddc..b428241 100644\n> --- a/builtin/reset.c\n> +++ b/builtin/reset.c\n> @@ -192,6 +192,8 @@ static void parse_args(struct pathspec *pathspec,\n>  {\n>         const char *rev = \"HEAD\";\n>         unsigned char unused[20];\n> +       int substituted_minus = 0;\n> +       char *user_input = argv[0];\n\nYou're assigning a 'const char *' to a 'char *'. The compiler should\nhave warned about it.\n\nThis variable name is not as expressive as it could be. Try to name\nthe variable after what you expect it to represent, for instance\n\"maybe_rev\" or \"rev_or_path\" or something more suitable. Even\n\"orig_argv0\" would be more informative than \"user_input\".\n\n>         /*\n>          * Possible arguments are:\n>          *\n> @@ -205,6 +207,10 @@ static void parse_args(struct pathspec *pathspec,\n>          */\n>\n>         if (argv[0]) {\n> +               if (!strcmp(argv[0], \"-\")) {\n> +                       argv[0] = \"@{-1}\";\n> +                       substituted_minus = 1;\n> +               }\n>                 if (!strcmp(argv[0], \"--\")) {\n>                         argv++; /* reset to HEAD, possibly with paths */\n>                 } else if (argv[1] && !strcmp(argv[1], \"--\")) {\n> @@ -222,9 +228,12 @@ static void parse_args(struct pathspec *pathspec,\n>                          * Ok, argv[0] looks like a commit/tree; it should not\n>                          * be a filename.\n>                          */\n> -                       verify_non_filename(prefix, argv[0]);\n> +                       verify_non_filename(prefix, user_input);\n>                         rev = *argv++;\n>                 } else {\n> +                       /* We were treating \"-\" as a commit and not a file */\n> +                       if (substituted_minus)\n> +                               argv[0] = \"-\";\n\nIn my review of the previous version[1], I mentioned that it was ugly\nto muck with argv[0]; moreover that it was particularly ugly to have\nto muck with it multiple times, undoing and redoing assignments.\nAlthough you've eliminated some reassignments via 'user_input', my\nintent, by asking if you could rework the logic, was to prompt you to\ntake a couple steps back and examine the overall logic of the function\nmore closely. The munging of argv[0] is effectively a fragile and\nundesirable band-aid approach. It is possible to support '-' as an\nalias for '@{-1}' without having to resort to such kludges at all.\n\nOne other concern: When there is no previous branch, and no file named\n\"-\", then 'git reset -' misleadingly complains \"bad flag '-' used\nafter filename\", rather than the more appropriate \"ambiguous argument\n'-': unknown revision or path\".\n\n[1]: http://article.gmane.org/gmane.comp.version-control.git/265255\n\n>                         /* Otherwise we treat this as a filename */\n>                         verify_filename(prefix, argv[0], 1);\n>                 }\n> --\n> 2.3.1.278.ge5c7b1f.dirty\n"},{"id":"257641","messageId":"CAPig+cSxuS0Khg2a0K1+K3UXH-TTgMREH30qYMt4cs0eCMbjiQ@mail.gmail.com","threadId":"38772","inReplyTo":"1426025409-18758-1-git-send-email-sudshekhar02@gmail.com","subject":"Re: [PATCH v3 2/2] t7102: add 'reset -' tests","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2015-03-13T10:27:46Z","receivedAt":"2015-03-13T10:27:46Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 10, 2015 at 6:10 PM, Sudhanshu Shekhar\n<sudshekhar02@gmail.com> wrote:\n> Add following test cases:\n>\n> 1) Confirm error message when git reset is used with no previous branch\n> 2) Confirm git reset - works like git reset @{-1}\n> 3) Confirm \"-\" is always treated as a commit unless the -- file option is specified\n> 4) Confirm \"git reset -\" works normally even when a file named @{-1} is present\n\nDoes it concern you that all new tests pass except the last one even\nwhen patch 1/2 is not applied? I would have expected most or all of\nthese tests to fail without patch 1/2.\n\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com>\n> Helped-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>\n> Helped-by: David Aguilar <davvid@gmail.com>\n> Signed-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n> ---\n> diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh\n> index 98bcfe2..d3a5874 100755\n> --- a/t/t7102-reset.sh\n> +++ b/t/t7102-reset.sh\n> @@ -568,4 +568,163 @@ test_expect_success 'reset --mixed sets up work tree' '\n>         test_cmp expect actual\n>  '\n>\n> +test_expect_success 'reset - with no previous branch fails' '\n> +       git init no_previous &&\n\nI understand the intention of the name \"no_previous\" in tests for\nwhich there is no @{-1}, however...\n\n> +       test_when_finished rm -rf no_previous &&\n> +       (\n> +               cd no_previous &&\n> +               test_must_fail git reset - 2>actual\n> +       ) &&\n> +       test_i18ngrep \"bad flag\" no_previous/actual\n> +'\n> +\n> +test_expect_success 'reset - while having file named - and no previous branch fails' '\n> +       git init no_previous &&\n> +       test_when_finished rm -rf no_previous &&\n> +       (\n> +               cd no_previous &&\n> +               >- &&\n> +               test_must_fail git reset - 2>actual\n> +       ) &&\n> +       test_i18ngrep \"bad flag\" no_previous/actual\n> +'\n> +\n> +test_expect_success \\\n> +       'reset - in the presence of file named - with previous branch resets commit' '\n> +       cat >expect <<-\\EOF\n> +       Unstaged changes after reset:\n> +       M       -\n> +       M       file\n> +       EOF &&\n> +       git init no_previous &&\n\nI don't understand the name \"no_previous\" in tests for which @{-1} can\nresolve. It probably would be better to choose a more generic name and\nuse it for all these tests. For instance, \"resetdash\" or just \"dash\"\nor something better.\n\n> +       test_when_finished rm -rf no_previous &&\n> +       (\n> +               cd no_previous &&\n> +               >- &&\n> +               >file &&\n> +               git add file - &&\n> +               git commit -m \"add base files\" &&\n> +               git checkout -b new_branch &&\n> +               echo \"random\" >- &&\n> +               echo \"wow\" >file &&\n> +               git add file - &&\n> +               git reset - >../actual\n> +       ) &&\n> +       test_cmp expect actual\n> +'\n> +\n> +test_expect_success 'reset - with file named @{-1} succeeds' '\n\nI may be missing something obvious, but why is it necessary to single\nout a file named @{-1} at all, particuarly when there are so many\nother ways to specify revisions, and there may be files mirroring\nthose spellings, as well?\n\n> +       cat >expect <<EOF\n> +       Unstaged changes after reset:\n> +       M       file\n> +       M       @{-1}\n> +       EOF &&\n> +       git init no_previous &&\n> +       test_when_finished rm -rf no_previous &&\n> +       (\n> +               cd no_previous &&\n> +               echo \"random\" >@{-1} &&\n> +               echo \"random\" >file &&\n> +               git add @{-1} file &&\n> +               git commit -m \"base commit\" &&\n> +               git checkout -b new_branch &&\n> +               echo \"additional stuff\" >>file &&\n> +               echo \"additional stuff\" >>@{-1} &&\n> +               git add file @{-1} &&\n> +               git reset - >../actual\n> +       ) &&\n> +       test_cmp expect actual\n> +'\n> +\n>  test_done\n> --\n> 2.3.1.278.ge5c7b1f.dirty\n"}]}