checkout: pass "struct checkout_opts *" as const pointer
[git/jnareb-git.git] / t / t5550-http-fetch.sh
blobb06f817af32483631b3ec297246e156400bc6b93
1 #!/bin/sh
3 test_description='test dumb fetching over http via static file'
4 . ./test-lib.sh
6 if test -n "$NO_CURL"; then
7 skip_all='skipping test, git built without http support'
8 test_done
9 fi
11 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5550'}
12 . "$TEST_DIRECTORY"/lib-httpd.sh
13 start_httpd
15 test_expect_success 'setup repository' '
16 echo content1 >file &&
17 git add file &&
18 git commit -m one
19 echo content2 >file &&
20 git add file &&
21 git commit -m two
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 &&
28 mkdir -p hooks &&
29 echo "exec git update-server-info" >hooks/post-update &&
30 chmod +x hooks/post-update &&
31 hooks/post-update
32 ) &&
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 &&
51 #!/bin/sh
52 echo >>"$PWD/askpass-query" "askpass: \$*" &&
53 cat "$PWD/askpass-response"
54 EOF
55 chmod +x askpass &&
56 GIT_ASKPASS="$PWD/askpass" &&
57 export GIT_ASKPASS
60 expect_askpass() {
61 dest=$HTTPD_DEST
63 case "$1" in
64 none)
66 pass)
67 echo "askpass: Password for 'http://$2@$dest': "
69 both)
70 echo "askpass: Username for 'http://$dest': "
71 echo "askpass: Password for 'http://$2@$dest': "
74 false
76 esac
77 } >askpass-expect &&
78 test_cmp askpass-expect askpass-query
81 test_expect_success 'cloning password-protected repository can fail' '
82 >askpass-query &&
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' '
89 >askpass-query &&
90 echo wrong >askpass-response &&
91 git clone "$HTTPD_URL_USER_PASS/auth/repo.git" clone-auth-none &&
92 expect_askpass none
95 test_expect_success 'http auth can use just user in URL' '
96 >askpass-query &&
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' '
103 >askpass-query &&
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() {
111 cat >/dev/null
112 echo username=user@host
113 echo password=user@host
114 }; f" &&
115 >askpass-query &&
116 echo wrong >askpass-response &&
117 git clone "$HTTPD_URL/auth/repo.git" clone-auth-helper &&
118 expect_askpass none
121 test_expect_success 'http auth can get username from config' '
122 test_config_global "credential.$HTTPD_URL.username" user@host &&
123 >askpass-query &&
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 &&
131 >askpass-query &&
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 &&
140 git push public &&
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) &&
149 (cd clone2 &&
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 &&
158 (cd clone &&
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
171 ) &&
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` &&
179 chmod u+w $p &&
180 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
181 ) &&
182 mkdir repo_bad1.git &&
183 (cd repo_bad1.git &&
184 git --bare init &&
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` &&
194 chmod u+w $p &&
195 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
196 ) &&
197 mkdir repo_bad2.git &&
198 (cd repo_bad2.git &&
199 git --bare init &&
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
207 : >exp
208 test_cmp exp act
211 stop_httpd
212 test_done