3 test_description='test fetching over git protocol'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 . "$TEST_DIRECTORY"/lib-git-daemon.sh
12 check_verbose_connect () {
13 test_i18ngrep -F "Looking up 127.0.0.1 ..." stderr &&
14 test_i18ngrep -F "Connecting to 127.0.0.1 (port " stderr &&
15 test_i18ngrep -F "done." stderr
18 test_expect_success 'setup repository' '
19 git config push.default matching &&
25 test_expect_success 'create git-accessible bare repository' '
26 mkdir "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
27 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
29 : >git-daemon-export-ok
31 git remote add public "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
32 git push public master:master
35 test_expect_success 'clone git repository' '
36 git clone -v "$GIT_DAEMON_URL/repo.git" clone 2>stderr &&
37 check_verbose_connect &&
38 test_cmp file clone/file
41 test_expect_success 'fetch changes via git protocol' '
42 echo content >>file &&
43 git commit -a -m two &&
45 (cd clone && git pull -v) 2>stderr &&
46 check_verbose_connect &&
47 test_cmp file clone/file
50 test_expect_success 'no-op fetch -v stderr is as expected' '
51 (cd clone && git fetch -v) 2>stderr &&
55 test_expect_success 'no-op fetch without "-v" is quiet' '
56 (cd clone && git fetch 2>../stderr) &&
57 test_must_be_empty stderr
60 test_expect_success 'remote detects correct HEAD' '
61 git push public master:other &&
63 git remote set-head -d origin &&
64 git remote set-head -a origin &&
65 git symbolic-ref refs/remotes/origin/HEAD > output &&
66 echo refs/remotes/origin/master > expect &&
67 test_cmp expect output
71 test_expect_success 'prepare pack objects' '
72 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
73 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
74 git --bare repack -a -d
78 test_expect_success 'fetch notices corrupt pack' '
79 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
80 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
81 p=$(ls objects/pack/pack-*.pack) &&
83 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
85 mkdir repo_bad1.git &&
88 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad1.git" &&
89 test 0 = $(ls objects/pack/pack-*.pack | wc -l)
93 test_expect_success 'fetch notices corrupt idx' '
94 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
95 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
96 rm -f objects/pack/multi-pack-index &&
97 p=$(ls objects/pack/pack-*.idx) &&
99 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
101 mkdir repo_bad2.git &&
104 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad2.git" &&
105 test 0 = $(ls objects/pack | wc -l)
117 chmod -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
133 shift || error "invalid number of arguments"
135 if test -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo"
137 if test -n "$do_export"
139 : >"$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
141 rm -f "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
145 test_must_fail git "$cmd" "$GIT_DAEMON_URL/$repo" "$@" 2>output &&
146 test_i18ngrep "fatal: remote error: $msg: /$repo" output &&
148 chmod +x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
152 msg="access denied or repository not exported"
153 test_expect_success 'clone non-existent' "test_remote_error '$msg' clone nowhere.git"
154 test_expect_success 'push disabled' "test_remote_error '$msg' push repo.git master"
155 test_expect_success 'read access denied' "test_remote_error -x '$msg' fetch repo.git"
156 test_expect_success 'not exported' "test_remote_error -n '$msg' fetch repo.git"
159 start_git_daemon --informative-errors
161 test_expect_success 'clone non-existent' "test_remote_error 'no such repository' clone nowhere.git"
162 test_expect_success 'push disabled' "test_remote_error 'service not enabled' push repo.git master"
163 test_expect_success 'read access denied' "test_remote_error -x 'no such repository' fetch repo.git"
164 test_expect_success 'not exported' "test_remote_error -n 'repository not exported' fetch repo.git"
167 start_git_daemon --interpolated-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH/%H%D"
169 test_expect_success 'access repo via interpolated hostname' '
170 repo="$GIT_DAEMON_DOCUMENT_ROOT_PATH/localhost/interp.git" &&
171 git init --bare "$repo" &&
172 git push "$repo" HEAD &&
173 >"$repo"/git-daemon-export-ok &&
174 GIT_OVERRIDE_VIRTUAL_HOST=localhost \
175 git ls-remote "$GIT_DAEMON_URL/interp.git" &&
176 GIT_OVERRIDE_VIRTUAL_HOST=LOCALHOST \
177 git ls-remote "$GIT_DAEMON_URL/interp.git"
180 test_expect_success 'hostname cannot break out of directory' '
181 repo="$GIT_DAEMON_DOCUMENT_ROOT_PATH/../escape.git" &&
182 git init --bare "$repo" &&
183 git push "$repo" HEAD &&
184 >"$repo"/git-daemon-export-ok &&
186 env GIT_OVERRIDE_VIRTUAL_HOST=.. \
187 git ls-remote "$GIT_DAEMON_URL/escape.git"
190 test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
192 printf "git-upload-pack /interp.git\n\0host=localhost" | packetize
195 fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&
196 depacketize <output >output.raw &&
198 # just pick out the value of master, which avoids any protocol
200 perl -lne "print \$1 if m{^(\\S+) refs/heads/master}" <output.raw >actual &&
201 git -C "$repo" rev-parse master >expect &&
202 test_cmp expect actual