3 test_description
='test dumb fetching over http via static file'
6 if test -n "$NO_CURL"; then
7 skip_all
='skipping test, git built without http support'
11 LIB_HTTPD_PORT
=${LIB_HTTPD_PORT-'5550'}
12 .
"$TEST_DIRECTORY"/lib-httpd.sh
15 test_expect_success
'setup repository' '
21 test_expect_success
'create http-accessible bare repository' '
22 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
23 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
25 echo "exec git update-server-info" >hooks/post-update &&
26 chmod +x hooks/post-update
28 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
29 git push public master:master
32 test_expect_success
'clone http repository' '
33 git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
34 cp -R clone-tmpl clone &&
35 test_cmp file clone/file
38 test_expect_success
'create password-protected repository' '
39 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
40 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
41 "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git"
44 test_expect_success
'setup askpass helpers' '
45 cat >askpass <<-EOF &&
47 echo >>"$PWD/askpass-query" "askpass: \$*" &&
48 cat "$PWD/askpass-response"
51 GIT_ASKPASS="$PWD/askpass" &&
56 dest
=$HTTPD_DEST/auth
/repo.git
62 echo "askpass: Password for 'http://$2@$dest': "
65 echo "askpass: Username for 'http://$dest': "
66 echo "askpass: Password for 'http://$2@$dest': "
73 test_cmp askpass-expect askpass-query
76 test_expect_success
'cloning password-protected repository can fail' '
78 echo wrong >askpass-response &&
79 test_must_fail git clone "$HTTPD_URL/auth/repo.git" clone-auth-fail &&
80 expect_askpass both wrong
83 test_expect_success
'http auth can use user/pass in URL' '
85 echo wrong >askpass-response &&
86 git clone "$HTTPD_URL_USER_PASS/auth/repo.git" clone-auth-none &&
90 test_expect_success
'http auth can use just user in URL' '
92 echo user@host >askpass-response &&
93 git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-pass &&
94 expect_askpass pass user@host
97 test_expect_success
'http auth can request both user and pass' '
99 echo user@host >askpass-response &&
100 git clone "$HTTPD_URL/auth/repo.git" clone-auth-both &&
101 expect_askpass both user@host
104 test_expect_success
'http auth respects credential helper config' '
105 test_config_global credential.helper "!f() {
107 echo username=user@host
108 echo password=user@host
111 echo wrong >askpass-response &&
112 git clone "$HTTPD_URL/auth/repo.git" clone-auth-helper &&
116 test_expect_success
'fetch changes via http' '
117 echo content >>file &&
118 git commit -a -m two &&
120 (cd clone && git pull) &&
121 test_cmp file clone/file
124 test_expect_success
'fetch changes via manual http-fetch' '
125 cp -R clone-tmpl clone2 &&
127 HEAD=$(git rev-parse --verify HEAD) &&
129 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
130 git checkout master-new &&
131 test $HEAD = $(git rev-parse --verify HEAD)) &&
132 test_cmp file clone2/file
135 test_expect_success
'http remote detects correct HEAD' '
136 git push public master:other &&
138 git remote set-head origin -d &&
139 git remote set-head origin -a &&
140 git symbolic-ref refs/remotes/origin/HEAD > output &&
141 echo refs/remotes/origin/master > expect &&
142 test_cmp expect output
146 test_expect_success
'fetch packed objects' '
147 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
148 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
150 git --bare prune-packed
152 git clone $HTTPD_URL/dumb/repo_pack.git
155 test_expect_success
'fetch notices corrupt pack' '
156 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
157 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
158 p=`ls objects/pack/pack-*.pack` &&
160 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
162 mkdir repo_bad1.git &&
165 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
166 test 0 = `ls objects/pack/pack-*.pack | wc -l`
170 test_expect_success
'fetch notices corrupt idx' '
171 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
172 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
173 p=`ls objects/pack/pack-*.idx` &&
175 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
177 mkdir repo_bad2.git &&
180 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
181 test 0 = `ls objects/pack | wc -l`
185 test_expect_success
'did not use upload-pack service' '
186 grep '/git-upload-pack
' <"$HTTPD_ROOT_PATH"/access.log >act