3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
6 test_description
='test smart pushing over http via http-backend'
9 if test -n "$NO_CURL"; then
10 skip_all
='skipping test, git built without http support'
15 LIB_HTTPD_PORT
=${LIB_HTTPD_PORT-'5541'}
16 .
"$TEST_DIRECTORY"/lib-httpd.sh
19 test_expect_success
'setup remote repository' '
27 git commit -m initial &&
29 git clone --bare test_repo test_repo.git &&
31 git config http.receivepack true &&
32 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
34 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
38 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
39 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
41 test_expect_success
'no empty path components' '
42 # In the URL, add a trailing slash, and see if git appends yet another
45 git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
52 " >act <"$HTTPD_ROOT_PATH"/access.log &&
54 # Clear the log, so that it does not affect the "used receive-pack
55 # service" test which reads the log too.
57 # We do this before the actual comparison to ensure the log is cleared.
58 echo > "$HTTPD_ROOT_PATH"/access.log &&
63 test_expect_success
'clone remote repository' '
64 rm -rf test_repo_clone &&
65 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
68 test_expect_success
'push to remote repository (standard)' '
69 cd "$ROOT_PATH"/test_repo_clone &&
73 git commit -m path2 &&
74 HEAD=$(git rev-parse --verify HEAD) &&
75 GIT_CURL_VERBOSE=1 git push -v -v 2>err &&
76 ! grep "Expect: 100-continue" err &&
77 grep "POST git-receive-pack ([0-9]* bytes)" err &&
78 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
79 test $HEAD = $(git rev-parse --verify HEAD))
82 test_expect_success
'push already up-to-date' '
86 test_expect_success
'create and delete remote branch' '
87 cd "$ROOT_PATH"/test_repo_clone &&
88 git checkout -b dev &&
93 git push origin dev &&
94 git push origin :dev &&
95 test_must_fail git show-ref --verify refs/remotes/origin/dev
100 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
101 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
102 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
103 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
104 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
105 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
106 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
107 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
108 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
110 test_expect_success
'used receive-pack service' '
116 " >act <"$HTTPD_ROOT_PATH"/access.log &&
120 test_http_push_nonff
"$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
121 "$ROOT_PATH"/test_repo_clone master
123 test_expect_success
'push fails for non-fast-forward refs unmatched by remote helper' '
124 # create a dissimilarly-named remote ref so that git is unable to match the
125 # two refs (viz. local, remote) unless an explicit refspec is provided.
126 git push origin master:retsam
128 echo "change changed" > path2 &&
129 git commit -a -m path2 --amend &&
131 # push master too; this ensures there is at least one '"'push'"' command to
132 # the remote helper and triggers interaction with the helper.
133 test_must_fail git push -v origin +master master:retsam >output 2>&1'
135 test_expect_success
'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
136 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
137 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
140 test_expect_success
'push fails for non-fast-forward refs unmatched by remote helper: our output' '
141 test_i18ngrep "To prevent you from losing history, non-fast-forward updates were rejected" \
145 test_expect_success
'push (chunked)' '
146 git checkout master &&
147 test_commit commit path3 &&
148 HEAD=$(git rev-parse --verify HEAD) &&
149 git config http.postbuffer 4 &&
150 test_when_finished "git config --unset http.postbuffer" &&
151 git push -v -v origin $BRANCH 2>err &&
152 grep "POST git-receive-pack (chunked)" err &&
153 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
154 test $HEAD = $(git rev-parse --verify HEAD))