From 9daf81f16e1dc55491b20b7da1ea82bf8cf3b3e9 Mon Sep 17 00:00:00 2001 From: Victor Lim Date: Mon, 26 Feb 2018 16:32:43 +0800 Subject: [PATCH] Fix https://github.com/rbenv/rbenv/issues/1065 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. --- libexec/rbenv-version-file | 2 +- test/version-file.bats | 2 +- test/version-origin.bats | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index c0550d64..a8335950 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -9,7 +9,7 @@ target_dir="$1" find_local_version_file() { local root="$1" while ! [[ "$root" =~ ^//[^/]*$ ]]; do - if [ -f "${root}/.ruby-version" ]; then + if [ -s "${root}/.ruby-version" ]; then echo "${root}/.ruby-version" return 0 fi diff --git a/test/version-file.bats b/test/version-file.bats index d8cc74e3..075b002d 100644 --- a/test/version-file.bats +++ b/test/version-file.bats @@ -9,7 +9,7 @@ setup() { create_file() { mkdir -p "$(dirname "$1")" - touch "$1" + echo "system" > "$1" } @test "detects global 'version' file" { diff --git a/test/version-origin.bats b/test/version-origin.bats index 7bca376d..55138920 100644 --- a/test/version-origin.bats +++ b/test/version-origin.bats @@ -26,7 +26,7 @@ setup() { } @test "detects local file" { - touch .ruby-version + echo "system" > .ruby-version run rbenv-version-origin assert_success "${PWD}/.ruby-version" }