3 test_description='test dumb fetching over http via static file'
5 . "$TEST_DIRECTORY"/lib-httpd.sh
8 test_expect_success 'setup repository' '
9 git config push.default matching &&
10 echo content1 >file &&
13 echo content2 >file &&
18 test_expect_success 'create http-accessible bare repository with loose objects' '
19 cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
20 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
21 git config core.bare true &&
23 echo "exec git update-server-info" >hooks/post-update &&
24 chmod +x hooks/post-update &&
27 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
28 git push public master:master
31 test_expect_success 'clone http repository' '
32 git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
33 cp -R clone-tmpl clone &&
34 test_cmp file clone/file
37 test_expect_success 'create password-protected repository' '
38 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
39 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
40 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
45 test_expect_success 'cloning password-protected repository can fail' '
47 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
48 expect_askpass both wrong
51 test_expect_success 'http auth can use user/pass in URL' '
53 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
57 test_expect_success 'http auth can use just user in URL' '
58 set_askpass wrong pass@host &&
59 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
60 expect_askpass pass user@host
63 test_expect_success 'http auth can request both user and pass' '
64 set_askpass user@host pass@host &&
65 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
66 expect_askpass both user@host
69 test_expect_success 'http auth respects credential helper config' '
70 test_config_global credential.helper "!f() {
72 echo username=user@host
73 echo password=pass@host
76 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
80 test_expect_success 'http auth can get username from config' '
81 test_config_global "credential.$HTTPD_URL.username" user@host &&
82 set_askpass wrong pass@host &&
83 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
84 expect_askpass pass user@host
87 test_expect_success 'configured username does not override URL' '
88 test_config_global "credential.$HTTPD_URL.username" wrong &&
89 set_askpass wrong pass@host &&
90 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
91 expect_askpass pass user@host
94 test_expect_success 'fetch changes via http' '
95 echo content >>file &&
96 git commit -a -m two &&
98 (cd clone && git pull) &&
99 test_cmp file clone/file
102 test_expect_success 'fetch changes via manual http-fetch' '
103 cp -R clone-tmpl clone2 &&
105 HEAD=$(git rev-parse --verify HEAD) &&
107 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
108 git checkout master-new &&
109 test $HEAD = $(git rev-parse --verify HEAD)) &&
110 test_cmp file clone2/file
113 test_expect_success 'http remote detects correct HEAD' '
114 git push public master:other &&
116 git remote set-head origin -d &&
117 git remote set-head origin -a &&
118 git symbolic-ref refs/remotes/origin/HEAD > output &&
119 echo refs/remotes/origin/master > expect &&
120 test_cmp expect output
124 test_expect_success 'fetch packed objects' '
125 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
126 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
127 git --bare repack -a -d
129 git clone $HTTPD_URL/dumb/repo_pack.git
132 test_expect_success 'fetch notices corrupt pack' '
133 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
134 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
135 p=`ls objects/pack/pack-*.pack` &&
137 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
139 mkdir repo_bad1.git &&
142 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
143 test 0 = `ls objects/pack/pack-*.pack | wc -l`
147 test_expect_success 'fetch notices corrupt idx' '
148 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
149 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
150 p=`ls objects/pack/pack-*.idx` &&
152 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
154 mkdir repo_bad2.git &&
157 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
158 test 0 = `ls objects/pack | wc -l`
162 test_expect_success 'did not use upload-pack service' '
163 grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act