archive: handle commits with an empty tree
[git/jnareb-git.git] / t / t5550-http-fetch.sh
blob80d20c876bbac0b00d388d511da555a29e827dbc
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 -R .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 -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
45 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
46 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
49 setup_askpass_helper
51 test_expect_success 'cloning password-protected repository can fail' '
52 set_askpass wrong &&
53 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
54 expect_askpass both wrong
57 test_expect_success 'http auth can use user/pass in URL' '
58 set_askpass wrong &&
59 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
60 expect_askpass none
63 test_expect_success 'http auth can use just user in URL' '
64 set_askpass user@host &&
65 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
66 expect_askpass pass user@host
69 test_expect_success 'http auth can request both user and pass' '
70 set_askpass user@host &&
71 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
72 expect_askpass both user@host
75 test_expect_success 'http auth respects credential helper config' '
76 test_config_global credential.helper "!f() {
77 cat >/dev/null
78 echo username=user@host
79 echo password=user@host
80 }; f" &&
81 set_askpass wrong &&
82 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
83 expect_askpass none
86 test_expect_success 'http auth can get username from config' '
87 test_config_global "credential.$HTTPD_URL.username" user@host &&
88 set_askpass user@host &&
89 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
90 expect_askpass pass user@host
93 test_expect_success 'configured username does not override URL' '
94 test_config_global "credential.$HTTPD_URL.username" wrong &&
95 set_askpass user@host &&
96 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
97 expect_askpass pass user@host
100 test_expect_success 'fetch changes via http' '
101 echo content >>file &&
102 git commit -a -m two &&
103 git push public &&
104 (cd clone && git pull) &&
105 test_cmp file clone/file
108 test_expect_success 'fetch changes via manual http-fetch' '
109 cp -R clone-tmpl clone2 &&
111 HEAD=$(git rev-parse --verify HEAD) &&
112 (cd clone2 &&
113 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
114 git checkout master-new &&
115 test $HEAD = $(git rev-parse --verify HEAD)) &&
116 test_cmp file clone2/file
119 test_expect_success 'http remote detects correct HEAD' '
120 git push public master:other &&
121 (cd clone &&
122 git remote set-head origin -d &&
123 git remote set-head origin -a &&
124 git symbolic-ref refs/remotes/origin/HEAD > output &&
125 echo refs/remotes/origin/master > expect &&
126 test_cmp expect output
130 test_expect_success 'fetch packed objects' '
131 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
132 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
133 git --bare repack -a -d
134 ) &&
135 git clone $HTTPD_URL/dumb/repo_pack.git
138 test_expect_success 'fetch notices corrupt pack' '
139 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
140 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
141 p=`ls objects/pack/pack-*.pack` &&
142 chmod u+w $p &&
143 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
144 ) &&
145 mkdir repo_bad1.git &&
146 (cd repo_bad1.git &&
147 git --bare init &&
148 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
149 test 0 = `ls objects/pack/pack-*.pack | wc -l`
153 test_expect_success 'fetch notices corrupt idx' '
154 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
155 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
156 p=`ls objects/pack/pack-*.idx` &&
157 chmod u+w $p &&
158 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
159 ) &&
160 mkdir repo_bad2.git &&
161 (cd repo_bad2.git &&
162 git --bare init &&
163 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
164 test 0 = `ls objects/pack | wc -l`
168 test_expect_success 'did not use upload-pack service' '
169 grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act
170 : >exp
171 test_cmp exp act
174 stop_httpd
175 test_done