1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
#!/bin/sh
test_description='Test Git when git repository is located at root
This test requires write access in root. Do not bother if you do not
have a throwaway chroot or VM.
Script t1509/prepare-chroot.sh may help you setup chroot, then you
can chroot in and execute this test from there.
'
. ./test-lib.sh
test_cmp_val() {
echo "$1" > expected
echo "$2" > result
test_cmp expected result
}
test_vars() {
test_expect_success "$1: gitdir" '
test_cmp_val "'"$2"'" "$(git rev-parse --git-dir)"
'
test_expect_success "$1: worktree" '
test_cmp_val "'"$3"'" "$(git rev-parse --show-toplevel)"
'
test_expect_success "$1: prefix" '
test_cmp_val "'"$4"'" "$(git rev-parse --show-prefix)"
'
}
test_foobar_root() {
test_expect_success 'add relative' '
test -z "$(cd / && git ls-files)" &&
git add foo/foome &&
git add foo/bar/barme &&
git add me &&
( cd / && git ls-files --stage ) > result &&
test_cmp /ls.expected result &&
rm "$(git rev-parse --git-dir)/index"
'
test_expect_success 'add absolute' '
test -z "$(cd / && git ls-files)" &&
git add /foo/foome &&
git add /foo/bar/barme &&
git add /me &&
( cd / && git ls-files --stage ) > result &&
test_cmp /ls.expected result &&
rm "$(git rev-parse --git-dir)/index"
'
}
test_foobar_foo() {
test_expect_success 'add relative' '
test -z "$(cd / && git ls-files)" &&
git add foome &&
git add bar/barme &&
git add ../me &&
( cd / && git ls-files --stage ) > result &&
test_cmp /ls.expected result &&
rm "$(git rev-parse --git-dir)/index"
'
test_expect_success 'add absolute' '
test -z "$(cd / && git ls-files)" &&
git add /foo/foome &&
git add /foo/bar/barme &&
git add /me &&
( cd / && git ls-files --stage ) > result &&
test_cmp /ls.expected result &&
rm "$(git rev-parse --git-dir)/index"
'
}
test_foobar_foobar() {
test_expect_success 'add relative' '
test -z "$(cd / && git ls-files)" &&
git add ../foome &&
git add barme &&
git add ../../me &&
( cd / && git ls-files --stage ) > result &&
test_cmp /ls.expected result &&
rm "$(git rev-parse --git-dir)/index"
'
test_expect_success 'add absolute' '
test -z "$(cd / && git ls-files)" &&
git add /foo/foome &&
git add /foo/bar/barme &&
git add /me &&
( cd / && git ls-files --stage ) > result &&
test_cmp /ls.expected result &&
rm "$(git rev-parse --git-dir)/index"
'
}
if ! test_have_prereq POSIXPERM || ! [ -w / ]; then
skip_all="Dangerous test skipped. Read this test if you want to execute it"
test_done
fi
if [ "$IKNOWWHATIAMDOING" != "YES" ]; then
skip_all="You must set env var IKNOWWHATIAMDOING=YES in order to run this test"
test_done
fi
if [ "$UID" = 0 ]; then
skip_all="No you can't run this with root"
test_done
fi
ONE_SHA1=d00491fd7e5bb6fa28c517a0bb32b8b506539d4d
test_expect_success 'setup' '
rm -rf /foo
mkdir /foo &&
mkdir /foo/bar &&
echo 1 > /foo/foome &&
echo 1 > /foo/bar/barme &&
echo 1 > /me
'
say "GIT_DIR absolute, GIT_WORK_TREE set"
test_expect_success 'go to /' 'cd /'
cat >ls.expected <<EOF
100644 $ONE_SHA1 0 foo/bar/barme
100644 $ONE_SHA1 0 foo/foome
100644 $ONE_SHA1 0 me
EOF
GIT_DIR="$TRASH_DIRECTORY/.git" && export GIT_DIR
GIT_WORK_TREE=/ && export GIT_WORK_TREE
test_vars 'abs gitdir, root' "$GIT_DIR" "/" ""
test_foobar_root
test_expect_success 'go to /foo' 'cd /foo'
test_vars 'abs gitdir, foo' "$GIT_DIR" "/" "foo/"
test_foobar_foo
test_expect_success 'go to /foo/bar' 'cd /foo/bar'
test_vars 'abs gitdir, foo/bar' "$GIT_DIR" "/" "foo/bar/"
test_foobar_foobar
say "GIT_DIR relative, GIT_WORK_TREE set"
test_expect_success 'go to /' 'cd /'
GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
GIT_WORK_TREE=/ && export GIT_WORK_TREE
test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
test_foobar_root
test_expect_success 'go to /foo' 'cd /foo'
GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
GIT_WORK_TREE=/ && export GIT_WORK_TREE
test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
test_foobar_foo
test_expect_success 'go to /foo/bar' 'cd /foo/bar'
GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
GIT_WORK_TREE=/ && export GIT_WORK_TREE
test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/"
test_foobar_foobar
say "GIT_DIR relative, GIT_WORK_TREE relative"
test_expect_success 'go to /' 'cd /'
GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
GIT_WORK_TREE=. && export GIT_WORK_TREE
test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
test_foobar_root
test_expect_success 'go to /' 'cd /foo'
GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
GIT_WORK_TREE=.. && export GIT_WORK_TREE
test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
test_foobar_foo
test_expect_success 'go to /foo/bar' 'cd /foo/bar'
GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
GIT_WORK_TREE=../.. && export GIT_WORK_TREE
test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/"
test_foobar_foobar
say ".git at root"
unset GIT_DIR
unset GIT_WORK_TREE
test_expect_success 'go to /' 'cd /'
test_expect_success 'setup' '
rm -rf /.git
echo "Initialized empty Git repository in /.git/" > expected &&
git init > result &&
test_cmp expected result
'
test_vars 'auto gitdir, root' ".git" "/" ""
test_foobar_root
test_expect_success 'go to /foo' 'cd /foo'
test_vars 'auto gitdir, foo' "/.git" "/" "foo/"
test_foobar_foo
test_expect_success 'go to /foo/bar' 'cd /foo/bar'
test_vars 'auto gitdir, foo/bar' "/.git" "/" "foo/bar/"
test_foobar_foobar
test_expect_success 'cleanup' 'rm -rf /.git'
say "auto bare gitdir"
# DESTROYYYYY!!!!!
test_expect_success 'setup' '
rm -rf /refs /objects /info /hooks
rm /*
cd / &&
echo "Initialized empty Git repository in /" > expected &&
git init --bare > result &&
test_cmp expected result
'
test_vars 'auto gitdir, root' "." "" ""
test_expect_success 'go to /foo' 'cd /foo'
test_vars 'auto gitdir, root' "/" "" ""
test_done
|