2010-02-14 16:44:45 +01:00
|
|
|
#!/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"
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
tests: correct misuses of POSIXPERM
POSIXPERM requires that a later call to stat(2) (hence "ls -l")
faithfully reproduces what an earlier chmod(2) did. Some
filesystems cannot satisify this.
SANITY requires that a file or a directory is indeed accessible (or
inaccessible) when its permission bits would say it ought to be
accessible (or inaccessible). Running tests as root would lose this
prerequisite for obvious reasons.
Fix a few tests that misuse POSIXPERM.
t0061-run-command.sh has two uses of POSIXPERM.
- One checks that an attempt to execute a file that is marked as
unexecutable results in a failure with EACCES; I do not think
having root-ness or any other capability that busts the
filesystem permission mode bits will make you run an unexecutable
file, so this should be left as-is. The test does not have
anything to do with SANITY.
- The other one expects 'git nitfol' runs the alias when an
alias.nitfol is defined and a directory on the PATH is marked as
unreadable and unsearchable. I _think_ the test tries to reject
the alternative expectation that we want to refuse to run the
alias because it would break "no alias may mask a command" rule
if a file 'git-nitfol' exists in the unreadable directory but we
cannot even determine if that is the case. Under !SANITY that
busts the permission bits, this test no longer checks that, so it
must be protected with SANITY.
t1509-root-worktree.sh expects to be run on a / that is writable by
the user and sees if Git behaves "sensibly" when /.git is the
repository to govern a worktree that is the whole filesystem, and
also if Git behaves "sensibly" when / itself is a bare repository
with refs, objects, and friends (I find the definition of "behaves
sensibly" under these conditions hard to fathom, but it is a
different matter).
The implementation of the test is very much problematic.
- It requires POSIXPERM, but it does not do chmod or checks modes
in any way.
- It runs "rm /*" and "rm -fr /refs /objects ..." in one of the
tests, and also does "cd / && git init --bare". If done on a
live system that takes advantages of the "feature" being tested,
these obviously will clobber the system. But there is no guard
against such a breakage.
- It uses "test $UID = 0" to see rootness, which now should be
spelled "! test_have_prereq NOT_ROOT"
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-16 19:32:09 +01:00
|
|
|
if ! test -w /
|
|
|
|
then
|
|
|
|
skip_all="Test requiring writable / skipped. Read this test if you want to run it"
|
|
|
|
test_done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test -e /refs || test -e /objects || test -e /info || test -e /hooks ||
|
|
|
|
test -e /.git || test -e /foo || test -e /me
|
|
|
|
then
|
|
|
|
skip_all="Skip test that clobbers existing files in /"
|
2010-02-14 16:44:45 +01:00
|
|
|
test_done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$IKNOWWHATIAMDOING" != "YES" ]; then
|
2010-06-24 19:44:48 +02:00
|
|
|
skip_all="You must set env var IKNOWWHATIAMDOING=YES in order to run this test"
|
2010-02-14 16:44:45 +01:00
|
|
|
test_done
|
|
|
|
fi
|
|
|
|
|
tests: correct misuses of POSIXPERM
POSIXPERM requires that a later call to stat(2) (hence "ls -l")
faithfully reproduces what an earlier chmod(2) did. Some
filesystems cannot satisify this.
SANITY requires that a file or a directory is indeed accessible (or
inaccessible) when its permission bits would say it ought to be
accessible (or inaccessible). Running tests as root would lose this
prerequisite for obvious reasons.
Fix a few tests that misuse POSIXPERM.
t0061-run-command.sh has two uses of POSIXPERM.
- One checks that an attempt to execute a file that is marked as
unexecutable results in a failure with EACCES; I do not think
having root-ness or any other capability that busts the
filesystem permission mode bits will make you run an unexecutable
file, so this should be left as-is. The test does not have
anything to do with SANITY.
- The other one expects 'git nitfol' runs the alias when an
alias.nitfol is defined and a directory on the PATH is marked as
unreadable and unsearchable. I _think_ the test tries to reject
the alternative expectation that we want to refuse to run the
alias because it would break "no alias may mask a command" rule
if a file 'git-nitfol' exists in the unreadable directory but we
cannot even determine if that is the case. Under !SANITY that
busts the permission bits, this test no longer checks that, so it
must be protected with SANITY.
t1509-root-worktree.sh expects to be run on a / that is writable by
the user and sees if Git behaves "sensibly" when /.git is the
repository to govern a worktree that is the whole filesystem, and
also if Git behaves "sensibly" when / itself is a bare repository
with refs, objects, and friends (I find the definition of "behaves
sensibly" under these conditions hard to fathom, but it is a
different matter).
The implementation of the test is very much problematic.
- It requires POSIXPERM, but it does not do chmod or checks modes
in any way.
- It runs "rm /*" and "rm -fr /refs /objects ..." in one of the
tests, and also does "cd / && git init --bare". If done on a
live system that takes advantages of the "feature" being tested,
these obviously will clobber the system. But there is no guard
against such a breakage.
- It uses "test $UID = 0" to see rootness, which now should be
spelled "! test_have_prereq NOT_ROOT"
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-16 19:32:09 +01:00
|
|
|
if ! test_have_prereq NOT_ROOT
|
|
|
|
then
|
|
|
|
skip_all="No you can't run this as root"
|
2010-02-14 16:44:45 +01:00
|
|
|
test_done
|
|
|
|
fi
|
|
|
|
|
|
|
|
ONE_SHA1=d00491fd7e5bb6fa28c517a0bb32b8b506539d4d
|
|
|
|
|
|
|
|
test_expect_success 'setup' '
|
2015-08-05 11:43:50 +02:00
|
|
|
rm -rf /foo &&
|
2010-02-14 16:44:45 +01:00
|
|
|
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
|
|
|
|
|
2010-10-13 20:36:36 +02:00
|
|
|
GIT_DIR="$TRASH_DIRECTORY/.git" && export GIT_DIR
|
|
|
|
GIT_WORK_TREE=/ && export GIT_WORK_TREE
|
2010-02-14 16:44:45 +01:00
|
|
|
|
|
|
|
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 /'
|
|
|
|
|
2010-10-13 20:36:36 +02:00
|
|
|
GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
|
|
|
|
GIT_WORK_TREE=/ && export GIT_WORK_TREE
|
2010-02-14 16:44:45 +01:00
|
|
|
|
|
|
|
test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
|
|
|
|
test_foobar_root
|
|
|
|
|
|
|
|
test_expect_success 'go to /foo' 'cd /foo'
|
|
|
|
|
2010-10-13 20:36:36 +02:00
|
|
|
GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
|
|
|
|
GIT_WORK_TREE=/ && export GIT_WORK_TREE
|
2010-02-14 16:44:45 +01:00
|
|
|
|
|
|
|
test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
|
|
|
|
test_foobar_foo
|
|
|
|
|
|
|
|
test_expect_success 'go to /foo/bar' 'cd /foo/bar'
|
|
|
|
|
2010-10-13 20:36:36 +02:00
|
|
|
GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
|
|
|
|
GIT_WORK_TREE=/ && export GIT_WORK_TREE
|
2010-02-14 16:44:45 +01:00
|
|
|
|
|
|
|
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 /'
|
|
|
|
|
2010-10-13 20:36:36 +02:00
|
|
|
GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR
|
|
|
|
GIT_WORK_TREE=. && export GIT_WORK_TREE
|
2010-02-14 16:44:45 +01:00
|
|
|
|
|
|
|
test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
|
|
|
|
test_foobar_root
|
|
|
|
|
|
|
|
test_expect_success 'go to /' 'cd /foo'
|
|
|
|
|
2010-10-13 20:36:36 +02:00
|
|
|
GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR
|
|
|
|
GIT_WORK_TREE=.. && export GIT_WORK_TREE
|
2010-02-14 16:44:45 +01:00
|
|
|
|
|
|
|
test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/"
|
|
|
|
test_foobar_foo
|
|
|
|
|
|
|
|
test_expect_success 'go to /foo/bar' 'cd /foo/bar'
|
|
|
|
|
2010-10-13 20:36:36 +02:00
|
|
|
GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR
|
|
|
|
GIT_WORK_TREE=../.. && export GIT_WORK_TREE
|
2010-02-14 16:44:45 +01:00
|
|
|
|
|
|
|
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' '
|
2015-08-05 11:43:50 +02:00
|
|
|
rm -rf /.git &&
|
2010-02-14 16:44:45 +01:00
|
|
|
echo "Initialized empty Git repository in /.git/" > expected &&
|
|
|
|
git init > result &&
|
2020-05-13 15:23:06 +02:00
|
|
|
test_i18ncmp expected result
|
2010-02-14 16:44:45 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
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' '
|
2015-08-05 11:43:50 +02:00
|
|
|
rm -rf /refs /objects /info /hooks &&
|
2015-08-05 11:43:51 +02:00
|
|
|
rm -f /expected /ls.expected /me /result &&
|
2010-02-14 16:44:45 +01:00
|
|
|
cd / &&
|
|
|
|
echo "Initialized empty Git repository in /" > expected &&
|
|
|
|
git init --bare > result &&
|
2020-05-13 15:23:06 +02:00
|
|
|
test_i18ncmp expected result
|
2010-02-14 16:44:45 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_vars 'auto gitdir, root' "." "" ""
|
|
|
|
|
|
|
|
test_expect_success 'go to /foo' 'cd /foo'
|
|
|
|
|
|
|
|
test_vars 'auto gitdir, root' "/" "" ""
|
|
|
|
|
|
|
|
test_done
|