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 git config push.default matching &&
17 echo content1 >file &&
20 echo content2 >file &&
25 test_expect_success
'create http-accessible bare repository with loose objects' '
26 cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
27 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
28 git config core.bare true &&
30 echo "exec git update-server-info" >hooks/post-update &&
31 chmod +x hooks/post-update &&
34 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
35 git push public master:master
38 test_expect_success
'clone http repository' '
39 git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
40 cp -R clone-tmpl clone &&
41 test_cmp file clone/file
44 test_expect_success
'create password-protected repository' '
45 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
46 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
47 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
52 test_expect_success
'cloning password-protected repository can fail' '
54 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
55 expect_askpass both wrong
58 test_expect_success
'http auth can use user/pass in URL' '
60 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
64 test_expect_success
'http auth can use just user in URL' '
65 set_askpass user@host &&
66 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
67 expect_askpass pass user@host
70 test_expect_success
'http auth can request both user and pass' '
71 set_askpass user@host &&
72 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
73 expect_askpass both user@host
76 test_expect_success
'http auth respects credential helper config' '
77 test_config_global credential.helper "!f() {
79 echo username=user@host
80 echo password=user@host
83 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
87 test_expect_success
'http auth can get username from config' '
88 test_config_global "credential.$HTTPD_URL.username" user@host &&
89 set_askpass user@host &&
90 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
91 expect_askpass pass user@host
94 test_expect_success
'configured username does not override URL' '
95 test_config_global "credential.$HTTPD_URL.username" wrong &&
96 set_askpass user@host &&
97 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
98 expect_askpass pass user@host
101 test_expect_success
'fetch changes via http' '
102 echo content >>file &&
103 git commit -a -m two &&
105 (cd clone && git pull) &&
106 test_cmp file clone/file
109 test_expect_success
'fetch changes via manual http-fetch' '
110 cp -R clone-tmpl clone2 &&
112 HEAD=$(git rev-parse --verify HEAD) &&
114 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
115 git checkout master-new &&
116 test $HEAD = $(git rev-parse --verify HEAD)) &&
117 test_cmp file clone2/file
120 test_expect_success
'http remote detects correct HEAD' '
121 git push public master:other &&
123 git remote set-head origin -d &&
124 git remote set-head origin -a &&
125 git symbolic-ref refs/remotes/origin/HEAD > output &&
126 echo refs/remotes/origin/master > expect &&
127 test_cmp expect output
131 test_expect_success
'fetch packed objects' '
132 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
133 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
134 git --bare repack -a -d
136 git clone $HTTPD_URL/dumb/repo_pack.git
139 test_expect_success
'fetch notices corrupt pack' '
140 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
141 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
142 p=`ls objects/pack/pack-*.pack` &&
144 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
146 mkdir repo_bad1.git &&
149 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
150 test 0 = `ls objects/pack/pack-*.pack | wc -l`
154 test_expect_success
'fetch notices corrupt idx' '
155 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
156 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
157 p=`ls objects/pack/pack-*.idx` &&
159 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
161 mkdir repo_bad2.git &&
164 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
165 test 0 = `ls objects/pack | wc -l`
169 test_expect_success
'did not use upload-pack service' '
170 grep '/git-upload-pack
' <"$HTTPD_ROOT_PATH"/access.log >act