Skip to content

Commit 6bc83cd

Browse files
chriscoolgitster
authored andcommitted
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>
1 parent f29b5e0 commit 6bc83cd

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

t/t3508-cherry-pick-many-commits.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ test_description='test cherry-picking many commits'
44

55
. ./test-lib.sh
66

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+
719
test_expect_success setup '
820
echo first > file1 &&
921
git add file1 &&
@@ -36,7 +48,7 @@ test_expect_success 'cherry-pick first..fourth works' '
3648
git diff --quiet other &&
3749
git diff --quiet HEAD other &&
3850
test_cmp expected actual &&
39-
test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
51+
check_head_differs_from fourth
4052
'
4153

4254
test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
@@ -53,7 +65,7 @@ test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
5365
git diff --quiet other &&
5466
git diff --quiet HEAD other &&
5567
test_cmp expected actual &&
56-
test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
68+
check_head_differs_from fourth
5769
'
5870

5971
test_expect_success 'cherry-pick --ff first..fourth works' '
@@ -63,7 +75,7 @@ test_expect_success 'cherry-pick --ff first..fourth works' '
6375
git cherry-pick --ff first..fourth &&
6476
git diff --quiet other &&
6577
git diff --quiet HEAD other &&
66-
test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify fourth)"
78+
check_head_equals fourth
6779
'
6880

6981
test_expect_success 'cherry-pick -n first..fourth works' '
@@ -113,7 +125,7 @@ test_expect_success 'cherry-pick -3 fourth works' '
113125
git cherry-pick -3 fourth &&
114126
git diff --quiet other &&
115127
git diff --quiet HEAD other &&
116-
test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
128+
check_head_differs_from fourth
117129
'
118130

119131
test_expect_success 'cherry-pick --stdin works' '
@@ -123,7 +135,7 @@ test_expect_success 'cherry-pick --stdin works' '
123135
git rev-list --reverse first..fourth | git cherry-pick --stdin &&
124136
git diff --quiet other &&
125137
git diff --quiet HEAD other &&
126-
test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
138+
check_head_differs_from fourth
127139
'
128140

129141
test_done

0 commit comments

Comments
 (0)