mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-17 07:43:46 -05:00
Improve git --version git revision lookup
It doesn't try to chdir into RBENV_ROOT anymore because that might be a location of an unrelated rbenv install that might have a different version than the current one that is installed e.g. via a package manager such as Homebrew. Now just tries the repo where the source files (`libexec/*`) are located, and if that isn't a valid rbenv repo, bail out early.
This commit is contained in:
@@ -2,22 +2,13 @@
|
||||
|
||||
load test_helper
|
||||
|
||||
export GIT_DIR="${RBENV_TEST_DIR}/.git"
|
||||
|
||||
setup() {
|
||||
mkdir -p "$HOME"
|
||||
git config --global user.name "Tester"
|
||||
git config --global user.email "tester@test.local"
|
||||
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/git" <<CMD
|
||||
#!$BASH
|
||||
if [[ \$1 == remote && \$PWD != "\$RBENV_TEST_DIR"/* ]]; then
|
||||
echo "not allowed" >&2
|
||||
exit 1
|
||||
else
|
||||
exec $(which git) "\$@"
|
||||
fi
|
||||
CMD
|
||||
chmod +x "${RBENV_TEST_DIR}/bin/git"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
git_commit() {
|
||||
@@ -28,26 +19,21 @@ git_commit() {
|
||||
assert [ ! -e "$RBENV_ROOT" ]
|
||||
run rbenv---version
|
||||
assert_success
|
||||
[[ $output == "rbenv 0."* ]]
|
||||
[[ $output == "rbenv "?.?.? ]]
|
||||
}
|
||||
|
||||
@test "doesn't read version from non-rbenv repo" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
cd "$RBENV_ROOT"
|
||||
git init
|
||||
git remote add origin https://github.com/homebrew/homebrew.git
|
||||
git_commit
|
||||
git tag v1.0
|
||||
|
||||
cd "$RBENV_TEST_DIR"
|
||||
run rbenv---version
|
||||
assert_success
|
||||
[[ $output == "rbenv 0."* ]]
|
||||
[[ $output == "rbenv "?.?.? ]]
|
||||
}
|
||||
|
||||
@test "reads version from git repo" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
cd "$RBENV_ROOT"
|
||||
git init
|
||||
git remote add origin https://github.com/rbenv/rbenv.git
|
||||
git_commit
|
||||
@@ -55,20 +41,15 @@ git_commit() {
|
||||
git_commit
|
||||
git_commit
|
||||
|
||||
cd "$RBENV_TEST_DIR"
|
||||
run rbenv---version
|
||||
assert_success
|
||||
[[ $output == "rbenv 0.4.1-2-g"* ]]
|
||||
assert_success "rbenv 0.4.1-2-g$(git rev-parse --short HEAD)"
|
||||
}
|
||||
|
||||
@test "prints default version if no tags in git repo" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
cd "$RBENV_ROOT"
|
||||
git init
|
||||
git remote add origin https://github.com/rbenv/rbenv.git
|
||||
git_commit
|
||||
|
||||
cd "$RBENV_TEST_DIR"
|
||||
run rbenv---version
|
||||
[[ $output == "rbenv 0."* ]]
|
||||
[[ $output == "rbenv "?.?.? ]]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user