git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Sverre Rabbelier <srabbelier@gmail.com>,
	Ramkumar Ramachandra <artagnon@gmail.com>,
	Jonathan Nieder <jrnieder@gmail.com>, Jeff King <peff@peff.net>
Subject: [PATCH] t3508: add check_head_differs_from() helper function and use it
Date: Wed, 21 Jul 2010 06:25:02 +0200	[thread overview]
Message-ID: <20100721042503.1948.5144.chriscool@tuxfamily.org> (raw)

In a test like:

test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"

the --verify does not accomplish much, since the exit status of
git rev-parse is not propagated to test. So it is more robust to
define and use the helper functions check_head_differs_from() and
check_head_equals() as done by this patch.

Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 t/t3508-cherry-pick-many-commits.sh |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh
index 6044173..0f61495 100755
--- a/t/t3508-cherry-pick-many-commits.sh
+++ b/t/t3508-cherry-pick-many-commits.sh
@@ -4,6 +4,18 @@ test_description='test cherry-picking many commits'
 
 . ./test-lib.sh
 
+check_head_differs_from() {
+	head=$(git rev-parse --verify HEAD) &&
+	arg=$(git rev-parse --verify "$1") &&
+	test "$head" != "$arg"
+}
+
+check_head_equals() {
+	head=$(git rev-parse --verify HEAD) &&
+	arg=$(git rev-parse --verify "$1") &&
+	test "$head" = "$arg"
+}
+
 test_expect_success setup '
 	echo first > file1 &&
 	git add file1 &&
@@ -36,7 +48,7 @@ test_expect_success 'cherry-pick first..fourth works' '
 	git diff --quiet other &&
 	git diff --quiet HEAD other &&
 	test_cmp expected actual &&
-	test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
+	check_head_differs_from fourth
 '
 
 test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
@@ -53,7 +65,7 @@ test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
 	git diff --quiet other &&
 	git diff --quiet HEAD other &&
 	test_cmp expected actual &&
-	test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
+	check_head_differs_from fourth
 '
 
 test_expect_success 'cherry-pick --ff first..fourth works' '
@@ -63,7 +75,7 @@ test_expect_success 'cherry-pick --ff first..fourth works' '
 	git cherry-pick --ff first..fourth &&
 	git diff --quiet other &&
 	git diff --quiet HEAD other &&
-	test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify fourth)"
+	check_head_equals fourth
 '
 
 test_expect_success 'cherry-pick -n first..fourth works' '
@@ -113,7 +125,7 @@ test_expect_success 'cherry-pick -3 fourth works' '
 	git cherry-pick -3 fourth &&
 	git diff --quiet other &&
 	git diff --quiet HEAD other &&
-	test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
+	check_head_differs_from fourth
 '
 
 test_expect_success 'cherry-pick --stdin works' '
@@ -123,7 +135,7 @@ test_expect_success 'cherry-pick --stdin works' '
 	git rev-list --reverse first..fourth | git cherry-pick --stdin &&
 	git diff --quiet other &&
 	git diff --quiet HEAD other &&
-	test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
+	check_head_differs_from fourth
 '
 
 test_done
-- 
1.7.2.rc3.133.g31b0a

             reply	other threads:[~2010-07-22 13:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-21  4:25 Christian Couder [this message]
2010-07-23  1:38 ` [PATCH] t3508: add check_head_differs_from() helper function and use it Jonathan Nieder

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

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

  git send-email \
    --in-reply-to=20100721042503.1948.5144.chriscool@tuxfamily.org \
    --to=chriscool@tuxfamily.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=srabbelier@gmail.com \
    /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.
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 NNTP newsgroup(s).