3 test_description='test fetching over git protocol'
6 . "$TEST_DIRECTORY"/lib-git-daemon.sh
9 check_verbose_connect () {
10 test_i18ngrep -F "Looking up 127.0.0.1 ..." stderr &&
11 test_i18ngrep -F "Connecting to 127.0.0.1 (port " stderr &&
12 test_i18ngrep -F "done." stderr
15 test_expect_success 'setup repository' '
16 git config push.default matching &&
22 test_expect_success 'create git-accessible bare repository' '
23 mkdir "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
24 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
26 : >git-daemon-export-ok
28 git remote add public "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
29 git push public master:master
32 test_expect_success 'clone git repository' '
33 git clone -v "$GIT_DAEMON_URL/repo.git" clone 2>stderr &&
34 check_verbose_connect &&
35 test_cmp file clone/file
38 test_expect_success 'fetch changes via git protocol' '
39 echo content >>file &&
40 git commit -a -m two &&
42 (cd clone && git pull -v) 2>stderr &&
43 check_verbose_connect &&
44 test_cmp file clone/file
47 test_expect_success 'no-op fetch -v stderr is as expected' '
48 (cd clone && git fetch -v) 2>stderr &&
52 test_expect_success 'no-op fetch without "-v" is quiet' '
53 (cd clone && git fetch 2>../stderr) &&
54 test_must_be_empty stderr
57 test_expect_success 'remote detects correct HEAD' '
58 git push public master:other &&
60 git remote set-head -d origin &&
61 git remote set-head -a origin &&
62 git symbolic-ref refs/remotes/origin/HEAD > output &&
63 echo refs/remotes/origin/master > expect &&
64 test_cmp expect output
68 test_expect_success 'prepare pack objects' '
69 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
70 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
71 git --bare repack -a -d
75 test_expect_success 'fetch notices corrupt pack' '
76 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
77 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
78 p=$(ls objects/pack/pack-*.pack) &&
80 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
82 mkdir repo_bad1.git &&
85 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad1.git" &&
86 test 0 = $(ls objects/pack/pack-*.pack | wc -l)
90 test_expect_success 'fetch notices corrupt idx' '
91 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
92 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
93 rm -f objects/pack/multi-pack-index &&
94 p=$(ls objects/pack/pack-*.idx) &&
96 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
98 mkdir repo_bad2.git &&
101 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad2.git" &&
102 test 0 = $(ls objects/pack | wc -l)
114 chmod -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
130 shift || error "invalid number of arguments"
132 if test -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo"
134 if test -n "$do_export"
136 : >"$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
138 rm -f "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
142 test_must_fail git "$cmd" "$GIT_DAEMON_URL/$repo" "$@" 2>output &&
143 test_i18ngrep "fatal: remote error: $msg: /$repo" output &&
145 chmod +x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
149 msg="access denied or repository not exported"
150 test_expect_success 'clone non-existent' "test_remote_error '$msg' clone nowhere.git"
151 test_expect_success 'push disabled' "test_remote_error '$msg' push repo.git master"
152 test_expect_success 'read access denied' "test_remote_error -x '$msg' fetch repo.git"
153 test_expect_success 'not exported' "test_remote_error -n '$msg' fetch repo.git"
156 start_git_daemon --informative-errors
158 test_expect_success 'clone non-existent' "test_remote_error 'no such repository' clone nowhere.git"
159 test_expect_success 'push disabled' "test_remote_error 'service not enabled' push repo.git master"
160 test_expect_success 'read access denied' "test_remote_error -x 'no such repository' fetch repo.git"
161 test_expect_success 'not exported' "test_remote_error -n 'repository not exported' fetch repo.git"
164 start_git_daemon --interpolated-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH/%H%D"
166 test_expect_success 'access repo via interpolated hostname' '
167 repo="$GIT_DAEMON_DOCUMENT_ROOT_PATH/localhost/interp.git" &&
168 git init --bare "$repo" &&
169 git push "$repo" HEAD &&
170 >"$repo"/git-daemon-export-ok &&
171 GIT_OVERRIDE_VIRTUAL_HOST=localhost \
172 git ls-remote "$GIT_DAEMON_URL/interp.git" &&
173 GIT_OVERRIDE_VIRTUAL_HOST=LOCALHOST \
174 git ls-remote "$GIT_DAEMON_URL/interp.git"
177 test_expect_success 'hostname cannot break out of directory' '
178 repo="$GIT_DAEMON_DOCUMENT_ROOT_PATH/../escape.git" &&
179 git init --bare "$repo" &&
180 git push "$repo" HEAD &&
181 >"$repo"/git-daemon-export-ok &&
183 env GIT_OVERRIDE_VIRTUAL_HOST=.. \
184 git ls-remote "$GIT_DAEMON_URL/escape.git"
187 test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
189 printf "git-upload-pack /interp.git\n\0host=localhost" | packetize
192 fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&
193 depacketize <output >output.raw &&
195 # just pick out the value of master, which avoids any protocol
197 perl -lne "print \$1 if m{^(\\S+) refs/heads/master}" <output.raw >actual &&
198 git -C "$repo" rev-parse master >expect &&
199 test_cmp expect actual