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 . "$TEST_DIRECTORY"/lib-httpd.sh
12 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5550'}
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" &&
53 >askpass-expect-none &&
54 echo "askpass: Password for '\''$HTTPD_DEST'\'': " >askpass-expect-pass &&
55 { echo "askpass: Username for '\''$HTTPD_DEST'\'': " &&
56 cat askpass-expect-pass
57 } >askpass-expect-both
60 test_expect_success 'cloning password-protected repository can fail' '
62 echo wrong >askpass-response &&
63 test_must_fail git clone "$HTTPD_URL/auth/repo.git" clone-auth-fail &&
64 test_cmp askpass-expect-both askpass-query
67 test_expect_success 'http auth can use user/pass in URL' '
69 echo wrong >askpass-response &&
70 git clone "$HTTPD_URL_USER_PASS/auth/repo.git" clone-auth-none &&
71 test_cmp askpass-expect-none askpass-query
74 test_expect_success 'http auth can use just user in URL' '
76 echo user@host >askpass-response &&
77 git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-pass &&
78 test_cmp askpass-expect-pass askpass-query
81 test_expect_success 'http auth can request both user and pass' '
83 echo user@host >askpass-response &&
84 git clone "$HTTPD_URL/auth/repo.git" clone-auth-both &&
85 test_cmp askpass-expect-both askpass-query
88 test_expect_success 'http auth can pull user from config' '
90 echo user@host >askpass-response &&
91 git config --global credential.$HTTPD_PROTO:$HTTPD_DEST.username user@host &&
92 git clone "$HTTPD_URL/auth/repo.git" clone-auth-config &&
93 test_cmp askpass-expect-pass askpass-query
96 test_expect_success 'http auth respects credential helpers' '
97 cat >credential-helper <<-\EOF &&
99 echo username=user@host
100 echo password=user@host
102 chmod +x credential-helper &&
103 git config --global credential.helper "\"$PWD/credential-helper\"" &&
105 git clone "$HTTPD_URL/auth/repo.git" clone-auth-helper &&
106 test_cmp askpass-expect-none askpass-query
109 test_expect_success 'fetch changes via http' '
110 echo content >>file &&
111 git commit -a -m two &&
113 (cd clone && git pull) &&
114 test_cmp file clone/file
117 test_expect_success 'fetch changes via manual http-fetch' '
118 cp -R clone-tmpl clone2 &&
120 HEAD=$(git rev-parse --verify HEAD) &&
122 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
123 git checkout master-new &&
124 test $HEAD = $(git rev-parse --verify HEAD)) &&
125 test_cmp file clone2/file
128 test_expect_success 'http remote detects correct HEAD' '
129 git push public master:other &&
131 git remote set-head origin -d &&
132 git remote set-head origin -a &&
133 git symbolic-ref refs/remotes/origin/HEAD > output &&
134 echo refs/remotes/origin/master > expect &&
135 test_cmp expect output
139 test_expect_success 'fetch packed objects' '
140 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
141 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
143 git --bare prune-packed
145 git clone $HTTPD_URL/dumb/repo_pack.git
148 test_expect_success 'fetch notices corrupt pack' '
149 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
150 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
151 p=`ls objects/pack/pack-*.pack` &&
153 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
155 mkdir repo_bad1.git &&
158 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
159 test 0 = `ls objects/pack/pack-*.pack | wc -l`
163 test_expect_success 'fetch notices corrupt idx' '
164 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
165 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
166 p=`ls objects/pack/pack-*.idx` &&
168 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
170 mkdir repo_bad2.git &&
173 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
174 test 0 = `ls objects/pack | wc -l`
178 test_expect_success 'did not use upload-pack service' '
179 grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act