mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -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:
parent
6481cbb172
commit
1a0be6f0ad
2 changed files with 11 additions and 33 deletions
|
@ -15,12 +15,9 @@ set -e
|
|||
version="0.4.0"
|
||||
git_revision=""
|
||||
|
||||
for source_dir in "${BASH_SOURCE%/*}" "$RBENV_ROOT"; do
|
||||
if cd "$source_dir" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then
|
||||
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
|
||||
git_revision="${git_revision#v}"
|
||||
[ -z "$git_revision" ] || break
|
||||
fi
|
||||
done
|
||||
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then
|
||||
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
|
||||
git_revision="${git_revision#v}"
|
||||
fi
|
||||
|
||||
echo "rbenv ${git_revision:-$version}"
|
||||
|
|
|
@ -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 "?.?.? ]]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue