3 test_description='test fetching over git protocol'
6 LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-5570}
7 . "$TEST_DIRECTORY"/lib-git-daemon.sh
10 test_expect_success 'setup repository' '
11 git config push.default matching &&
17 test_expect_success 'create git-accessible bare repository' '
18 mkdir "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
19 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
21 : >git-daemon-export-ok
23 git remote add public "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
24 git push public master:master
27 test_expect_success 'clone git repository' '
28 git clone "$GIT_DAEMON_URL/repo.git" clone &&
29 test_cmp file clone/file
32 test_expect_success 'fetch changes via git protocol' '
33 echo content >>file &&
34 git commit -a -m two &&
36 (cd clone && git pull) &&
37 test_cmp file clone/file
40 test_expect_failure 'remote detects correct HEAD' '
41 git push public master:other &&
43 git remote set-head -d origin &&
44 git remote set-head -a origin &&
45 git symbolic-ref refs/remotes/origin/HEAD > output &&
46 echo refs/remotes/origin/master > expect &&
47 test_cmp expect output
51 test_expect_success 'prepare pack objects' '
52 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
53 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
54 git --bare repack -a -d
58 test_expect_success 'fetch notices corrupt pack' '
59 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
60 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
61 p=`ls objects/pack/pack-*.pack` &&
63 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
65 mkdir repo_bad1.git &&
68 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad1.git" &&
69 test 0 = `ls objects/pack/pack-*.pack | wc -l`
73 test_expect_success 'fetch notices corrupt idx' '
74 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
75 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
76 p=`ls objects/pack/pack-*.idx` &&
78 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
80 mkdir repo_bad2.git &&
83 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad2.git" &&
84 test 0 = `ls objects/pack | wc -l`
96 chmod -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
112 shift || error "invalid number of arguments"
114 if test -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo"
116 if test -n "$do_export"
118 : >"$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
120 rm -f "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
124 test_must_fail git "$cmd" "$GIT_DAEMON_URL/$repo" "$@" 2>output &&
125 echo "fatal: remote error: $msg: /$repo" >expect &&
126 test_cmp expect output
128 chmod +x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
132 msg="access denied or repository not exported"
133 test_expect_success 'clone non-existent' "test_remote_error '$msg' clone nowhere.git "
134 test_expect_success 'push disabled' "test_remote_error '$msg' push repo.git master"
135 test_expect_success 'read access denied' "test_remote_error -x '$msg' fetch repo.git "
136 test_expect_success 'not exported' "test_remote_error -n '$msg' fetch repo.git "
139 start_git_daemon --informative-errors
141 test_expect_success 'clone non-existent' "test_remote_error 'no such repository' clone nowhere.git "
142 test_expect_success 'push disabled' "test_remote_error 'service not enabled' push repo.git master"
143 test_expect_success 'read access denied' "test_remote_error -x 'no such repository' fetch repo.git "
144 test_expect_success 'not exported' "test_remote_error -n 'repository not exported' fetch repo.git "