t3508: add check_head_differs_from() helper function and use it
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Jul 21, 2010 at 06:25 UTC
6bc83cdd0b9c7eab365e10d46d1e2acdb769728a
1 file changed
+17
-5
t/t3508-cherry-pick-many-commits.sh
+17
-5
@@ -4,6 +4,18 @@ test_description='test cherry-picking many commits'
4
5
. ./test-lib.sh
6
7
+check_head_differs_from() {
8
+ head=$(git rev-parse --verify HEAD) &&
9
+ arg=$(git rev-parse --verify "$1") &&
10
+ test "$head" != "$arg"
11
+}
12
+
13
+check_head_equals() {
14
+ head=$(git rev-parse --verify HEAD) &&
15
+ arg=$(git rev-parse --verify "$1") &&
16
+ test "$head" = "$arg"
17
+}
18
+
19
test_expect_success setup '
20
echo first > file1 &&
21
git add file1 &&
@@ -36,7 +48,7 @@ test_expect_success 'cherry-pick first..fourth works' '
48
git diff --quiet other &&
49
git diff --quiet HEAD other &&
50
test_cmp expected actual &&
39
- test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
51
+ check_head_differs_from fourth
52
'
53
54
test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
@@ -53,7 +65,7 @@ test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
65
git diff --quiet other &&
66
git diff --quiet HEAD other &&
67
test_cmp expected actual &&
56
- test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
68
+ check_head_differs_from fourth
69
'
70
71
test_expect_success 'cherry-pick --ff first..fourth works' '
@@ -63,7 +75,7 @@ test_expect_success 'cherry-pick --ff first..fourth works' '
75
git cherry-pick --ff first..fourth &&
76
git diff --quiet other &&
77
git diff --quiet HEAD other &&
66
- test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify fourth)"
78
+ check_head_equals fourth
79
'
80
81
test_expect_success 'cherry-pick -n first..fourth works' '
@@ -113,7 +125,7 @@ test_expect_success 'cherry-pick -3 fourth works' '
125
git cherry-pick -3 fourth &&
126
git diff --quiet other &&
127
git diff --quiet HEAD other &&
116
- test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
128
+ check_head_differs_from fourth
129
'
130
131
test_expect_success 'cherry-pick --stdin works' '
@@ -123,7 +135,7 @@ test_expect_success 'cherry-pick --stdin works' '
135
git rev-list --reverse first..fourth | git cherry-pick --stdin &&
136
git diff --quiet other &&
137
git diff --quiet HEAD other &&
126
- test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
138
+ check_head_differs_from fourth
139
'
140
141
test_done