Skip to content

Commit 6cbd6e9

Browse files
rctaygitster
authored andcommitted
t554[01]-http-push: refactor, add non-ff tests
Move non-fast forward tests to lib-httpd.sh so that we don't have to duplicate the tests in both t5540 and t5541. Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe4bc2a commit 6cbd6e9

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

t/lib-httpd.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,32 @@ stop_httpd() {
131131
"$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
132132
-f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
133133
}
134+
135+
test_http_push_nonff() {
136+
REMOTE_REPO=$1
137+
LOCAL_REPO=$2
138+
BRANCH=$3
139+
140+
test_expect_success 'non-fast-forward push fails' '
141+
cd "$REMOTE_REPO" &&
142+
HEAD=$(git rev-parse --verify HEAD) &&
143+
144+
cd "$LOCAL_REPO" &&
145+
git checkout $BRANCH &&
146+
echo "changed" > path2 &&
147+
git commit -a -m path2 --amend &&
148+
149+
!(git push -v origin >output 2>&1) &&
150+
(cd "$REMOTE_REPO" &&
151+
test $HEAD = $(git rev-parse --verify HEAD))
152+
'
153+
154+
test_expect_success 'non-fast-forward push show ref status' '
155+
grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output
156+
'
157+
158+
test_expect_success 'non-fast-forward push shows help message' '
159+
grep "To prevent you from losing history, non-fast-forward updates were rejected" \
160+
output
161+
'
162+
}

t/t5540-http-push.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
137137
138138
'
139139

140+
test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
141+
"$ROOT_PATH"/test_repo_clone master
142+
140143
stop_httpd
141144

142145
test_done

t/t5541-http-push.sh

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,8 @@ test_expect_success 'used receive-pack service' '
8888
test_cmp exp act
8989
'
9090

91-
test_expect_success 'non-fast-forward push fails' '
92-
cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
93-
HEAD=$(git rev-parse --verify HEAD) &&
94-
95-
cd "$ROOT_PATH"/test_repo_clone &&
96-
git checkout master &&
97-
echo "changed" > path2 &&
98-
git commit -a -m path2 --amend &&
99-
100-
!(git push -v origin >output 2>&1) &&
101-
(cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
102-
test $HEAD = $(git rev-parse --verify HEAD))
103-
'
104-
105-
test_expect_success 'non-fast-forward push show ref status' '
106-
grep "^ ! \[rejected\][ ]*master -> master (non-fast-forward)$" output
107-
'
108-
109-
test_expect_success 'non-fast-forward push shows help message' '
110-
grep "To prevent you from losing history, non-fast-forward updates were rejected" \
111-
output
112-
'
91+
test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
92+
"$ROOT_PATH"/test_repo_clone master
11393

11494
test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
11595
# create a dissimilarly-named remote ref so that git is unable to match the

0 commit comments

Comments
 (0)