mirror of
https://github.com/pyenv/pyenv.git
synced 2024-12-22 15:23:35 +00:00
Merge branch 'rbenv-local-respects-ancestry'
This commit is contained in:
commit
a62a75369e
4 changed files with 42 additions and 20 deletions
|
@ -47,9 +47,10 @@ elif [ -n "$RBENV_VERSION" ]; then
|
|||
} >&2
|
||||
fi
|
||||
else
|
||||
rbenv-version-file-read .ruby-version ||
|
||||
rbenv-version-file-read .rbenv-version ||
|
||||
{ echo "rbenv: no local version configured for this directory"
|
||||
if version_file="$(rbenv-version-file "$PWD")"; then
|
||||
rbenv-version-file-read "$version_file"
|
||||
else
|
||||
echo "rbenv: no local version configured for this directory" >&2
|
||||
exit 1
|
||||
} >&2
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -1,35 +1,45 @@
|
|||
#!/usr/bin/env bash
|
||||
# Usage: rbenv version-file [<dir>]
|
||||
# Summary: Detect the file that sets the current rbenv version
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
target_dir="$1"
|
||||
|
||||
find_local_version_file() {
|
||||
local root="$1"
|
||||
while true; do
|
||||
[[ "$root" =~ ^//[^/]*$ ]] && break
|
||||
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
|
||||
if [ -e "${root}/.ruby-version" ]; then
|
||||
echo "${root}/.ruby-version"
|
||||
exit
|
||||
return 0
|
||||
elif [ -e "${root}/.rbenv-version" ]; then
|
||||
echo "${root}/.rbenv-version"
|
||||
exit
|
||||
return 0
|
||||
fi
|
||||
[ -n "$root" ] || break
|
||||
root="${root%/*}"
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
find_local_version_file "$RBENV_DIR"
|
||||
[ "$RBENV_DIR" = "$PWD" ] || find_local_version_file "$PWD"
|
||||
find_global_version_file() {
|
||||
local global_version_file="${RBENV_ROOT}/version"
|
||||
|
||||
global_version_file="${RBENV_ROOT}/version"
|
||||
if [ -e "$global_version_file" ]; then
|
||||
echo "$global_version_file"
|
||||
elif [ -e "${RBENV_ROOT}/global" ]; then
|
||||
echo "${RBENV_ROOT}/global"
|
||||
elif [ -e "${RBENV_ROOT}/default" ]; then
|
||||
echo "${RBENV_ROOT}/default"
|
||||
else
|
||||
echo "$global_version_file"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -e "$global_version_file" ]; then
|
||||
echo "$global_version_file"
|
||||
elif [ -e "${RBENV_ROOT}/global" ]; then
|
||||
echo "${RBENV_ROOT}/global"
|
||||
elif [ -e "${RBENV_ROOT}/default" ]; then
|
||||
echo "${RBENV_ROOT}/default"
|
||||
if [ -n "$target_dir" ]; then
|
||||
find_local_version_file "$target_dir"
|
||||
else
|
||||
echo "$global_version_file"
|
||||
find_local_version_file "$RBENV_DIR" || {
|
||||
[ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
|
||||
} || find_global_version_file
|
||||
fi
|
||||
|
|
|
@ -32,11 +32,11 @@ setup() {
|
|||
assert_success "2.0"
|
||||
}
|
||||
|
||||
@test "ignores version in parent directory" {
|
||||
@test "discovers version file in parent directory" {
|
||||
echo "1.2.3" > .ruby-version
|
||||
mkdir -p "subdir" && cd "subdir"
|
||||
run rbenv-local
|
||||
assert_failure
|
||||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
@test "ignores RBENV_DIR" {
|
||||
|
|
|
@ -97,3 +97,14 @@ create_file() {
|
|||
RBENV_DIR="${RBENV_TEST_DIR}/widget/blank" run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/project/.ruby-version"
|
||||
}
|
||||
|
||||
@test "finds version file in target directory" {
|
||||
create_file "project/.ruby-version"
|
||||
run rbenv-version-file "${PWD}/project"
|
||||
assert_success "${RBENV_TEST_DIR}/project/.ruby-version"
|
||||
}
|
||||
|
||||
@test "fails when no version file in target directory" {
|
||||
run rbenv-version-file "$PWD"
|
||||
assert_failure ""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue