From dd86f543fc77b758573fd2b34b6792228ca21159 Mon Sep 17 00:00:00 2001 From: Jeffrey 'jf' Lim Date: Wed, 8 Jan 2020 15:54:33 +0800 Subject: [PATCH 1/5] libexec/rbenv-version: get rid of misleading "set by $(rbenv-version-origin)" message when system ruby is in use --- libexec/rbenv-version | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-version b/libexec/rbenv-version index d1fefcc5..60922b69 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -8,4 +8,9 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -echo "$(rbenv-version-name) (set by $(rbenv-version-origin))" +RBENV_VERSION_FILE="$(rbenv-version-origin)" +if [ -e "$RBENV_VERSION_FILE" ]; then + echo "$(rbenv-version-name) (set by $RBENV_VERSION_FILE)" +else + echo "$(rbenv-version-name)" +fi From 5c3268c9afb08e345d204d05b977f24cedee52d1 Mon Sep 17 00:00:00 2001 From: Jeffrey 'jf' Lim Date: Wed, 8 Jan 2020 16:40:48 +0800 Subject: [PATCH 2/5] libexec/rbenv-version{,-origin}: fix earlier commit to allow for RBENV_VERSION env var --- libexec/rbenv-version | 8 ++++---- libexec/rbenv-version-origin | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv-version b/libexec/rbenv-version index 60922b69..f968cd1f 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -8,9 +8,9 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -RBENV_VERSION_FILE="$(rbenv-version-origin)" -if [ -e "$RBENV_VERSION_FILE" ]; then - echo "$(rbenv-version-name) (set by $RBENV_VERSION_FILE)" -else +RBENV_VERSION_ORIGIN="$(rbenv-version-origin)" +if [ -z "$RBENV_VERSION_ORIGIN" ]; then echo "$(rbenv-version-name)" +else + echo "$(rbenv-version-name) (set by $RBENV_VERSION_ORIGIN)" fi diff --git a/libexec/rbenv-version-origin b/libexec/rbenv-version-origin index 3f1d4f03..139d8157 100755 --- a/libexec/rbenv-version-origin +++ b/libexec/rbenv-version-origin @@ -17,5 +17,8 @@ if [ -n "$RBENV_VERSION_ORIGIN" ]; then elif [ -n "$RBENV_VERSION" ]; then echo "RBENV_VERSION environment variable" else - rbenv-version-file + RBENV_VERSION_FILE="$(rbenv-version-file)" + if [ -e "$RBENV_VERSION_FILE" ]; then + echo $RBENV_VERSION_FILE + fi fi From 40db754168e04eedb7a8915fc0faad8a58be71bd Mon Sep 17 00:00:00 2001 From: Jeffrey 'jf' Lim Date: Wed, 8 Jan 2020 16:41:14 +0800 Subject: [PATCH 3/5] Fix tests for #1203 --- test/version-origin.bats | 6 +++--- test/version.bats | 2 +- test/versions.bats | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/version-origin.bats b/test/version-origin.bats index 55138920..1257f9b8 100644 --- a/test/version-origin.bats +++ b/test/version-origin.bats @@ -7,10 +7,10 @@ setup() { cd "$RBENV_TEST_DIR" } -@test "reports global file even if it doesn't exist" { +@test "does not report global file if it doesn't exist" { assert [ ! -e "${RBENV_ROOT}/version" ] run rbenv-version-origin - assert_success "${RBENV_ROOT}/version" + assert_success "" } @test "detects global file" { @@ -52,5 +52,5 @@ SH @test "doesn't inherit RBENV_VERSION_ORIGIN from environment" { RBENV_VERSION_ORIGIN=ignored run rbenv-version-origin - assert_success "${RBENV_ROOT}/version" + assert_success "" } diff --git a/test/version.bats b/test/version.bats index 886d0efa..f75af978 100644 --- a/test/version.bats +++ b/test/version.bats @@ -14,7 +14,7 @@ setup() { @test "no version selected" { assert [ ! -d "${RBENV_ROOT}/versions" ] run rbenv-version - assert_success "system (set by ${RBENV_ROOT}/version)" + assert_success "system" } @test "set by RBENV_VERSION" { diff --git a/test/versions.bats b/test/versions.bats index 3273b375..2c88ee2f 100644 --- a/test/versions.bats +++ b/test/versions.bats @@ -21,7 +21,7 @@ stub_system_ruby() { stub_system_ruby assert [ ! -d "${RBENV_ROOT}/versions" ] run rbenv-versions - assert_success "* system (set by ${RBENV_ROOT}/version)" + assert_success "* system" } @test "not even system ruby available" { @@ -42,7 +42,7 @@ stub_system_ruby() { run rbenv-versions assert_success assert_output < Date: Thu, 16 Jan 2020 23:15:09 +0800 Subject: [PATCH 4/5] libexec/rbenv-version{,-origin}: move "missing rbenv-version-file detection" logic as per @mislav --- libexec/rbenv-version | 10 ++++++---- libexec/rbenv-version-origin | 5 +---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/libexec/rbenv-version b/libexec/rbenv-version index f968cd1f..c95ab0d3 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -8,9 +8,11 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -RBENV_VERSION_ORIGIN="$(rbenv-version-origin)" -if [ -z "$RBENV_VERSION_ORIGIN" ]; then - echo "$(rbenv-version-name)" +version_name="$(rbenv-version-name)" +version_origin="$(rbenv-version-origin)" + +if [ "$version_origin" = "${RBENV_ROOT}/version" ] && [ ! -e "$version_origin" ]; then + echo "$version_name" else - echo "$(rbenv-version-name) (set by $RBENV_VERSION_ORIGIN)" + echo "$version_name (set by $version_origin)" fi diff --git a/libexec/rbenv-version-origin b/libexec/rbenv-version-origin index 139d8157..3f1d4f03 100755 --- a/libexec/rbenv-version-origin +++ b/libexec/rbenv-version-origin @@ -17,8 +17,5 @@ if [ -n "$RBENV_VERSION_ORIGIN" ]; then elif [ -n "$RBENV_VERSION" ]; then echo "RBENV_VERSION environment variable" else - RBENV_VERSION_FILE="$(rbenv-version-file)" - if [ -e "$RBENV_VERSION_FILE" ]; then - echo $RBENV_VERSION_FILE - fi + rbenv-version-file fi From 137e705db7f3e5e344c15e3daee264ba9c2b6237 Mon Sep 17 00:00:00 2001 From: Jeffrey 'jf' Lim Date: Thu, 16 Jan 2020 23:24:42 +0800 Subject: [PATCH 5/5] Fix (revert) test/version-origin.bats --- test/version-origin.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/version-origin.bats b/test/version-origin.bats index 1257f9b8..55138920 100644 --- a/test/version-origin.bats +++ b/test/version-origin.bats @@ -7,10 +7,10 @@ setup() { cd "$RBENV_TEST_DIR" } -@test "does not report global file if it doesn't exist" { +@test "reports global file even if it doesn't exist" { assert [ ! -e "${RBENV_ROOT}/version" ] run rbenv-version-origin - assert_success "" + assert_success "${RBENV_ROOT}/version" } @test "detects global file" { @@ -52,5 +52,5 @@ SH @test "doesn't inherit RBENV_VERSION_ORIGIN from environment" { RBENV_VERSION_ORIGIN=ignored run rbenv-version-origin - assert_success "" + assert_success "${RBENV_ROOT}/version" }