use parse_commit_or_die instead of custom message
[git/mingw.git] / t / t5550-http-fetch.sh
blobf7d0f146f0f69775dd3fa3ea06895e2bb1a74d55
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 git config push.default matching &&
17 echo content1 >file &&
18 git add file &&
19 git commit -m one
20 echo content2 >file &&
21 git add file &&
22 git commit -m two
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 &&
29 mkdir -p hooks &&
30 echo "exec git update-server-info" >hooks/post-update &&
31 chmod +x hooks/post-update &&
32 hooks/post-update
33 ) &&
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"
50 setup_askpass_helper
52 test_expect_success 'cloning password-protected repository can fail' '
53 set_askpass wrong &&
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' '
59 set_askpass wrong &&
60 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
61 expect_askpass 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() {
78 cat >/dev/null
79 echo username=user@host
80 echo password=user@host
81 }; f" &&
82 set_askpass wrong &&
83 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
84 expect_askpass none
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 &&
104 git push public &&
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) &&
113 (cd clone2 &&
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 &&
122 (cd clone &&
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
135 ) &&
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` &&
143 chmod u+w $p &&
144 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
145 ) &&
146 mkdir repo_bad1.git &&
147 (cd repo_bad1.git &&
148 git --bare init &&
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` &&
158 chmod u+w $p &&
159 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
160 ) &&
161 mkdir repo_bad2.git &&
162 (cd repo_bad2.git &&
163 git --bare init &&
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
171 : >exp
172 test_cmp exp act
175 stop_httpd
176 test_done