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' '
16 test_expect_success 'create git-accessible bare repository' '
17 mkdir "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
18 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
20 : >git-daemon-export-ok
22 git remote add public "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
23 git push public master:master
26 test_expect_success 'clone git repository' '
27 git clone "$GIT_DAEMON_URL/repo.git" clone &&
28 test_cmp file clone/file
31 test_expect_success 'fetch changes via git protocol' '
32 echo content >>file &&
33 git commit -a -m two &&
35 (cd clone && git pull) &&
36 test_cmp file clone/file
39 test_expect_failure 'remote detects correct HEAD' '
40 git push public master:other &&
42 git remote set-head -d origin &&
43 git remote set-head -a origin &&
44 git symbolic-ref refs/remotes/origin/HEAD > output &&
45 echo refs/remotes/origin/master > expect &&
46 test_cmp expect output
50 test_expect_success 'prepare pack objects' '
51 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
52 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
53 git --bare repack -a -d
57 test_expect_success 'fetch notices corrupt pack' '
58 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
59 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
60 p=`ls objects/pack/pack-*.pack` &&
62 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
64 mkdir repo_bad1.git &&
67 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad1.git" &&
68 test 0 = `ls objects/pack/pack-*.pack | wc -l`
72 test_expect_success 'fetch notices corrupt idx' '
73 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
74 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
75 p=`ls objects/pack/pack-*.idx` &&
77 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
79 mkdir repo_bad2.git &&
82 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad2.git" &&
83 test 0 = `ls objects/pack | wc -l`
95 chmod -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
108 error "invalid number of arguments"
115 if test -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo"
117 if test -n "$do_export"
119 : >"$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
121 rm -f "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
125 test_must_fail git "$cmd" "$GIT_DAEMON_URL/$repo" 2>output &&
126 echo "fatal: remote error: $msg: /$repo" >expect &&
127 test_cmp expect output
129 chmod +x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
133 msg="access denied or repository not exported"
134 test_expect_success 'clone non-existent' "test_remote_error clone nowhere.git '$msg'"
135 test_expect_success 'push disabled' "test_remote_error push repo.git '$msg'"
136 test_expect_success 'read access denied' "test_remote_error -x fetch repo.git '$msg'"
137 test_expect_success 'not exported' "test_remote_error -n fetch repo.git '$msg'"
140 start_git_daemon --informative-errors
142 test_expect_success 'clone non-existent' "test_remote_error clone nowhere.git 'no such repository'"
143 test_expect_success 'push disabled' "test_remote_error push repo.git 'service not enabled'"
144 test_expect_success 'read access denied' "test_remote_error -x fetch repo.git 'no such repository'"
145 test_expect_success 'not exported' "test_remote_error -n fetch repo.git 'repository not exported'"