Skip to content

Commit

Permalink
Merge branch 'jl/fix-test'
Browse files Browse the repository at this point in the history
* jl/fix-test:
  t1020: Get rid of 'cd "$HERE"' at the start of each test
  t2016 (checkout -p): add missing &&
  t1302 (core.repositoryversion): style tweaks
  t2105 (gitfile): add missing &&
  t1450 (fsck): remove dangling objects
  tests: subshell indentation stylefix
  Several tests: cd inside subshell instead of around
  • Loading branch information
gitster committed Sep 15, 2010
2 parents 43d268e + fd3c32c commit e3f213c
Show file tree
Hide file tree
Showing 35 changed files with 604 additions and 491 deletions.
106 changes: 58 additions & 48 deletions t/t1020-subdirectory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,123 +16,133 @@ test_expect_success setup '
cp one original.one &&
cp dir/two original.two
'
HERE=`pwd`
LF='
'

test_expect_success 'update-index and ls-files' '
cd "$HERE" &&
git update-index --add one &&
case "`git ls-files`" in
one) echo pass one ;;
*) echo bad one; exit 1 ;;
esac &&
cd dir &&
git update-index --add two &&
case "`git ls-files`" in
two) echo pass two ;;
*) echo bad two; exit 1 ;;
esac &&
cd .. &&
(
cd dir &&
git update-index --add two &&
case "`git ls-files`" in
two) echo pass two ;;
*) echo bad two; exit 1 ;;
esac
) &&
case "`git ls-files`" in
dir/two"$LF"one) echo pass both ;;
*) echo bad; exit 1 ;;
esac
'

test_expect_success 'cat-file' '
cd "$HERE" &&
two=`git ls-files -s dir/two` &&
two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
echo "$two" &&
git cat-file -p "$two" >actual &&
cmp dir/two actual &&
cd dir &&
git cat-file -p "$two" >actual &&
cmp two actual
(
cd dir &&
git cat-file -p "$two" >actual &&
cmp two actual
)
'
rm -f actual dir/actual

test_expect_success 'diff-files' '
cd "$HERE" &&
echo a >>one &&
echo d >>dir/two &&
case "`git diff-files --name-only`" in
dir/two"$LF"one) echo pass top ;;
*) echo bad top; exit 1 ;;
esac &&
# diff should not omit leading paths
cd dir &&
case "`git diff-files --name-only`" in
dir/two"$LF"one) echo pass subdir ;;
*) echo bad subdir; exit 1 ;;
esac &&
case "`git diff-files --name-only .`" in
dir/two) echo pass subdir limited ;;
*) echo bad subdir limited; exit 1 ;;
esac
(
cd dir &&
case "`git diff-files --name-only`" in
dir/two"$LF"one) echo pass subdir ;;
*) echo bad subdir; exit 1 ;;
esac &&
case "`git diff-files --name-only .`" in
dir/two) echo pass subdir limited ;;
*) echo bad subdir limited; exit 1 ;;
esac
)
'

test_expect_success 'write-tree' '
cd "$HERE" &&
top=`git write-tree` &&
echo $top &&
cd dir &&
sub=`git write-tree` &&
echo $sub &&
test "z$top" = "z$sub"
(
cd dir &&
sub=`git write-tree` &&
echo $sub &&
test "z$top" = "z$sub"
)
'

test_expect_success 'checkout-index' '
cd "$HERE" &&
git checkout-index -f -u one &&
cmp one original.one &&
cd dir &&
git checkout-index -f -u two &&
cmp two ../original.two
(
cd dir &&
git checkout-index -f -u two &&
cmp two ../original.two
)
'

test_expect_success 'read-tree' '
cd "$HERE" &&
rm -f one dir/two &&
tree=`git write-tree` &&
git read-tree --reset -u "$tree" &&
cmp one original.one &&
cmp dir/two original.two &&
cd dir &&
rm -f two &&
git read-tree --reset -u "$tree" &&
cmp two ../original.two &&
cmp ../one ../original.one
(
cd dir &&
rm -f two &&
git read-tree --reset -u "$tree" &&
cmp two ../original.two &&
cmp ../one ../original.one
)
'

test_expect_success 'no file/rev ambiguity check inside .git' '
cd "$HERE" &&
git commit -a -m 1 &&
cd "$HERE"/.git &&
git show -s HEAD
(
cd .git &&
git show -s HEAD
)
'

test_expect_success 'no file/rev ambiguity check inside a bare repo' '
cd "$HERE" &&
git clone -s --bare .git foo.git &&
cd foo.git && GIT_DIR=. git show -s HEAD
(
cd foo.git &&
GIT_DIR=. git show -s HEAD
)
'

# This still does not work as it should...
: test_expect_success 'no file/rev ambiguity check inside a bare repo' '
cd "$HERE" &&
git clone -s --bare .git foo.git &&
cd foo.git && git show -s HEAD
(
cd foo.git &&
git show -s HEAD
)
'

test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
cd "$HERE" &&
rm -fr foo.git &&
git clone -s .git another &&
ln -s another yetanother &&
cd yetanother/.git &&
git show -s HEAD
(
cd yetanother/.git &&
git show -s HEAD
)
'

test_done
77 changes: 50 additions & 27 deletions t/t1302-repo-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,64 @@ test_description='Test repository version check'

. ./test-lib.sh

cat >test.patch <<EOF
diff --git a/test.txt b/test.txt
new file mode 100644
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+123
EOF
test_expect_success 'setup' '
cat >test.patch <<-\EOF &&
diff --git a/test.txt b/test.txt
new file mode 100644
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+123
EOF
test_create_repo "test"
test_create_repo "test2"

GIT_CONFIG=test2/.git/config git config core.repositoryformatversion 99 || exit 1
test_create_repo "test" &&
test_create_repo "test2" &&
GIT_CONFIG=test2/.git/config git config core.repositoryformatversion 99
'

test_expect_success 'gitdir selection on normal repos' '
(test "$(git config core.repositoryformatversion)" = 0 &&
cd test &&
test "$(git config core.repositoryformatversion)" = 0)'
echo 0 >expect &&
git config core.repositoryformatversion >actual &&
(
cd test &&
git config core.repositoryformatversion >../actual2
) &&
test_cmp expect actual &&
test_cmp expect actual2
'

# Make sure it would stop at test2, not trash
test_expect_success 'gitdir selection on unsupported repo' '
(cd test2 &&
test "$(git config core.repositoryformatversion)" = 99)'
# Make sure it would stop at test2, not trash
echo 99 >expect &&
(
cd test2 &&
git config core.repositoryformatversion >../actual
)
test_cmp expect actual
'

test_expect_success 'gitdir not required mode' '
(git apply --stat test.patch &&
cd test && git apply --stat ../test.patch &&
cd ../test2 && git apply --stat ../test.patch)'

test_expect_success 'gitdir required mode on normal repos' '
(git apply --check --index test.patch &&
cd test && git apply --check --index ../test.patch)'
git apply --stat test.patch &&
(
cd test &&
git apply --stat ../test.patch
) &&
(
cd test2 &&
git apply --stat ../test.patch
)
'

test_expect_success 'gitdir required mode on unsupported repo' '
(cd test2 && test_must_fail git apply --check --index ../test.patch)
test_expect_success 'gitdir required mode' '
git apply --check --index test.patch &&
(
cd test &&
git apply --check --index ../test.patch
) &&
(
cd test2 &&
test_must_fail git apply --check --index ../test.patch
)
'

test_done
Loading

0 comments on commit e3f213c

Please sign in to comment.