From 7af5ea261ed62ac71b418d6bcd5b72dd50a597c6 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Tue, 23 Dec 2025 19:14:47 +0300 Subject: [PATCH] Work with Git entirely in a test repo --- plugins/python-build/bin/pyenv-install | 3 ++- plugins/python-build/test/pyenv.bats | 5 ++++- test/--version.bats | 8 +++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/python-build/bin/pyenv-install b/plugins/python-build/bin/pyenv-install index a6e6021a..508e8a24 100755 --- a/plugins/python-build/bin/pyenv-install +++ b/plugins/python-build/bin/pyenv-install @@ -265,7 +265,8 @@ for DEFINITION in "${DEFINITIONS[@]}"; do echo "See all available versions with \`pyenv install --list'." echo echo -n "If the version you need is missing, try upgrading pyenv" - if [[ command -v brew && "${_PYENV_INSTALL_PREFIX}" == "$(brew --prefix)/"* ]; then + declare brew_prefix + if brew_prefix="$(brew --prefix 2>/dev/null)" && [[ $_PYENV_INSTALL_PREFIX/ == "$brew_prefix/"* ]]; then printf ":\n\n" echo " brew update && brew upgrade pyenv" elif [ -d "${_PYENV_INSTALL_PREFIX}/.git" ]; then diff --git a/plugins/python-build/test/pyenv.bats b/plugins/python-build/test/pyenv.bats index 3422ed97..9b514d78 100644 --- a/plugins/python-build/test/pyenv.bats +++ b/plugins/python-build/test/pyenv.bats @@ -141,6 +141,9 @@ OUT stub_python_build "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'" mkdir "$BATS_TEST_TMPDIR/.git" + #Faking the Pyenv installation prefix may break things. + # May have to move some dependent stuff into the fake root for the code to find it + # or introduce an overriding test variable in the code specifically for the hint. _PYENV_INSTALL_PREFIX="$BATS_TEST_TMPDIR" run pyenv-install 2.7.9 assert_failure assert_output <&2 && exit 2' \ "--definitions : true" diff --git a/test/--version.bats b/test/--version.bats index c494b17d..4005711f 100644 --- a/test/--version.bats +++ b/test/--version.bats @@ -3,8 +3,9 @@ load test_helper _setup() { - export GIT_DIR="${PYENV_TEST_DIR}/.git" - mkdir -p "$GIT_DIR" + export GIT_DIR="${PYENV_TEST_DIR}" + export GIT_WORK_TREE="$GIT_DIR" + git init --quiet git config user.name "Tester" git config user.email "tester@test.local" cd "$PYENV_TEST_DIR" @@ -22,7 +23,6 @@ git_commit() { } @test "doesn't read version from non-pyenv repo" { - git init git remote add origin https://github.com/homebrew/homebrew.git git_commit git tag v1.0 @@ -33,7 +33,6 @@ git_commit() { } @test "reads version from git repo" { - git init git remote add origin https://github.com/pyenv/pyenv.git git_commit git tag v0.4.1 @@ -45,7 +44,6 @@ git_commit() { } @test "prints default version if no tags in git repo" { - git init git remote add origin https://github.com/pyenv/pyenv.git git_commit