{"thread":{"id":"24467","subject":"[PATCH] t3508: add check_head_differs_from() helper function and use it","startedAt":"2010-07-21T04:25:02Z","lastAt":"2010-07-23T01:38:59Z","messageCount":2,"participants":["Christian Couder","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"145994","messageId":"20100721042503.1948.5144.chriscool@tuxfamily.org","threadId":"24467","inReplyTo":null,"subject":"[PATCH] t3508: add check_head_differs_from() helper function and use it","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2010-07-21T04:25:02Z","receivedAt":"2010-07-21T04:25:02Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"In a test like:\n\ntest \"$(git rev-parse --verify HEAD)\" != \"$(git rev-parse --verify fourth)\"\n\nthe --verify does not accomplish much, since the exit status of\ngit rev-parse is not propagated to test. So it is more robust to\ndefine and use the helper functions check_head_differs_from() and\ncheck_head_equals() as done by this patch.\n\nSuggested-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n t/t3508-cherry-pick-many-commits.sh |   22 +++++++++++++++++-----\n 1 files changed, 17 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh\nindex 6044173..0f61495 100755\n--- a/t/t3508-cherry-pick-many-commits.sh\n+++ b/t/t3508-cherry-pick-many-commits.sh\n@@ -4,6 +4,18 @@ test_description='test cherry-picking many commits'\n \n . ./test-lib.sh\n \n+check_head_differs_from() {\n+\thead=$(git rev-parse --verify HEAD) &&\n+\targ=$(git rev-parse --verify \"$1\") &&\n+\ttest \"$head\" != \"$arg\"\n+}\n+\n+check_head_equals() {\n+\thead=$(git rev-parse --verify HEAD) &&\n+\targ=$(git rev-parse --verify \"$1\") &&\n+\ttest \"$head\" = \"$arg\"\n+}\n+\n test_expect_success setup '\n \techo first > file1 &&\n \tgit add file1 &&\n@@ -36,7 +48,7 @@ test_expect_success 'cherry-pick first..fourth works' '\n \tgit diff --quiet other &&\n \tgit diff --quiet HEAD other &&\n \ttest_cmp expected actual &&\n-\ttest \"$(git rev-parse --verify HEAD)\" != \"$(git rev-parse --verify fourth)\"\n+\tcheck_head_differs_from fourth\n '\n \n test_expect_success 'cherry-pick --strategy resolve first..fourth works' '\n@@ -53,7 +65,7 @@ test_expect_success 'cherry-pick --strategy resolve first..fourth works' '\n \tgit diff --quiet other &&\n \tgit diff --quiet HEAD other &&\n \ttest_cmp expected actual &&\n-\ttest \"$(git rev-parse --verify HEAD)\" != \"$(git rev-parse --verify fourth)\"\n+\tcheck_head_differs_from fourth\n '\n \n test_expect_success 'cherry-pick --ff first..fourth works' '\n@@ -63,7 +75,7 @@ test_expect_success 'cherry-pick --ff first..fourth works' '\n \tgit cherry-pick --ff first..fourth &&\n \tgit diff --quiet other &&\n \tgit diff --quiet HEAD other &&\n-\ttest \"$(git rev-parse --verify HEAD)\" = \"$(git rev-parse --verify fourth)\"\n+\tcheck_head_equals fourth\n '\n \n test_expect_success 'cherry-pick -n first..fourth works' '\n@@ -113,7 +125,7 @@ test_expect_success 'cherry-pick -3 fourth works' '\n \tgit cherry-pick -3 fourth &&\n \tgit diff --quiet other &&\n \tgit diff --quiet HEAD other &&\n-\ttest \"$(git rev-parse --verify HEAD)\" != \"$(git rev-parse --verify fourth)\"\n+\tcheck_head_differs_from fourth\n '\n \n test_expect_success 'cherry-pick --stdin works' '\n@@ -123,7 +135,7 @@ test_expect_success 'cherry-pick --stdin works' '\n \tgit rev-list --reverse first..fourth | git cherry-pick --stdin &&\n \tgit diff --quiet other &&\n \tgit diff --quiet HEAD other &&\n-\ttest \"$(git rev-parse --verify HEAD)\" != \"$(git rev-parse --verify fourth)\"\n+\tcheck_head_differs_from fourth\n '\n \n test_done\n-- \n1.7.2.rc3.133.g31b0a\n"},{"id":"146036","messageId":"20100723013859.GA28603@burratino","threadId":"24467","inReplyTo":"20100721042503.1948.5144.chriscool@tuxfamily.org","subject":"Re: [PATCH] t3508: add check_head_differs_from() helper function and use it","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-07-23T01:38:59Z","receivedAt":"2010-07-23T01:38:59Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Christian Couder wrote:\n\n> So it is more robust to\n> define and use the helper functions check_head_differs_from() and\n> check_head_equals() as done by this patch.\n\nIt makes the test a little nicer to read, too.  Thanks.\n"}]}