status: introduce status.short to enable --short by default
[git/mjg.git] / t / t5570-git-daemon.sh
blobf01edffa3c0babf76593fbd211f6606ff2036c74
1 #!/bin/sh
3 test_description='test fetching over git protocol'
4 . ./test-lib.sh
6 LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-5570}
7 . "$TEST_DIRECTORY"/lib-git-daemon.sh
8 start_git_daemon
10 test_expect_success 'setup repository' '
11 git config push.default matching &&
12 echo content >file &&
13 git add file &&
14 git commit -m one
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" &&
20 git --bare init &&
21 : >git-daemon-export-ok
22 ) &&
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 &&
35 git push public &&
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 &&
42 (cd clone &&
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` &&
62 chmod u+w $p &&
63 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
64 ) &&
65 mkdir repo_bad1.git &&
66 (cd repo_bad1.git &&
67 git --bare init &&
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` &&
77 chmod u+w $p &&
78 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
79 ) &&
80 mkdir repo_bad2.git &&
81 (cd repo_bad2.git &&
82 git --bare init &&
83 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad2.git" &&
84 test 0 = `ls objects/pack | wc -l`
88 test_remote_error()
90 do_export=YesPlease
91 while test $# -gt 0
93 case $1 in
94 -x)
95 shift
96 chmod -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
98 -n)
99 shift
100 do_export=
103 break
104 esac
105 done
107 msg=$1
108 shift
109 cmd=$1
110 shift
111 repo=$1
112 shift || error "invalid number of arguments"
114 if test -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo"
115 then
116 if test -n "$do_export"
117 then
118 : >"$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
119 else
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
127 ret=$?
128 chmod +x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
129 (exit $ret)
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 "
138 stop_git_daemon
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 "
146 stop_git_daemon
147 test_done