Add test for using Git at root of file system
This kind of test requires a throw-away root filesystem so that it can play on. If you have such a system, go ahead, "chmod 777 /" and run this test manually. Because this is a dangerous test, you are required to set an env variable, and not to use root to run it. Script prepare-root.sh may help you set up a chroot environment with Git test suite inside. You will need Linux, static linked busybox, rsync and root permission to use it. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
72ec8ba6dd
commit
3719b2fe55
249
t/t1509-root-worktree.sh
Executable file
249
t/t1509-root-worktree.sh
Executable file
@ -0,0 +1,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
|
||||||
|
say "Dangerous test skipped. Read this test if you want to execute it"
|
||||||
|
test_done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$IKNOWWHATIAMDOING" != "YES" ]; then
|
||||||
|
say "You must set env var IKNOWWHATIAMDOING=YES in order to run this test"
|
||||||
|
test_done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$UID" = 0 ]; then
|
||||||
|
say "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
|
||||||
|
|
||||||
|
export GIT_DIR="$TRASH_DIRECTORY/.git"
|
||||||
|
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 /'
|
||||||
|
|
||||||
|
export GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git"
|
||||||
|
export GIT_WORK_TREE=/
|
||||||
|
|
||||||
|
test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
|
||||||
|
test_foobar_root
|
||||||
|
|
||||||
|
test_expect_success 'go to /foo' 'cd /foo'
|
||||||
|
|
||||||
|
export GIT_DIR="../$TRASH_DIRECTORY/.git"
|
||||||
|
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'
|
||||||
|
|
||||||
|
export GIT_DIR="../../$TRASH_DIRECTORY/.git"
|
||||||
|
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 /'
|
||||||
|
|
||||||
|
export GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git"
|
||||||
|
export GIT_WORK_TREE=.
|
||||||
|
|
||||||
|
test_vars 'rel gitdir, root' "$GIT_DIR" "/" ""
|
||||||
|
test_foobar_root
|
||||||
|
|
||||||
|
test_expect_success 'go to /' 'cd /foo'
|
||||||
|
|
||||||
|
export GIT_DIR="../$TRASH_DIRECTORY/.git"
|
||||||
|
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'
|
||||||
|
|
||||||
|
export GIT_DIR="../../$TRASH_DIRECTORY/.git"
|
||||||
|
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
|
14
t/t1509/excludes
Normal file
14
t/t1509/excludes
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
*.o
|
||||||
|
*~
|
||||||
|
*.bak
|
||||||
|
*.c
|
||||||
|
*.h
|
||||||
|
.git
|
||||||
|
contrib
|
||||||
|
Documentation
|
||||||
|
git-gui
|
||||||
|
gitk-git
|
||||||
|
gitweb
|
||||||
|
t/t4013
|
||||||
|
t/t5100
|
||||||
|
t/t5515
|
38
t/t1509/prepare-chroot.sh
Executable file
38
t/t1509/prepare-chroot.sh
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo >&2 "$@"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
xmkdir() {
|
||||||
|
while [ -n "$1" ]; do
|
||||||
|
[ -d "$1" ] || mkdir "$1" || die "Unable to mkdir $1"
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
R="$1"
|
||||||
|
|
||||||
|
[ -n "$R" ] || die "Usage: prepare-chroot.sh <root>"
|
||||||
|
[ -x git ] || die "This script needs to be executed at git source code's top directory"
|
||||||
|
[ -x /bin/busybox ] || die "You need busybox"
|
||||||
|
|
||||||
|
xmkdir "$R" "$R/bin" "$R/etc" "$R/lib" "$R/dev"
|
||||||
|
[ -c "$R/dev/null" ] || die "/dev/null is missing. Do mknod $R/dev/null c 1 3 && chmod 666 $R/dev/null"
|
||||||
|
echo "root:x:0:0:root:/:/bin/sh" > "$R/etc/passwd"
|
||||||
|
echo "$(id -nu):x:$(id -u):$(id -g)::$(pwd)/t:/bin/sh" >> "$R/etc/passwd"
|
||||||
|
echo "root::0:root" > "$R/etc/group"
|
||||||
|
echo "$(id -ng)::$(id -g):$(id -nu)" >> "$R/etc/group"
|
||||||
|
|
||||||
|
[ -x "$R/bin/busybox" ] || cp /bin/busybox "$R/bin/busybox"
|
||||||
|
[ -x "$R/bin/sh" ] || ln -s /bin/busybox "$R/bin/sh"
|
||||||
|
[ -x "$R/bin/su" ] || ln -s /bin/busybox "$R/bin/su"
|
||||||
|
|
||||||
|
mkdir -p "$R$(pwd)"
|
||||||
|
rsync --exclude-from t/t1509/excludes -Ha . "$R$(pwd)"
|
||||||
|
ldd git | grep '/' | sed 's,.*\s\(/[^ ]*\).*,\1,' | while read i; do
|
||||||
|
mkdir -p "$R$(dirname $i)"
|
||||||
|
cp "$i" "$R/$i"
|
||||||
|
done
|
||||||
|
echo "Execute this in root: 'chroot $R /bin/su - $(id -nu)'"
|
Loading…
Reference in New Issue
Block a user