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' '
16 echo content1 >file &&
19 echo content2 >file &&
24 test_expect_success
'create http-accessible bare repository with loose objects' '
25 cp -a .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
26 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
27 git config core.bare true &&
29 echo "exec git update-server-info" >hooks/post-update &&
30 chmod +x hooks/post-update &&
33 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
34 git push public master:master
37 test_expect_success
'clone http repository' '
38 git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
39 cp -R clone-tmpl clone &&
40 test_cmp file clone/file
43 test_expect_success
'create password-protected repository' '
44 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
45 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
46 "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git"
49 test_expect_success
'setup askpass helpers' '
50 cat >askpass <<-EOF &&
52 echo >>"$PWD/askpass-query" "askpass: \$*" &&
53 cat "$PWD/askpass-response"
56 GIT_ASKPASS="$PWD/askpass" &&
67 echo "askpass: Password for 'http://$2@$dest': "
70 echo "askpass: Username for 'http://$dest': "
71 echo "askpass: Password for 'http://$2@$dest': "
78 test_cmp askpass-expect askpass-query
81 test_expect_success
'cloning password-protected repository can fail' '
83 echo wrong >askpass-response &&
84 test_must_fail git clone "$HTTPD_URL/auth/repo.git" clone-auth-fail &&
85 expect_askpass both wrong
88 test_expect_success
'http auth can use user/pass in URL' '
90 echo wrong >askpass-response &&
91 git clone "$HTTPD_URL_USER_PASS/auth/repo.git" clone-auth-none &&
95 test_expect_success
'http auth can use just user in URL' '
97 echo user@host >askpass-response &&
98 git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-pass &&
99 expect_askpass pass user@host
102 test_expect_success
'http auth can request both user and pass' '
104 echo user@host >askpass-response &&
105 git clone "$HTTPD_URL/auth/repo.git" clone-auth-both &&
106 expect_askpass both user@host
109 test_expect_success
'http auth respects credential helper config' '
110 test_config_global credential.helper "!f() {
112 echo username=user@host
113 echo password=user@host
116 echo wrong >askpass-response &&
117 git clone "$HTTPD_URL/auth/repo.git" clone-auth-helper &&
121 test_expect_success
'http auth can get username from config' '
122 test_config_global "credential.$HTTPD_URL.username" user@host &&
124 echo user@host >askpass-response &&
125 git clone "$HTTPD_URL/auth/repo.git" clone-auth-user &&
126 expect_askpass pass user@host
129 test_expect_success
'configured username does not override URL' '
130 test_config_global "credential.$HTTPD_URL.username" wrong &&
132 echo user@host >askpass-response &&
133 git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-user2 &&
134 expect_askpass pass user@host
137 test_expect_success
'fetch changes via http' '
138 echo content >>file &&
139 git commit -a -m two &&
141 (cd clone && git pull) &&
142 test_cmp file clone/file
145 test_expect_success
'fetch changes via manual http-fetch' '
146 cp -R clone-tmpl clone2 &&
148 HEAD=$(git rev-parse --verify HEAD) &&
150 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
151 git checkout master-new &&
152 test $HEAD = $(git rev-parse --verify HEAD)) &&
153 test_cmp file clone2/file
156 test_expect_success
'http remote detects correct HEAD' '
157 git push public master:other &&
159 git remote set-head origin -d &&
160 git remote set-head origin -a &&
161 git symbolic-ref refs/remotes/origin/HEAD > output &&
162 echo refs/remotes/origin/master > expect &&
163 test_cmp expect output
167 test_expect_success
'fetch packed objects' '
168 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
169 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
170 git --bare repack -a -d
172 git clone $HTTPD_URL/dumb/repo_pack.git
175 test_expect_success
'fetch notices corrupt pack' '
176 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
177 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
178 p=`ls objects/pack/pack-*.pack` &&
180 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
182 mkdir repo_bad1.git &&
185 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
186 test 0 = `ls objects/pack/pack-*.pack | wc -l`
190 test_expect_success
'fetch notices corrupt idx' '
191 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
192 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
193 p=`ls objects/pack/pack-*.idx` &&
195 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
197 mkdir repo_bad2.git &&
200 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
201 test 0 = `ls objects/pack | wc -l`
205 test_expect_success
'did not use upload-pack service' '
206 grep '/git-upload-pack
' <"$HTTPD_ROOT_PATH"/access.log >act