From a6ca9dfa5cd025353afe21aa4432b3b3663ebef2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:13:21 -0400 Subject: [PATCH 01/12] t/Makefile: stop setting GIT_CONFIG Once upon a time, the setting of GIT_CONFIG in the environment could affect how tests ran. Commit 9c3796f (Fix setting config variables with an alternative GIT_CONFIG, 2006-06-20) unconditionally set GIT_CONFIG in the Makefile when running tests to give us a known starting point. This is insufficient for running the tests outside of the Makefile, however, and 8565d2d (Make tests independent of global config files, 2007-02-15) later set GIT_CONFIG directly in test-lib.sh. At that point the Makefile setting was redundant, but we never removed it. Let's do so now. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/Makefile b/t/Makefile index 2373a04f7a..8fd1a72357 100644 --- a/t/Makefile +++ b/t/Makefile @@ -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)' From 35de3ac1db323976b88949839ff8b2135513e257 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:13:36 -0400 Subject: [PATCH 02/12] t/test-lib: drop redundant unset of GIT_CONFIG This is already handled by the mass GIT_* unsetting added by 95a1d12 (tests: scrub environment of GIT_* variables, 2011-03-15). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/test-lib.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 1531c241c0..625f06e5e5 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -649,7 +649,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 From 221bf985063737240124fe15c328cd125e9d048e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:14:33 -0400 Subject: [PATCH 03/12] t: drop useless sane_unset GIT_* calls Several test scripts manually unset GIT_CONFIG and other GIT_* variables. These are generally taken care of for us by test-lib.sh already. Unsetting these is not only useless, but can be confusing to a reader, who may wonder why some tests in a script unset them and others do not (t0001 is particularly guilty of this inconsistency, probably because many of its tests predate the test-lib.sh environment-cleansing). Note that we cannot always get rid of such unsetting. For example, t9130 can drop the GIT_CONFIG unset, but not the GIT_DIR one, because lib-git-svn.sh sets the latter. And in t1000, we unset GIT_TEMPLATE_DIR, which is explicitly initialized by test-lib.sh. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 15 --------------- t/t9130-git-svn-authors-file.sh | 1 - t/t9400-git-cvsserver-server.sh | 1 - 3 files changed, 17 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 9fb582b192..ddc8160069 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -25,7 +25,6 @@ check_config () { test_expect_success 'plain' ' ( - sane_unset GIT_DIR GIT_WORK_TREE && mkdir plain && cd plain && git init @@ -35,7 +34,6 @@ test_expect_success 'plain' ' 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 +45,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 +62,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 +74,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 && @@ -91,7 +86,6 @@ 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 @@ -104,7 +98,6 @@ test_expect_success 'plain with GIT_WORK_TREE' ' 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 @@ -114,7 +107,6 @@ test_expect_success 'plain bare' ' 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 @@ -128,7 +120,6 @@ test_expect_success 'plain bare with GIT_WORK_TREE' ' test_expect_success 'GIT_DIR bare' ' ( - sane_unset GIT_CONFIG && mkdir git-dir-bare.git && GIT_DIR=git-dir-bare.git git init ) && @@ -138,7 +129,6 @@ test_expect_success 'GIT_DIR bare' ' 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 @@ -149,7 +139,6 @@ test_expect_success 'init --bare' ' test_expect_success 'GIT_DIR non-bare' ' ( - sane_unset GIT_CONFIG && mkdir non-bare && cd non-bare && GIT_DIR=.git git init @@ -160,7 +149,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 ) && @@ -170,7 +158,6 @@ 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 ) @@ -183,8 +170,6 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' test_expect_success 'reinit' ' ( - sane_unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG && - mkdir again && cd again && git init >out1 2>err1 && diff --git a/t/t9130-git-svn-authors-file.sh b/t/t9130-git-svn-authors-file.sh index c3443ceb25..a812783798 100755 --- a/t/t9130-git-svn-authors-file.sh +++ b/t/t9130-git-svn-authors-file.sh @@ -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)" && diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index 3edc4086d8..ed98e64477 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -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" From 3cc6a6f0f7519733deeebe17d7a19a53e9c02028 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:15:24 -0400 Subject: [PATCH 04/12] t: stop using GIT_CONFIG to cross repo boundaries Some tests want to check or set config in another repository. E.g., t1000 creates repositories and makes sure that their core.bare and core.worktree settings are what we expect. We can do this with: GIT_CONFIG=$repo/.git/config git config ... but it better shows the intent to just enter the repository and let "git config" do the normal lookups: (cd $repo && git config ...) In theory, this would cause us to use an extra subshell, but in all such cases, we are actually already in a subshell. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 4 ++-- t/t5701-clone-local.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index ddc8160069..9b05fdf765 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -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" || { diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh index c4903687fb..3c087e907c 100755 --- a/t/t5701-clone-local.sh +++ b/t/t5701-clone-local.sh @@ -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) ' From 551a3e60d1cb9dca37a3a789cf1a4b94074ce6c5 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:15:54 -0400 Subject: [PATCH 05/12] t: prefer "git config --file" to GIT_CONFIG with test_must_fail This lets us get rid of an extra "env" invocation in the middle, and is slightly more readable. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1300-repo-config.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index cd23d07029..e355aa1c97 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -961,15 +961,15 @@ test_expect_success SYMLINKS 'symlinked configuration' ' ' 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' " From f7e87141011fc55f8267ea76d3cc016ee87f9053 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:17:01 -0400 Subject: [PATCH 06/12] t: prefer "git config --file" to GIT_CONFIG Doing: GIT_CONFIG=foo git config ... is equivalent to: git config --file=foo ... The latter is easier to read and slightly less error-prone, because of issues with one-shot variables and shell functions (e.g., you cannot use the former with test_must_fail). Note that we explicitly leave one case in t1300 which checks the same operation on both GIT_CONFIG and "git config --file". They are equivalent in the code these days, but this will make sure it remains so. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1300-repo-config.sh | 20 ++++++++++---------- t/t1302-repo-version.sh | 2 +- t/t7400-submodule-basic.sh | 5 ++--- t/t9130-git-svn-authors-file.sh | 2 +- t/t9154-git-svn-fancy-glob.sh | 6 +++--- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index e355aa1c97..85c6637008 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -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 ' @@ -495,10 +495,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 ) ' @@ -510,8 +510,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 ' @@ -942,11 +942,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 && @@ -954,8 +954,8 @@ 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 ' diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh index 0e47662406..0d9388afc4 100755 --- a/t/t1302-repo-version.sh +++ b/t/t1302-repo-version.sh @@ -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' ' diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index c28e8d8ada..7c88245031 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -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 ' diff --git a/t/t9130-git-svn-authors-file.sh b/t/t9130-git-svn-authors-file.sh index a812783798..c44de267a1 100755 --- a/t/t9130-git-svn-authors-file.sh +++ b/t/t9130-git-svn-authors-file.sh @@ -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' ' diff --git a/t/t9154-git-svn-fancy-glob.sh b/t/t9154-git-svn-fancy-glob.sh index b780e0efe3..a0150f057d 100755 --- a/t/t9154-git-svn-fancy-glob.sh +++ b/t/t9154-git-svn-fancy-glob.sh @@ -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 && From 3d06c5f19daf6710d99b6e4c7c0d097c8ce528fc Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:17:15 -0400 Subject: [PATCH 07/12] t0001: make symlink reinit test more careful In the final test of t0001, we have a repo whose .git is a symlink to a directory "here", and we use "--separate-git-dir" to migrate that to a .git file pointing to a different directory. We check that the data is migrated to the new directory and that .git looks like a git-file. We also check that "here" is not a directory, which is slightly misleading. It should not be a directory, but neither should it be gone. It is the actual resting place of the git-file, and .git remains a symlink to it. Let's check that more explicitly, both to make our test more robust, and to make further cleanups in this area more obvious. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 9b05fdf765..5245711986 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -402,8 +402,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 -d realgitdir/refs ' test_done From 633734d4a13ace930b34c83d37b4e8a22ccf5a3b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:17:35 -0400 Subject: [PATCH 08/12] t0001: use test_path_is_* t0001 predates the test_path_is_* helpers, and uses "test -f" and "test -d" directly. Using the helpers provides better debugging output, and are a little more robust. As opposed to "! test -d", test_path_is_missing will actually makes sure the path does not exist at all. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 5245711986..fdcf4b3ba5 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -199,13 +199,13 @@ test_expect_success 'init with --template (blank)' ' cd template-plain && git init ) && - test -f template-plain/.git/info/exclude && + test_path_is_file template-plain/.git/info/exclude && ( mkdir template-blank && cd template-blank && git init --template= ) && - ! test -f template-blank/.git/info/exclude + test_path_is_missing template-blank/.git/info/exclude ' test_expect_success 'init with init.templatedir set' ' @@ -263,7 +263,7 @@ test_expect_success 'init creates a new directory' ' rm -fr newdir && ( git init newdir && - test -d newdir/.git/refs + test_path_is_dir newdir/.git/refs ) ' @@ -271,7 +271,7 @@ test_expect_success 'init creates a new bare directory' ' rm -fr newdir && ( git init --bare newdir && - test -d newdir/refs + test_path_is_dir newdir/refs ) ' @@ -280,7 +280,7 @@ test_expect_success 'init recreates a directory' ' ( mkdir newdir && git init newdir && - test -d newdir/.git/refs + test_path_is_dir newdir/.git/refs ) ' @@ -289,14 +289,14 @@ test_expect_success 'init recreates a new bare directory' ' ( mkdir newdir && git init --bare newdir && - test -d newdir/refs + 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)' ' @@ -306,7 +306,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 && @@ -319,7 +319,7 @@ test_expect_success 'init notices EEXIST (1)' ' ( >newdir && test_must_fail git init newdir && - test -f newdir + test_path_is_file newdir ) ' @@ -329,7 +329,7 @@ test_expect_success 'init notices EEXIST (2)' ' mkdir newdir && >newdir/a test_must_fail git init newdir/a/b && - test -f newdir/a + test_path_is_file newdir/a ) ' @@ -345,15 +345,15 @@ test_expect_success POSIXPERM,SANITY 'init notices EPERM' ' 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' ' @@ -361,7 +361,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' ' @@ -375,8 +375,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' ' @@ -388,7 +388,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' ' @@ -403,7 +403,7 @@ test_expect_success SYMLINKS 're-init to move gitdir symlink' ' echo "gitdir: `pwd`/realgitdir" >expected && test_cmp expected newdir/.git && test_cmp expected newdir/here && - test -d realgitdir/refs + test_path_is_dir realgitdir/refs ' test_done From 2a472410cbb481c56ee207dbda2ee99d158c0f48 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:18:12 -0400 Subject: [PATCH 09/12] t0001: use test_config_global We hand-set several config options using : git config -f $HOME/.gitconfig ... Instead, we can use "test_config_global". Not only is this more readable, but it cleans up for us so that subsequent tests aren't polluted by our settings. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index fdcf4b3ba5..9515da3024 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -211,9 +211,8 @@ test_expect_success 'init with --template (blank)' ' 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 && @@ -225,10 +224,9 @@ test_expect_success 'init with init.templatedir set' ' ' test_expect_success 'init --bare/--shared overrides system/global config' ' + test_config_global core.bare false && + test_config_global core.sharedRepository 0640 && ( - 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 @@ -239,9 +237,8 @@ test_expect_success 'init --bare/--shared overrides system/global config' ' ' test_expect_success 'init honors global core.sharedRepository' ' + test_config_global core.sharedRepository 0666 && ( - test_config="$HOME"/.gitconfig && - git config -f "$test_config" core.sharedRepository 0666 && mkdir shared-honor-global && cd shared-honor-global && git init From 0981140fcc2fe33c37da87802b95e01af2a94add Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:19:50 -0400 Subject: [PATCH 10/12] t0001: use test_must_fail We've hand-rolled several "if" statements looking for failures. We can use test_must_fail here, which is shorter and more robust. Note that we modify the commands slightly (to use "git init foo" rather than "cd foo && git init") to avoid dealing with a subshell, but this should not affect the outcome. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 9515da3024..4560bba559 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -85,15 +85,8 @@ test_expect_failure 'plain nested in bare through aliased command' ' ' test_expect_success 'plain with GIT_WORK_TREE' ' - if ( - 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' ' @@ -106,15 +99,10 @@ test_expect_success 'plain bare' ' ' test_expect_success 'plain bare with GIT_WORK_TREE' ' - if ( - 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' ' @@ -156,15 +144,11 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' ' ' test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' - - if ( - 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' ' From 99e1c7367f34ecc69ce46263309610b66d027d88 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:21:25 -0400 Subject: [PATCH 11/12] t0001: drop useless subshells Many tests use subshells, but don't actually change the shell environment. They were probably cargo-culted from earlier tests which did need subshells. Drop the useless ones. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 61 ++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 4560bba559..d8c00b44cc 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -106,11 +106,8 @@ test_expect_success 'plain bare with GIT_WORK_TREE' ' ' test_expect_success 'GIT_DIR bare' ' - - ( - 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 ' @@ -242,36 +239,28 @@ test_expect_success 'init rejects insanely long --template' ' test_expect_success 'init creates a new directory' ' rm -fr newdir && - ( - git init newdir && - test_path_is_dir 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_path_is_dir 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_path_is_dir 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_path_is_dir newdir/refs - ) + mkdir newdir && + git init --bare newdir && + test_path_is_dir newdir/refs ' test_expect_success 'init creates a new deep directory' ' @@ -297,30 +286,24 @@ 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_path_is_file 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_path_is_file 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' ' From 410c3428ed42bc0978e2917236e95cd5f860864f Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Mar 2014 19:23:06 -0400 Subject: [PATCH 12/12] t0001: drop subshells just for "cd" Many tests do something like: ( mkdir foo && cd foo && git init ) You can do the same these days with "git init foo", which makes the tests shorter and simpler to read. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 56 ++++++++----------------------------------------- 1 file changed, 9 insertions(+), 47 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index d8c00b44cc..bbc9cb60dd 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -24,11 +24,7 @@ check_config () { } test_expect_success 'plain' ' - ( - mkdir plain && - cd plain && - git init - ) && + git init plain && check_config plain/.git false unset ' @@ -90,11 +86,7 @@ test_expect_success 'plain with GIT_WORK_TREE' ' ' test_expect_success 'plain bare' ' - ( - mkdir plain-bare-1 && - cd plain-bare-1 && - git --bare init - ) && + git --bare init plain-bare-1 && check_config plain-bare-1 true unset ' @@ -112,12 +104,7 @@ test_expect_success 'GIT_DIR bare' ' ' test_expect_success 'init --bare' ' - - ( - mkdir init-bare.git && - cd init-bare.git && - git init --bare - ) && + git init --bare init-bare.git && check_config init-bare.git true unset ' @@ -166,26 +153,14 @@ 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 - ) && + git init template-plain && test_path_is_file template-plain/.git/info/exclude && - ( - mkdir template-blank && - cd template-blank && - git init --template= - ) && + git init --template= template-blank && test_path_is_missing template-blank/.git/info/exclude ' @@ -207,11 +182,7 @@ test_expect_success 'init with init.templatedir set' ' test_expect_success 'init --bare/--shared overrides system/global config' ' test_config_global core.bare false && test_config_global core.sharedRepository 0640 && - ( - mkdir init-bare-shared-override && - cd init-bare-shared-override && - git init --bare --shared=0666 - ) && + 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` @@ -219,22 +190,13 @@ test_expect_success 'init --bare/--shared overrides system/global config' ' test_expect_success 'init honors global core.sharedRepository' ' test_config_global core.sharedRepository 0666 && - ( - mkdir shared-honor-global && - cd shared-honor-global && - git init - ) && + 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' '