{"thread":{"id":"38761","subject":"[PATCH v2 2/2] Added test cases for git reset -","startedAt":"2015-03-09T08:15:35Z","lastAt":"2015-03-10T07:37:31Z","messageCount":4,"participants":["Sudhanshu Shekhar","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"257370","messageId":"1425888936-23370-1-git-send-email-sudshekhar02@gmail.com","threadId":"38761","inReplyTo":null,"subject":"[PATCH v2 1/2] Teach reset the same short-hand as checkout","fromName":"Sudhanshu Shekhar","fromEmail":"sudshekhar02@gmail.com","sentAt":"2015-03-09T08:15:35Z","receivedAt":"2015-03-09T08:15:35Z","isPatch":true,"sender":{"key":"sudshekhar02@gmail.com","avatar":null},"body":"\"-\" now means the previous branch.\n\nSigned-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\nThanks-to: Eric Sunshine, Junio C Hamano, Matthieu Moy\n---\n builtin/reset.c | 9 ++++++++-\n 1 file changed, 8 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 4c08ddc..02f33ef 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@@ -225,12 +230,14 @@ static void parse_args(struct pathspec *pathspec,\n \t\t\tverify_non_filename(prefix, argv[0]);\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.168.g0c82976.dirty\n"},{"id":"257369","messageId":"1425888936-23370-2-git-send-email-sudshekhar02@gmail.com","threadId":"38761","inReplyTo":"1425888936-23370-1-git-send-email-sudshekhar02@gmail.com","subject":"[PATCH v2 2/2] Added test cases for git reset -","fromName":"Sudhanshu Shekhar","fromEmail":"sudshekhar02@gmail.com","sentAt":"2015-03-09T08:15:36Z","receivedAt":"2015-03-09T08:15:36Z","isPatch":true,"sender":{"key":"sudshekhar02@gmail.com","avatar":null},"body":"1) 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\nis specified\n\nSigned-off-by: Sudhanshu Shekhar<sudshekhar02@gmail.com>\nThanks-to: David Aguilar<davvid@gmail.com>\n---\nDavid, thank you for your remarks. I have tried to incorporate your suggestions into this patch.\nPlease let me know if I have missed out on anything else.\n\n t/t7102-reset.sh | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 121 insertions(+)\n\ndiff --git a/t/t7102-reset.sh b/t/t7102-reset.sh\nindex 98bcfe2..fe43f64 100755\n--- a/t/t7102-reset.sh\n+++ b/t/t7102-reset.sh\n@@ -568,4 +568,125 @@ test_expect_success 'reset --mixed sets up work tree' '\n \ttest_cmp expect actual\n '\n \n+cat >expect <<EOF\n+fatal: bad flag '-' used after filename\n+EOF\n+\n+test_expect_success 'reset - with no previous branch' '\n+\tgit init no_previous --quiet &&\n+\t(\n+\t\tcd no_previous &&\n+\t\ttest_must_fail git reset - 2>output\n+\t) &&\n+\ttest_cmp expect no_previous/output\n+'\n+\n+test_expect_success 'reset - while having file named - and no previous branch' '\n+\tgit init no_previous --quiet &&\n+\t(\n+\t\tcd no_previous &&\n+\t\ttouch ./- &&\n+\t\ttest_must_fail git reset - 2>output\n+\t) &&\n+\ttest_cmp expect no_previous/output\n+'\n+\n+cat >expect <<EOF\n+Unstaged changes after reset:\n+M\t-\n+M\t1\n+EOF\n+\n+test_expect_success 'reset - in the prescence of file named - with previous branch' '\n+\tgit init no_previous --quiet &&\n+\t(\n+\t\tcd no_previous &&\n+\t\ttouch ./- 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+\tgit init no_previous --quiet &&\n+\t(\n+\t\tcd no_previous &&\n+\t\ttouch ./- 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+cat >expect <<EOF\n+Unstaged changes after reset:\n+M\t-\n+EOF\n+\n+test_expect_success 'reset - in the presence of file named - with -- file option' '\n+\tgit init no_previous --quiet &&\n+\t(\n+\t\tcd no_previous &&\n+\t\ttouch ./- 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+\tgit init no_previous --quiet &&\n+\t(\n+\t\tcd no_previous &&\n+\t\ttouch ./- 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 --quiet &&\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_done\n-- \n2.3.1.168.g0c82976.dirty\n"},{"id":"257441","messageId":"xmqq385d60o3.fsf@gitster.dls.corp.google.com","threadId":"38761","inReplyTo":"1425888936-23370-1-git-send-email-sudshekhar02@gmail.com","subject":"Re: [PATCH v2 1/2] Teach reset the same short-hand as checkout","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-03-10T02:34:04Z","receivedAt":"2015-03-10T02:34:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sudhanshu Shekhar <sudshekhar02@gmail.com> writes:\n\n> \"-\" now means the previous branch.\n>\n> Signed-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n> Thanks-to: Eric Sunshine, Junio C Hamano, Matthieu Moy\n> ---\n\n\nThese look unusual for a few reasons: your S-o-b should be at the\nend, we usually say Helped-by: instead, and we do not use these with\nmultiple names on a single line.\n\nPlease do not try to be original without a good reason.  We may\nstart counting the number of times people appear on these footers to\nsee how much contribution those who do not directly author commits\n(read: those who mentor others) are making.\n\n>  builtin/reset.c | 9 ++++++++-\n>  1 file changed, 8 insertions(+), 1 deletion(-)\n\nThe comment I gave in the thread that ends at $gmane/265112 would\napply equally to this patch, I think.\n\ncf. http://thread.gmane.org/gmane.comp.version-control.git/264986/focus=265112\n"},{"id":"257448","messageId":"CAODo60pDGeX+VtuhvByduBzvmFabH4GVH-xe-dcMou_Zz=C7vg@mail.gmail.com","threadId":"38761","inReplyTo":"xmqq385d60o3.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v2 1/2] Teach reset the same short-hand as checkout","fromName":"Sudhanshu Shekhar","fromEmail":"sudshekhar02@gmail.com","sentAt":"2015-03-10T07:37:31Z","receivedAt":"2015-03-10T07:37:31Z","isPatch":true,"sender":{"key":"sudshekhar02@gmail.com","avatar":null},"body":"Hi,\n\nOn Tue, Mar 10, 2015 at 8:04 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Sudhanshu Shekhar <sudshekhar02@gmail.com> writes:\n>\n>> \"-\" now means the previous branch.\n>>\n>> Signed-off-by: Sudhanshu Shekhar <sudshekhar02@gmail.com>\n>> Thanks-to: Eric Sunshine, Junio C Hamano, Matthieu Moy\n>> ---\n>\n>\n> These look unusual for a few reasons: your S-o-b should be at the\n> end, we usually say Helped-by: instead, and we do not use these with\n> multiple names on a single line.\n>\n> Please do not try to be original without a good reason.  We may\n> start counting the number of times people appear on these footers to\n> see how much contribution those who do not directly author commits\n> (read: those who mentor others) are making.\n\nThank you for telling me this. I will it keep it in mind from next\ntime onwards.\n\n>\n>>  builtin/reset.c | 9 ++++++++-\n>>  1 file changed, 8 insertions(+), 1 deletion(-)\n>\n> The comment I gave in the thread that ends at $gmane/265112 would\n> apply equally to this patch, I think.\n>\n> cf. http://thread.gmane.org/gmane.comp.version-control.git/264986/focus=265112\nI have rectified this in my new patch and will send it soon.\nKindly do let me know if there are any other changes required.\n\nThank you.\nRegards,\nSudhanshu\n"}]}