Windows: define S_ISUID properly
[git/dscho.git] / t / t1509-root-worktree.sh
blob335420fd87f87727f323156f461e520374b7da0b
1 #!/bin/sh
3 test_description='Test Git when git repository is located at root
5 This test requires write access in root. Do not bother if you do not
6 have a throwaway chroot or VM.
8 Script t1509/prepare-chroot.sh may help you setup chroot, then you
9 can chroot in and execute this test from there.
12 . ./test-lib.sh
14 test_cmp_val() {
15 echo "$1" > expected
16 echo "$2" > result
17 test_cmp expected result
20 test_vars() {
21 test_expect_success "$1: gitdir" '
22 test_cmp_val "'"$2"'" "$(git rev-parse --git-dir)"
25 test_expect_success "$1: worktree" '
26 test_cmp_val "'"$3"'" "$(git rev-parse --show-toplevel)"
29 test_expect_success "$1: prefix" '
30 test_cmp_val "'"$4"'" "$(git rev-parse --show-prefix)"
34 test_foobar_root() {
35 test_expect_success 'add relative' '
36 test -z "$(cd / && git ls-files)" &&
37 git add foo/foome &&
38 git add foo/bar/barme &&
39 git add me &&
40 ( cd / && git ls-files --stage ) > result &&
41 test_cmp /ls.expected result &&
42 rm "$(git rev-parse --git-dir)/index"
45 test_expect_success 'add absolute' '
46 test -z "$(cd / && git ls-files)" &&
47 git add /foo/foome &&
48 git add /foo/bar/barme &&
49 git add /me &&
50 ( cd / && git ls-files --stage ) > result &&
51 test_cmp /ls.expected result &&
52 rm "$(git rev-parse --git-dir)/index"
57 test_foobar_foo() {
58 test_expect_success 'add relative' '
59 test -z "$(cd / && git ls-files)" &&
60 git add foome &&
61 git add bar/barme &&
62 git add ../me &&
63 ( cd / && git ls-files --stage ) > result &&
64 test_cmp /ls.expected result &&
65 rm "$(git rev-parse --git-dir)/index"
68 test_expect_success 'add absolute' '
69 test -z "$(cd / && git ls-files)" &&
70 git add /foo/foome &&
71 git add /foo/bar/barme &&
72 git add /me &&
73 ( cd / && git ls-files --stage ) > result &&
74 test_cmp /ls.expected result &&
75 rm "$(git rev-parse --git-dir)/index"
79 test_foobar_foobar() {
80 test_expect_success 'add relative' '
81 test -z "$(cd / && git ls-files)" &&
82 git add ../foome &&
83 git add barme &&
84 git add ../../me &&
85 ( cd / && git ls-files --stage ) > result &&
86 test_cmp /ls.expected result &&
87 rm "$(git rev-parse --git-dir)/index"
90 test_expect_success 'add absolute' '
91 test -z "$(cd / && git ls-files)" &&
92 git add /foo/foome &&
93 git add /foo/bar/barme &&
94 git add /me &&
95 ( cd / && git ls-files --stage ) > result &&
96 test_cmp /ls.expected result &&
97 rm "$(git rev-parse --git-dir)/index"
101 if ! test_have_prereq POSIXPERM || ! [ -w / ]; then
102 skip_all="Dangerous test skipped. Read this test if you want to execute it"
103 test_done
106 if [ "$IKNOWWHATIAMDOING" != "YES" ]; then
107 skip_all="You must set env var IKNOWWHATIAMDOING=YES in order to run this test"
108 test_done
111 if [ "$UID" = 0 ]; then
112 skip_all="No you can't run this with root"
113 test_done
116 ONE_SHA1=d00491fd7e5bb6fa28c517a0bb32b8b506539d4d
118 test_expect_success 'setup' '
119 rm -rf /foo
120 mkdir /foo &&
121 mkdir /foo/bar &&
122 echo 1 > /foo/foome &&
123 echo 1 > /foo/bar/barme &&
124 echo 1 > /me
127 say "GIT_DIR absolute, GIT_WORK_TREE set"
129 test_expect_success 'go to /' 'cd /'
131 cat >ls.expected <<EOF
132 100644 $ONE_SHA1 0 foo/bar/barme
133 100644 $ONE_SHA1 0 foo/foome
134 100644 $ONE_SHA1 0 me
137 GIT_DIR="$TRASH_DIRECTORY/.git" && export GIT_DIR
138 GIT_WORK_TREE=/ && export GIT_WORK_TREE
140 test_vars 'abs gitdir, root' "$GIT_DIR" "/" ""
141 test_foobar_root
143 test_expect_success 'go to /foo' 'cd /foo'
145 test_vars 'abs gitdir, foo' "$GIT_DIR" "/" "foo/"
146 test_foobar_foo
148 test_expect_success 'go to /foo/bar' 'cd /foo/bar'
150 test_vars 'abs gitdir, foo/bar' "$GIT_DIR" "/" "foo/bar/"
151 test_foobar_foobar
153 say "GIT_DIR relative, GIT_WORK_TREE set"
155 test_expect_success 'go to /' 'cd /'
157 GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
158 GIT_WORK_TREE=/ && export GIT_WORK_TREE
160 test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
161 test_foobar_root
163 test_expect_success 'go to /foo' 'cd /foo'
165 GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
166 GIT_WORK_TREE=/ && export GIT_WORK_TREE
168 test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
169 test_foobar_foo
171 test_expect_success 'go to /foo/bar' 'cd /foo/bar'
173 GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
174 GIT_WORK_TREE=/ && export GIT_WORK_TREE
176 test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/"
177 test_foobar_foobar
179 say "GIT_DIR relative, GIT_WORK_TREE relative"
181 test_expect_success 'go to /' 'cd /'
183 GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
184 GIT_WORK_TREE=. && export GIT_WORK_TREE
186 test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
187 test_foobar_root
189 test_expect_success 'go to /' 'cd /foo'
191 GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
192 GIT_WORK_TREE=.. && export GIT_WORK_TREE
194 test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
195 test_foobar_foo
197 test_expect_success 'go to /foo/bar' 'cd /foo/bar'
199 GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
200 GIT_WORK_TREE=../.. && export GIT_WORK_TREE
202 test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/"
203 test_foobar_foobar
205 say ".git at root"
207 unset GIT_DIR
208 unset GIT_WORK_TREE
210 test_expect_success 'go to /' 'cd /'
211 test_expect_success 'setup' '
212 rm -rf /.git
213 echo "Initialized empty Git repository in /.git/" > expected &&
214 git init > result &&
215 test_cmp expected result
218 test_vars 'auto gitdir, root' ".git" "/" ""
219 test_foobar_root
221 test_expect_success 'go to /foo' 'cd /foo'
222 test_vars 'auto gitdir, foo' "/.git" "/" "foo/"
223 test_foobar_foo
225 test_expect_success 'go to /foo/bar' 'cd /foo/bar'
226 test_vars 'auto gitdir, foo/bar' "/.git" "/" "foo/bar/"
227 test_foobar_foobar
229 test_expect_success 'cleanup' 'rm -rf /.git'
231 say "auto bare gitdir"
233 # DESTROYYYYY!!!!!
234 test_expect_success 'setup' '
235 rm -rf /refs /objects /info /hooks
236 rm /*
237 cd / &&
238 echo "Initialized empty Git repository in /" > expected &&
239 git init --bare > result &&
240 test_cmp expected result
243 test_vars 'auto gitdir, root' "." "" ""
245 test_expect_success 'go to /foo' 'cd /foo'
247 test_vars 'auto gitdir, root' "/" "" ""
249 test_done