Command `rbenv version-name > .ruby-version` will create an empty `.ruby-version` file
before running `rbenv-version-file`. This causes `rbenv-version-file` to return empty
string which in turn causes `rbenv-version-name` to return `system`.

Ensure size of `.ruby-version` is non-zero as a workaround.
This commit is contained in:
Victor Lim 2018-02-26 16:32:43 +08:00
parent b943955dbf
commit 9daf81f16e
3 changed files with 3 additions and 3 deletions

View file

@ -9,7 +9,7 @@ target_dir="$1"
find_local_version_file() { find_local_version_file() {
local root="$1" local root="$1"
while ! [[ "$root" =~ ^//[^/]*$ ]]; do while ! [[ "$root" =~ ^//[^/]*$ ]]; do
if [ -f "${root}/.ruby-version" ]; then if [ -s "${root}/.ruby-version" ]; then
echo "${root}/.ruby-version" echo "${root}/.ruby-version"
return 0 return 0
fi fi

View file

@ -9,7 +9,7 @@ setup() {
create_file() { create_file() {
mkdir -p "$(dirname "$1")" mkdir -p "$(dirname "$1")"
touch "$1" echo "system" > "$1"
} }
@test "detects global 'version' file" { @test "detects global 'version' file" {

View file

@ -26,7 +26,7 @@ setup() {
} }
@test "detects local file" { @test "detects local file" {
touch .ruby-version echo "system" > .ruby-version
run rbenv-version-origin run rbenv-version-origin
assert_success "${PWD}/.ruby-version" assert_success "${PWD}/.ruby-version"
} }