git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Sundararajan R <dyoucme@gmail.com>
To: git@vger.kernel.org
Cc: Sundararajan R <dyoucme@gmail.com>
Subject: [v2 PATCH 2/2] reset: add tests for git reset -
Date: Tue, 10 Mar 2015 21:08:03 +0530	[thread overview]
Message-ID: <1426001883-6423-2-git-send-email-dyoucme@gmail.com> (raw)
In-Reply-To: <1426001883-6423-1-git-send-email-dyoucme@gmail.com>

The failure case which occurs on teaching git is taught the '-' shorthand
is when there exists no branch pointed to by '@{-1}'.

The ambiguous cases occur when there exist files named '-' or '@{-1}' in 
the work tree. These are also treated as failure cases but here the user
is given advice as to how he can proceed.

Add tests to check the handling of these cases. 
Also add a test to verify that reset - behaves like reset @{-1} when none
of the above cases are true.

Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Torsten Bögershausen <tboegi@web.de>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Helped-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Signed-off-by: Sundararajan R <dyoucme@gmail.com>
---
Thank you for your feedback Torsten and Eric.
I have now made the modifications suggested by you.
I have also incorporated the suggestions given by Matthieu on the archive.
Please let me know if there is something else I should add.

 t/t7102-reset.sh | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 98bcfe2..c05dab0 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -568,4 +568,94 @@ test_expect_success 'reset --mixed sets up work tree' '
 	test_cmp expect actual
 '
 
+test_expect_success 'reset - with no @{-1} should fail' '
+	git init new &&
+	(
+		cd new &&
+		test_must_fail git reset - 2>actual
+	) &&
+	test_i18ngrep "unknown revision" new/actual 
+	test_when_finished rm -rf new
+'
+
+test_expect_success 'reset - with no @{-1} and file named - should fail' '
+	git init new &&
+	(
+		cd new &&
+		echo "Hello" >- &&
+		git add - &&
+		test_must_fail git reset - 2>actual 
+	) &&
+	test_i18ngrep "both revision and filename" new/actual 
+	test_when_finished rm -rf new
+'
+
+test_expect_success 'reset - with @{-1} and file named @{-1} should fail' '
+	git init new &&
+	(
+		cd new && 
+		echo "Hello" >@{-1} &&
+		git add @{-1} &&
+		git commit -m "first_commit" &&
+		git checkout -b new_branch &&
+		>@{-1} &&
+		git add @{-1} &&
+		test_must_fail git reset - 2>actual 
+	) &&
+	test_i18ngrep "both revision and filename" new/actual 
+	test_when_finished rm -rf new
+'
+
+test_expect_success 'reset - with @{-1} and file named - should fail' '
+	git init new &&
+	(
+		cd new && 
+		echo "Hello" >- &&
+		git add - &&
+		git commit -m "first_commit" &&
+		git checkout -b new_branch &&
+		>- &&
+		git add - &&
+		test_must_fail git reset - 2>actual 
+	) &&
+	test_i18ngrep "both revision and filename" new/actual 
+	test_when_finished rm -rf new
+'
+
+test_expect_success 'reset - with @{-1} and file named @{-1} and - should fail' '
+	git init new &&
+	(
+		cd new &&
+		>- &&
+		git add - &&
+		git commit -m "first_commit" &&
+		git checkout -b new_branch
+		>@{-1} &&
+		git add @{-1} &&
+		test_must_fail git reset - 2>actual
+	) &&
+ 	test_i18ngrep "both revision and filename" new/actual 
+	test_when_finished rm -rf new
+'
+
+test_expect_success 'reset - with @{-1} and no file named - or @{-1} should succeed' '
+	git init new &&
+	(
+		cd new &&
+		echo "Hey" >new_file &&
+		git add new_file &&
+		git commit -m "first_commit" &&
+		git checkout -b new_branch &&
+		>new_file &&
+		git add new_file &&
+		git reset - &&
+		git status -uno >file1 &&
+		git add new_file &&
+		git reset @{-1} &&
+		git status -uno >file2 
+	) &&
+	test_cmp new/file1 new/file2 
+	test_when_finished rm -rf new
+'
+
 test_done
-- 
2.1.0

  reply	other threads:[~2015-03-10 15:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-10 15:38 [v2 PATCH 1/2] reset: add '-' shorthand for '@{-1}' Sundararajan R
2015-03-10 15:38 ` Sundararajan R [this message]
2015-03-10 17:23   ` [v2 PATCH 2/2] reset: add tests for git reset - Torsten Bögershausen
2015-03-10 17:35   ` Eric Sunshine
2015-03-10 17:25 ` [v2 PATCH 1/2] reset: add '-' shorthand for '@{-1}' Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426001883-6423-2-git-send-email-dyoucme@gmail.com \
    --to=dyoucme@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).