Merge branch 'jk/tests-cleanup'

* jk/tests-cleanup:
  t0001: drop subshells just for "cd"
  t0001: drop useless subshells
  t0001: use test_must_fail
  t0001: use test_config_global
  t0001: use test_path_is_*
  t0001: make symlink reinit test more careful
  t: prefer "git config --file" to GIT_CONFIG
  t: prefer "git config --file" to GIT_CONFIG with test_must_fail
  t: stop using GIT_CONFIG to cross repo boundaries
  t: drop useless sane_unset GIT_* calls
  t/test-lib: drop redundant unset of GIT_CONFIG
  t/Makefile: stop setting GIT_CONFIG
This commit is contained in:
Junio C Hamano 2014-03-31 16:31:17 -07:00
Родитель 00d4ff1a69 410c3428ed
Коммит ad4d8911f8
10 изменённых файлов: 87 добавлений и 180 удалений

Просмотреть файл

@ -36,11 +36,11 @@ test: pre-clean $(TEST_LINT)
$(MAKE) aggregate-results-and-cleanup
prove: pre-clean $(TEST_LINT)
@echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
@echo "*** prove ***"; $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
$(MAKE) clean-except-prove-cache
$(T):
@echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
@echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
pre-clean:
$(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'

Просмотреть файл

@ -12,8 +12,8 @@ check_config () {
echo "expected a directory $1, a file $1/config and $1/refs"
return 1
fi
bare=$(GIT_CONFIG="$1/config" git config --bool core.bare)
worktree=$(GIT_CONFIG="$1/config" git config core.worktree) ||
bare=$(cd "$1" && git config --bool core.bare)
worktree=$(cd "$1" && git config core.worktree) ||
worktree=unset
test "$bare" = "$2" && test "$worktree" = "$3" || {
@ -24,18 +24,12 @@ check_config () {
}
test_expect_success 'plain' '
(
sane_unset GIT_DIR GIT_WORK_TREE &&
mkdir plain &&
cd plain &&
git init
) &&
git init plain &&
check_config plain/.git false unset
'
test_expect_success 'plain nested in bare' '
(
sane_unset GIT_DIR GIT_WORK_TREE &&
git init --bare bare-ancestor.git &&
cd bare-ancestor.git &&
mkdir plain-nested &&
@ -47,7 +41,6 @@ test_expect_success 'plain nested in bare' '
test_expect_success 'plain through aliased command, outside any git repo' '
(
sane_unset GIT_DIR GIT_WORK_TREE &&
HOME=$(pwd)/alias-config &&
export HOME &&
mkdir alias-config &&
@ -65,7 +58,6 @@ test_expect_success 'plain through aliased command, outside any git repo' '
test_expect_failure 'plain nested through aliased command' '
(
sane_unset GIT_DIR GIT_WORK_TREE &&
git init plain-ancestor-aliased &&
cd plain-ancestor-aliased &&
echo "[alias] aliasedinit = init" >>.git/config &&
@ -78,7 +70,6 @@ test_expect_failure 'plain nested through aliased command' '
test_expect_failure 'plain nested in bare through aliased command' '
(
sane_unset GIT_DIR GIT_WORK_TREE &&
git init --bare bare-ancestor-aliased.git &&
cd bare-ancestor-aliased.git &&
echo "[alias] aliasedinit = init" >>config &&
@ -90,66 +81,36 @@ test_expect_failure 'plain nested in bare through aliased command' '
'
test_expect_success 'plain with GIT_WORK_TREE' '
if (
sane_unset GIT_DIR &&
mkdir plain-wt &&
cd plain-wt &&
GIT_WORK_TREE=$(pwd) git init
)
then
echo Should have failed -- GIT_WORK_TREE should not be used
false
fi
mkdir plain-wt &&
test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt
'
test_expect_success 'plain bare' '
(
sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
mkdir plain-bare-1 &&
cd plain-bare-1 &&
git --bare init
) &&
git --bare init plain-bare-1 &&
check_config plain-bare-1 true unset
'
test_expect_success 'plain bare with GIT_WORK_TREE' '
if (
sane_unset GIT_DIR GIT_CONFIG &&
mkdir plain-bare-2 &&
cd plain-bare-2 &&
GIT_WORK_TREE=$(pwd) git --bare init
)
then
echo Should have failed -- GIT_WORK_TREE should not be used
false
fi
mkdir plain-bare-2 &&
test_must_fail \
env GIT_WORK_TREE="$(pwd)/plain-bare-2" \
git --bare init plain-bare-2
'
test_expect_success 'GIT_DIR bare' '
(
sane_unset GIT_CONFIG &&
mkdir git-dir-bare.git &&
GIT_DIR=git-dir-bare.git git init
) &&
mkdir git-dir-bare.git &&
GIT_DIR=git-dir-bare.git git init &&
check_config git-dir-bare.git true unset
'
test_expect_success 'init --bare' '
(
sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
mkdir init-bare.git &&
cd init-bare.git &&
git init --bare
) &&
git init --bare init-bare.git &&
check_config init-bare.git true unset
'
test_expect_success 'GIT_DIR non-bare' '
(
sane_unset GIT_CONFIG &&
mkdir non-bare &&
cd non-bare &&
GIT_DIR=.git git init
@ -160,7 +121,6 @@ test_expect_success 'GIT_DIR non-bare' '
test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
(
sane_unset GIT_CONFIG &&
mkdir git-dir-wt-1.git &&
GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
) &&
@ -168,23 +128,16 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
'
test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
if (
sane_unset GIT_CONFIG &&
mkdir git-dir-wt-2.git &&
GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init
)
then
echo Should have failed -- --bare should not be used
false
fi
mkdir git-dir-wt-2.git &&
test_must_fail env \
GIT_WORK_TREE="$(pwd)" \
GIT_DIR=git-dir-wt-2.git \
git --bare init
'
test_expect_success 'reinit' '
(
sane_unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG &&
mkdir again &&
cd again &&
git init >out1 2>err1 &&
@ -200,35 +153,22 @@ test_expect_success 'reinit' '
test_expect_success 'init with --template' '
mkdir template-source &&
echo content >template-source/file &&
(
mkdir template-custom &&
cd template-custom &&
git init --template=../template-source
) &&
git init --template=../template-source template-custom &&
test_cmp template-source/file template-custom/.git/file
'
test_expect_success 'init with --template (blank)' '
(
mkdir template-plain &&
cd template-plain &&
git init
) &&
test -f template-plain/.git/info/exclude &&
(
mkdir template-blank &&
cd template-blank &&
git init --template=
) &&
! test -f template-blank/.git/info/exclude
git init template-plain &&
test_path_is_file template-plain/.git/info/exclude &&
git init --template= template-blank &&
test_path_is_missing template-blank/.git/info/exclude
'
test_expect_success 'init with init.templatedir set' '
mkdir templatedir-source &&
echo Content >templatedir-source/file &&
test_config_global init.templatedir "${HOME}/templatedir-source" &&
(
test_config="${HOME}/.gitconfig" &&
git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" &&
mkdir templatedir-set &&
cd templatedir-set &&
sane_unset GIT_TEMPLATE_DIR &&
@ -240,78 +180,55 @@ test_expect_success 'init with init.templatedir set' '
'
test_expect_success 'init --bare/--shared overrides system/global config' '
(
test_config="$HOME"/.gitconfig &&
git config -f "$test_config" core.bare false &&
git config -f "$test_config" core.sharedRepository 0640 &&
mkdir init-bare-shared-override &&
cd init-bare-shared-override &&
git init --bare --shared=0666
) &&
test_config_global core.bare false &&
test_config_global core.sharedRepository 0640 &&
git init --bare --shared=0666 init-bare-shared-override &&
check_config init-bare-shared-override true unset &&
test x0666 = \
x`git config -f init-bare-shared-override/config core.sharedRepository`
'
test_expect_success 'init honors global core.sharedRepository' '
(
test_config="$HOME"/.gitconfig &&
git config -f "$test_config" core.sharedRepository 0666 &&
mkdir shared-honor-global &&
cd shared-honor-global &&
git init
) &&
test_config_global core.sharedRepository 0666 &&
git init shared-honor-global &&
test x0666 = \
x`git config -f shared-honor-global/.git/config core.sharedRepository`
'
test_expect_success 'init rejects insanely long --template' '
(
insane=$(printf "x%09999dx" 1) &&
mkdir test &&
cd test &&
test_must_fail git init --template=$insane
)
test_must_fail git init --template=$(printf "x%09999dx" 1) test
'
test_expect_success 'init creates a new directory' '
rm -fr newdir &&
(
git init newdir &&
test -d newdir/.git/refs
)
git init newdir &&
test_path_is_dir newdir/.git/refs
'
test_expect_success 'init creates a new bare directory' '
rm -fr newdir &&
(
git init --bare newdir &&
test -d newdir/refs
)
git init --bare newdir &&
test_path_is_dir newdir/refs
'
test_expect_success 'init recreates a directory' '
rm -fr newdir &&
(
mkdir newdir &&
git init newdir &&
test -d newdir/.git/refs
)
mkdir newdir &&
git init newdir &&
test_path_is_dir newdir/.git/refs
'
test_expect_success 'init recreates a new bare directory' '
rm -fr newdir &&
(
mkdir newdir &&
git init --bare newdir &&
test -d newdir/refs
)
mkdir newdir &&
git init --bare newdir &&
test_path_is_dir newdir/refs
'
test_expect_success 'init creates a new deep directory' '
rm -fr newdir &&
git init newdir/a/b/c &&
test -d newdir/a/b/c/.git/refs
test_path_is_dir newdir/a/b/c/.git/refs
'
test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' '
@ -321,7 +238,7 @@ test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shar
# the repository itself should follow "shared"
umask 002 &&
git init --bare --shared=0660 newdir/a/b/c &&
test -d newdir/a/b/c/refs &&
test_path_is_dir newdir/a/b/c/refs &&
ls -ld newdir/a newdir/a/b > lsab.out &&
! grep -v "^drwxrw[sx]r-x" lsab.out &&
ls -ld newdir/a/b/c > lsc.out &&
@ -331,44 +248,38 @@ test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shar
test_expect_success 'init notices EEXIST (1)' '
rm -fr newdir &&
(
>newdir &&
test_must_fail git init newdir &&
test -f newdir
)
>newdir &&
test_must_fail git init newdir &&
test_path_is_file newdir
'
test_expect_success 'init notices EEXIST (2)' '
rm -fr newdir &&
(
mkdir newdir &&
>newdir/a
test_must_fail git init newdir/a/b &&
test -f newdir/a
)
mkdir newdir &&
>newdir/a &&
test_must_fail git init newdir/a/b &&
test_path_is_file newdir/a
'
test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
rm -fr newdir &&
(
mkdir newdir &&
chmod -w newdir &&
test_must_fail git init newdir/a/b
)
mkdir newdir &&
chmod -w newdir &&
test_must_fail git init newdir/a/b
'
test_expect_success 'init creates a new bare directory with global --bare' '
rm -rf newdir &&
git --bare init newdir &&
test -d newdir/refs
test_path_is_dir newdir/refs
'
test_expect_success 'init prefers command line to GIT_DIR' '
rm -rf newdir &&
mkdir otherdir &&
GIT_DIR=otherdir git --bare init newdir &&
test -d newdir/refs &&
! test -d otherdir/refs
test_path_is_dir newdir/refs &&
test_path_is_missing otherdir/refs
'
test_expect_success 'init with separate gitdir' '
@ -376,7 +287,7 @@ test_expect_success 'init with separate gitdir' '
git init --separate-git-dir realgitdir newdir &&
echo "gitdir: `pwd`/realgitdir" >expected &&
test_cmp expected newdir/.git &&
test -d realgitdir/refs
test_path_is_dir realgitdir/refs
'
test_expect_success 're-init on .git file' '
@ -390,8 +301,8 @@ test_expect_success 're-init to update git link' '
) &&
echo "gitdir: `pwd`/surrealgitdir" >expected &&
test_cmp expected newdir/.git &&
test -d surrealgitdir/refs &&
! test -d realgitdir/refs
test_path_is_dir surrealgitdir/refs &&
test_path_is_missing realgitdir/refs
'
test_expect_success 're-init to move gitdir' '
@ -403,7 +314,7 @@ test_expect_success 're-init to move gitdir' '
) &&
echo "gitdir: `pwd`/realgitdir" >expected &&
test_cmp expected newdir/.git &&
test -d realgitdir/refs
test_path_is_dir realgitdir/refs
'
test_expect_success SYMLINKS 're-init to move gitdir symlink' '
@ -417,8 +328,8 @@ test_expect_success SYMLINKS 're-init to move gitdir symlink' '
) &&
echo "gitdir: `pwd`/realgitdir" >expected &&
test_cmp expected newdir/.git &&
test -d realgitdir/refs &&
! test -d newdir/here
test_cmp expected newdir/here &&
test_path_is_dir realgitdir/refs
'
test_done

Просмотреть файл

@ -461,7 +461,7 @@ test_expect_success 'new variable inserts into proper section' '
test_cmp expect .git/config
'
test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' '
test_expect_success 'alternative --file (non-existing file should fail)' '
test_must_fail git config --file non-existing-config -l
'
@ -508,10 +508,10 @@ test_expect_success 'refer config from subdirectory' '
'
test_expect_success 'refer config from subdirectory via GIT_CONFIG' '
test_expect_success 'refer config from subdirectory via --file' '
(
cd x &&
GIT_CONFIG=../other-config git config --get ein.bahn >actual &&
git config --file=../other-config --get ein.bahn >actual &&
test_cmp expect actual
)
'
@ -523,8 +523,8 @@ cat > expect << EOF
park = ausweis
EOF
test_expect_success '--set in alternative GIT_CONFIG' '
GIT_CONFIG=other-config git config anwohner.park ausweis &&
test_expect_success '--set in alternative file' '
git config --file=other-config anwohner.park ausweis &&
test_cmp expect other-config
'
@ -955,11 +955,11 @@ test_expect_success 'inner whitespace kept verbatim' '
test_expect_success SYMLINKS 'symlinked configuration' '
ln -s notyet myconfig &&
GIT_CONFIG=myconfig git config test.frotz nitfol &&
git config --file=myconfig test.frotz nitfol &&
test -h myconfig &&
test -f notyet &&
test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
test "z$(git config --file=notyet test.frotz)" = znitfol &&
git config --file=myconfig test.xyzzy rezrov &&
test -h myconfig &&
test -f notyet &&
cat >expect <<-\EOF &&
@ -967,22 +967,22 @@ test_expect_success SYMLINKS 'symlinked configuration' '
rezrov
EOF
{
GIT_CONFIG=notyet git config test.frotz &&
GIT_CONFIG=notyet git config test.xyzzy
git config --file=notyet test.frotz &&
git config --file=notyet test.xyzzy
} >actual &&
test_cmp expect actual
'
test_expect_success 'nonexistent configuration' '
test_must_fail env GIT_CONFIG=doesnotexist git config --list &&
test_must_fail env GIT_CONFIG=doesnotexist git config test.xyzzy
test_must_fail git config --file=doesnotexist --list &&
test_must_fail git config --file=doesnotexist test.xyzzy
'
test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
ln -s doesnotexist linktonada &&
ln -s linktonada linktolinktonada &&
test_must_fail env GIT_CONFIG=linktonada git config --list &&
test_must_fail env GIT_CONFIG=linktolinktonada git config --list
test_must_fail git config --file=linktonada --list &&
test_must_fail git config --file=linktolinktonada --list
'
test_expect_success 'check split_cmdline return' "

Просмотреть файл

@ -19,7 +19,7 @@ test_expect_success 'setup' '
test_create_repo "test" &&
test_create_repo "test2" &&
GIT_CONFIG=test2/.git/config git config core.repositoryformatversion 99
git config --file=test2/.git/config core.repositoryformatversion 99
'
test_expect_success 'gitdir selection on normal repos' '

Просмотреть файл

@ -12,8 +12,8 @@ test_expect_success 'preparing origin repository' '
: >file && git add . && git commit -m1 &&
git clone --bare . a.git &&
git clone --bare . x &&
test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true &&
test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true &&
test "$(cd a.git && git config --bool core.bare)" = true &&
test "$(cd x && git config --bool core.bare)" = true &&
git bundle create b1.bundle --all &&
git bundle create b2.bundle master &&
mkdir dir &&
@ -24,7 +24,7 @@ test_expect_success 'preparing origin repository' '
test_expect_success 'local clone without .git suffix' '
git clone -l -s a b &&
(cd b &&
test "$(GIT_CONFIG=.git/config git config --bool core.bare)" = false &&
test "$(git config --bool core.bare)" = false &&
git fetch)
'

Просмотреть файл

@ -249,8 +249,7 @@ test_expect_success 'submodule add in subdirectory with relative path should fai
'
test_expect_success 'setup - add an example entry to .gitmodules' '
GIT_CONFIG=.gitmodules \
git config submodule.example.url git://example.com/init.git
git config --file=.gitmodules submodule.example.url git://example.com/init.git
'
test_expect_success 'status should fail for unmapped paths' '
@ -264,7 +263,7 @@ test_expect_success 'setup - map path in .gitmodules' '
path = init
EOF
GIT_CONFIG=.gitmodules git config submodule.example.path init &&
git config --file=.gitmodules submodule.example.path init &&
test_cmp expect .gitmodules
'

Просмотреть файл

@ -67,7 +67,7 @@ test_expect_success 'fetch fails on ee' '
'
tmp_config_get () {
GIT_CONFIG=.git/svn/.metadata git config --get "$1"
git config --file=.git/svn/.metadata --get "$1"
}
test_expect_success 'failure happened without negative side effects' '
@ -97,7 +97,6 @@ test_expect_success 'fresh clone with svn.authors-file in config' '
test x = x"$(git config svn.authorsfile)" &&
test_config="$HOME"/.gitconfig &&
sane_unset GIT_DIR &&
sane_unset GIT_CONFIG &&
git config --global \
svn.authorsfile "$HOME"/svn-authors &&
test x"$HOME"/svn-authors = x"$(git config svn.authorsfile)" &&

Просмотреть файл

@ -22,7 +22,7 @@ test_expect_success 'add red branch' "
"
test_expect_success 'add gre branch' "
GIT_CONFIG=.git/svn/.metadata git config --unset svn-remote.svn.branches-maxRev &&
git config --file=.git/svn/.metadata --unset svn-remote.svn.branches-maxRev &&
git config svn-remote.svn.branches 'branches/{red,gre}:refs/remotes/*' &&
git svn fetch &&
git rev-parse refs/remotes/red &&
@ -31,7 +31,7 @@ test_expect_success 'add gre branch' "
"
test_expect_success 'add green branch' "
GIT_CONFIG=.git/svn/.metadata git config --unset svn-remote.svn.branches-maxRev &&
git config --file=.git/svn/.metadata --unset svn-remote.svn.branches-maxRev &&
git config svn-remote.svn.branches 'branches/{red,green}:refs/remotes/*' &&
git svn fetch &&
git rev-parse refs/remotes/red &&
@ -40,7 +40,7 @@ test_expect_success 'add green branch' "
"
test_expect_success 'add all branches' "
GIT_CONFIG=.git/svn/.metadata git config --unset svn-remote.svn.branches-maxRev &&
git config --file=.git/svn/.metadata --unset svn-remote.svn.branches-maxRev &&
git config svn-remote.svn.branches 'branches/*:refs/remotes/*' &&
git svn fetch &&
git rev-parse refs/remotes/red &&

Просмотреть файл

@ -25,7 +25,6 @@ perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
test_done
}
unset GIT_DIR GIT_CONFIG
WORKDIR=$(pwd)
SERVERDIR=$(pwd)/gitcvs.git
git_config="$SERVERDIR/config"

Просмотреть файл

@ -655,7 +655,6 @@ else # normal case, use ../bin-wrappers only unless $with_dashes:
fi
fi
GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt
unset GIT_CONFIG
GIT_CONFIG_NOSYSTEM=1
GIT_ATTR_NOSYSTEM=1
export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM