Skip to content

Commit

Permalink
Don't try to allow overriding with rbenv shell
Browse files Browse the repository at this point in the history
* I can't find a way to recognize a custom RBENV_VERSION when this hook
* runs, since RBENV_VERSION is always populated regardless.
  • Loading branch information
aripollak committed Oct 2, 2015
1 parent 8af986f commit 67c64e3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
2 changes: 1 addition & 1 deletion bin/rbenv-bundler-ruby-version
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ find_gemfile_path() {
}

should_find_in_gemfile() {
[ -z "$RBENV_VERSION" ] && [ -z "$(rbenv-local 2>/dev/null)" ]
[ -z "$(rbenv-local 2>/dev/null)" ]
}

version_from_gemfile() {
Expand Down
8 changes: 0 additions & 8 deletions test/bundler-ruby-version.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ load test_helper
assert_success ''
}

@test 'Allow overriding version with rbenv shell' {
cd_into_project_with_gemfile "'" 1.2.3
create_version 4.5.6
export RBENV_VERSION=4.5.6
run rbenv bundler-ruby-version
assert_success ''
}

@test 'Recognize simple ruby version in single quotes with leading spaces' {
mkdir -p "$EXAMPLE_APP_DIR"
cd "$EXAMPLE_APP_DIR"
Expand Down

3 comments on commit 67c64e3

@jasonkarns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could query version-origin to see where RBENV_VERSION was set from. It would emit

if by shell:

RBENV_VERSION environment variable

if global:

/usr/local/var/rbenv/version

(and if global, you could query whether the version is 'system' or a real rbenv version)

@aripollak
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonkarns that has the same problem as the code above, since rbenv-version-origin just checks RBENV_VERSION anyway, and RBENV_VERSION is always set to the currently-prioritized rbenv version before this script would get run: https://github.com/sstephenson/rbenv/blob/9e664b5d27cd7b2bdb94a9ec8ce55c32ebe1ad7a/libexec/rbenv-which#L36

@jasonkarns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line referenced above sets RBENV_VERSION for the current shell, but it's not exported. You would be invoking rbenv-version-origin in a subshell, so RBENV_VERSION would not be set.

As I went about verifying this, I realized that since we need to invoke a subshell anyway, we may as well just query for an exported RBENV_VERSION itself, rather than going through the roundabout version-origin. So I verified that local env_var="$(echo $RBENV_VERSION)" and it does. But then I realized that rbenv-bundler-ruby-version itself is executed in a subshell from the which hook. So RBENV_VERSION is only set in the context of rbenv-bundler-ruby-version when it has been exported by the user. So this commit can be reverted. It works just fine. (I tested locally)

Please sign in to comment.