t1500-rev-parse has many tests which change directories and leak environment variables. This makes it difficult to add new tests without minding the environment variables and current directory. Each test is now setup, executed, and cleaned up without leaving anything behind. Test comparisons been converted to use test_cmp or test_stdout. Signed-off-by: Michael Rappazzo <rappazzo@xxxxxxxxx> --- t/t1500-rev-parse.sh | 355 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 295 insertions(+), 60 deletions(-) diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh index 48ee077..e2c2a06 100755 --- a/t/t1500-rev-parse.sh +++ b/t/t1500-rev-parse.sh @@ -3,85 +3,320 @@ test_description='test git rev-parse' . ./test-lib.sh -test_rev_parse() { - name=$1 - shift +test_expect_success 'toplevel: is-bare-repository' ' + test_stdout false git rev-parse --is-bare-repository +' - test_expect_success "$name: is-bare-repository" \ - "test '$1' = \"\$(git rev-parse --is-bare-repository)\"" - shift - [ $# -eq 0 ] && return +test_expect_success 'toplevel: is-inside-git-dir' ' + test_stdout false git rev-parse --is-inside-git-dir +' - test_expect_success "$name: is-inside-git-dir" \ - "test '$1' = \"\$(git rev-parse --is-inside-git-dir)\"" - shift - [ $# -eq 0 ] && return +test_expect_success 'toplevel: is-inside-work-tree' ' + test_stdout true git rev-parse --is-inside-work-tree +' - test_expect_success "$name: is-inside-work-tree" \ - "test '$1' = \"\$(git rev-parse --is-inside-work-tree)\"" - shift - [ $# -eq 0 ] && return +test_expect_success 'toplevel: prefix' ' + test_stdout "" git rev-parse --show-prefix +' - test_expect_success "$name: prefix" \ - "test '$1' = \"\$(git rev-parse --show-prefix)\"" - shift - [ $# -eq 0 ] && return +test_expect_success 'toplevel: git-dir' ' + test_stdout .git git rev-parse --git-dir +' - test_expect_success "$name: git-dir" \ - "test '$1' = \"\$(git rev-parse --git-dir)\"" - shift - [ $# -eq 0 ] && return -} +test_expect_success '.git/: is-bare-repository' ' + test_stdout false git -C .git rev-parse --is-bare-repository +' -# label is-bare is-inside-git is-inside-work prefix git-dir +test_expect_success '.git/: is-inside-git-dir' ' + test_stdout true git -C .git rev-parse --is-inside-git-dir +' -ROOT=$(pwd) +test_expect_success '.git/: is-inside-work-tree' ' + test_stdout false git -C .git rev-parse --is-inside-work-tree +' -test_rev_parse toplevel false false true '' .git +test_expect_success '.git/: prefix' ' + test_stdout "" git -C .git rev-parse --show-prefix +' -cd .git || exit 1 -test_rev_parse .git/ false true false '' . -cd objects || exit 1 -test_rev_parse .git/objects/ false true false '' "$ROOT/.git" -cd ../.. || exit 1 +test_expect_success '.git/: git-dir' ' + test_stdout . git -C .git rev-parse --git-dir +' -mkdir -p sub/dir || exit 1 -cd sub/dir || exit 1 -test_rev_parse subdirectory false false true sub/dir/ "$ROOT/.git" -cd ../.. || exit 1 +test_expect_success '.git/objects/: is-bare-repository' ' + test_stdout false git -C .git/objects rev-parse --is-bare-repository +' -git config core.bare true -test_rev_parse 'core.bare = true' true false false +test_expect_success '.git/objects/: is-inside-git-dir' ' + test_stdout true git -C .git/objects rev-parse --is-inside-git-dir +' -git config --unset core.bare -test_rev_parse 'core.bare undefined' false false true +test_expect_success '.git/objects/: is-inside-work-tree' ' + test_stdout false git -C .git/objects rev-parse --is-inside-work-tree +' -mkdir work || exit 1 -cd work || exit 1 -GIT_DIR=../.git -GIT_CONFIG="$(pwd)"/../.git/config -export GIT_DIR GIT_CONFIG +test_expect_success '.git/objects/: prefix' ' + test_stdout "" git -C .git/objects rev-parse --show-prefix +' -git config core.bare false -test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true '' +test_expect_success '.git/objects/: git-dir' ' + echo $(pwd)/.git >expect && + git -C .git/objects rev-parse --git-dir >actual && + test_cmp expect actual +' -git config core.bare true -test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false '' +test_expect_success 'subdirectory: is-bare-repository' ' + mkdir -p sub/dir && + test_when_finished "rm -rf sub" && + test_stdout false git -C sub/dir rev-parse --is-bare-repository +' -git config --unset core.bare -test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true '' +test_expect_success 'subdirectory: is-inside-git-dir' ' + mkdir -p sub/dir && + test_when_finished "rm -rf sub" && + test_stdout false git -C sub/dir rev-parse --is-inside-git-dir +' -mv ../.git ../repo.git || exit 1 -GIT_DIR=../repo.git -GIT_CONFIG="$(pwd)"/../repo.git/config +test_expect_success 'subdirectory: is-inside-work-tree' ' + mkdir -p sub/dir && + test_when_finished "rm -rf sub" && + test_stdout true git -C sub/dir rev-parse --is-inside-work-tree +' -git config core.bare false -test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true '' +test_expect_success 'subdirectory: prefix' ' + mkdir -p sub/dir && + test_when_finished "rm -rf sub" && + test sub/dir/ = "$(git -C sub/dir rev-parse --show-prefix)" +' -git config core.bare true -test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false '' +test_expect_success 'subdirectory: git-dir' ' + mkdir -p sub/dir && + test_when_finished "rm -rf sub" && + echo $(pwd)/.git >expect && + git -C sub/dir rev-parse --git-dir >actual && + test_cmp expect actual +' -git config --unset core.bare -test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true '' +test_expect_success 'core.bare = true: is-bare-repository' ' + test_config core.bare true && + test_stdout true git rev-parse --is-bare-repository +' + +test_expect_success 'core.bare = true: is-inside-git-dir' ' + test_config core.bare true && + test_stdout false git rev-parse --is-inside-git-dir +' + +test_expect_success 'core.bare = true: is-inside-work-tree' ' + test_config core.bare true && + test_stdout false git rev-parse --is-inside-work-tree +' + +test_expect_success 'core.bare undefined: is-bare-repository' ' + test_config core.bare "" && + test_stdout false git rev-parse --is-bare-repository +' + +test_expect_success 'core.bare undefined: is-inside-git-dir' ' + test_config core.bare "" && + test_stdout false git rev-parse --is-inside-git-dir +' + +test_expect_success 'core.bare undefined: is-inside-work-tree' ' + test_config core.bare "" && + test_stdout true git rev-parse --is-inside-work-tree +' + +test_expect_success 'GIT_DIR=../.git, core.bare = false: is-bare-repository' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bare false && + GIT_DIR=../.git test_stdout false git -C work rev-parse --is-bare-repository +' + +test_expect_success 'GIT_DIR=../.git, core.bare = false: is-inside-git-dir' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bare false && + GIT_DIR=../.git test_stdout false git -C work rev-parse --is-inside-git-dir +' + +test_expect_success 'GIT_DIR=../.git, core.bare = false: is-inside-work-tree' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bare false && + GIT_DIR=../.git test_stdout true git -C work rev-parse --is-inside-work-tree +' + +test_expect_success 'GIT_DIR=../.git, core.bare = false: prefix' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bare false && + GIT_DIR=../.git test_stdout "" git -C work rev-parse --show-prefix >actual +' + +test_expect_success 'GIT_DIR=../.git, core.bare = true: is-bare-repository' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bare true && + GIT_DIR=../.git test_stdout true git -C work rev-parse --is-bare-repository +' + +test_expect_success 'GIT_DIR=../.git, core.bare = true: is-inside-git-dir' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bare true && + GIT_DIR=../.git test_stdout false git -C work rev-parse --is-inside-git-dir +' + +test_expect_success 'GIT_DIR=../.git, core.bare = true: is-inside-work-tree' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bare true && + GIT_DIR=../.git test_stdout false git -C work rev-parse --is-inside-work-tree +' + +test_expect_success 'GIT_DIR=../.git, core.bare = true: prefix' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bare true && + GIT_DIR=../.git test_stdout "" git -C work rev-parse --show-prefix +' + +test_expect_success 'GIT_DIR=../.git, core.bare undefined: is-bare-repository' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bar = && + GIT_DIR=../.git test_stdout false git -C work rev-parse --is-bare-repository +' + +test_expect_success 'GIT_DIR=../.git, core.bare undefined: is-inside-git-dir' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bar = && + GIT_DIR=../.git test_stdout false git -C work rev-parse --is-inside-git-dir +' + +test_expect_success 'GIT_DIR=../.git, core.bare undefined: is-inside-work-tree' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bar = && + GIT_DIR=../.git test_stdout true git -C work rev-parse --is-inside-work-tree +' + +test_expect_success 'GIT_DIR=../.git, core.bare undefined: prefix' ' + mkdir work && + test_when_finished "rm -rf work" && + test_config -C "$(pwd)"/.git core.bar = && + GIT_DIR=../.git test_stdout "" git -C work rev-parse --show-prefix +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare = false: is-bare-repository' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare false && + GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-bare-repository +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare = false: is-inside-git-dir' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare false && + GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-inside-git-dir +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare = false: is-inside-work-tree' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare false && + GIT_DIR=../repo.git test_stdout true git -C work rev-parse --is-inside-work-tree +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare = false: prefix' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare false && + GIT_DIR=../repo.git test_stdout "" git -C work rev-parse --show-prefix +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare = true: is-bare-repository' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare true && + GIT_DIR=../repo.git test_stdout true git -C work rev-parse --is-bare-repository +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare = true: is-inside-git-dir' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare true && + GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-inside-git-dir +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare = true: is-inside-work-tree' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare true && + GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-inside-work-tree +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare = true: prefix' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare true && + GIT_DIR=../repo.git test_stdout "" git -C work rev-parse --show-prefix +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare undefined: is-bare-repository' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare "" && + GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-bare-repository +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare undefined: is-inside-git-dir' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare "" && + GIT_DIR=../repo.git test_stdout false git -C work rev-parse --is-inside-git-dir +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare undefined: is-inside-work-tree' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare "" && + GIT_DIR=../repo.git test_stdout true git -C work rev-parse --is-inside-work-tree +' + +test_expect_success 'GIT_DIR=../repo.git, core.bare undefined: prefix' ' + mkdir work && + test_when_finished "rm -rf work" && + cp -r .git repo.git && + test_when_finished "rm -r repo.git" && + test_config -C "$(pwd)"/repo.git core.bare "" && + GIT_DIR=../repo.git test_stdout "" git -C work rev-parse --show-prefix +' test_done -- 2.8.0 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html