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.
 
  17         test_cmp expected result
 
  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)"
 
  35         test_expect_success 'add relative' '
 
  36                 test -z "$(cd / && git ls-files)" &&
 
  38                 git add foo/bar/barme &&
 
  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)" &&
 
  48                 git add /foo/bar/barme &&
 
  50                 ( cd / && git ls-files --stage ) > result &&
 
  51                 test_cmp /ls.expected result &&
 
  52                 rm "$(git rev-parse --git-dir)/index"
 
  58         test_expect_success 'add relative' '
 
  59                 test -z "$(cd / && git ls-files)" &&
 
  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)" &&
 
  71                 git add /foo/bar/barme &&
 
  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)" &&
 
  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)" &&
 
  93                 git add /foo/bar/barme &&
 
  95                 ( cd / && git ls-files --stage ) > result &&
 
  96                 test_cmp /ls.expected result &&
 
  97                 rm "$(git rev-parse --git-dir)/index"
 
 103         skip_all="Test requiring writable / skipped. Read this test if you want to run it"
 
 107 if  test -e /refs || test -e /objects || test -e /info || test -e /hooks ||
 
 108     test -e /.git || test -e /foo || test -e /me
 
 110         skip_all="Skip test that clobbers existing files in /"
 
 114 if [ "$IKNOWWHATIAMDOING" != "YES" ]; then
 
 115         skip_all="You must set env var IKNOWWHATIAMDOING=YES in order to run this test"
 
 119 if ! test_have_prereq NOT_ROOT
 
 121         skip_all="No you can't run this as root"
 
 125 ONE_SHA1=d00491fd7e5bb6fa28c517a0bb32b8b506539d4d
 
 127 test_expect_success 'setup' '
 
 131         echo 1 > /foo/foome &&
 
 132         echo 1 > /foo/bar/barme &&
 
 136 say "GIT_DIR absolute, GIT_WORK_TREE set"
 
 138 test_expect_success 'go to /' 'cd /'
 
 140 cat >ls.expected <<EOF
 
 141 100644 $ONE_SHA1 0      foo/bar/barme
 
 142 100644 $ONE_SHA1 0      foo/foome
 
 143 100644 $ONE_SHA1 0      me
 
 146 GIT_DIR="$TRASH_DIRECTORY/.git" && export GIT_DIR
 
 147 GIT_WORK_TREE=/ && export GIT_WORK_TREE
 
 149 test_vars 'abs gitdir, root' "$GIT_DIR" "/" ""
 
 152 test_expect_success 'go to /foo' 'cd /foo'
 
 154 test_vars 'abs gitdir, foo' "$GIT_DIR" "/" "foo/"
 
 157 test_expect_success 'go to /foo/bar' 'cd /foo/bar'
 
 159 test_vars 'abs gitdir, foo/bar' "$GIT_DIR" "/" "foo/bar/"
 
 162 say "GIT_DIR relative, GIT_WORK_TREE set"
 
 164 test_expect_success 'go to /' 'cd /'
 
 166 GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
 
 167 GIT_WORK_TREE=/ && export GIT_WORK_TREE
 
 169 test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
 
 172 test_expect_success 'go to /foo' 'cd /foo'
 
 174 GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
 
 175 GIT_WORK_TREE=/ && export GIT_WORK_TREE
 
 177 test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
 
 180 test_expect_success 'go to /foo/bar' 'cd /foo/bar'
 
 182 GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
 
 183 GIT_WORK_TREE=/ && export GIT_WORK_TREE
 
 185 test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/"
 
 188 say "GIT_DIR relative, GIT_WORK_TREE relative"
 
 190 test_expect_success 'go to /' 'cd /'
 
 192 GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
 
 193 GIT_WORK_TREE=. && export GIT_WORK_TREE
 
 195 test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
 
 198 test_expect_success 'go to /' 'cd /foo'
 
 200 GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
 
 201 GIT_WORK_TREE=.. && export GIT_WORK_TREE
 
 203 test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
 
 206 test_expect_success 'go to /foo/bar' 'cd /foo/bar'
 
 208 GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
 
 209 GIT_WORK_TREE=../.. && export GIT_WORK_TREE
 
 211 test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/"
 
 219 test_expect_success 'go to /' 'cd /'
 
 220 test_expect_success 'setup' '
 
 222         echo "Initialized empty Git repository in /.git/" > expected &&
 
 224         test_cmp expected result
 
 227 test_vars 'auto gitdir, root' ".git" "/" ""
 
 230 test_expect_success 'go to /foo' 'cd /foo'
 
 231 test_vars 'auto gitdir, foo' "/.git" "/" "foo/"
 
 234 test_expect_success 'go to /foo/bar' 'cd /foo/bar'
 
 235 test_vars 'auto gitdir, foo/bar' "/.git" "/" "foo/bar/"
 
 238 test_expect_success 'cleanup' 'rm -rf /.git'
 
 240 say "auto bare gitdir"
 
 243 test_expect_success 'setup' '
 
 244         rm -rf /refs /objects /info /hooks &&
 
 245         rm -f /expected /ls.expected /me /result &&
 
 247         echo "Initialized empty Git repository in /" > expected &&
 
 248         git init --bare > result &&
 
 249         test_cmp expected result
 
 252 test_vars 'auto gitdir, root' "." "" ""
 
 254 test_expect_success 'go to /foo' 'cd /foo'
 
 256 test_vars 'auto gitdir, root' "/" "" ""