New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow use of errexit (-e) when scripting rvm #3223

merged 1 commit into from Dec 24, 2014


None yet
2 participants

dholdren commented Dec 24, 2014

The cd hook is broken when scripting rvm with set -e (errexit),
in the particular case where a Gemfile is present and does not contain a ruby version directive

Steps to reproduce

Running this script:

set -e

source "$HOME/.rvm/scripts/rvm" #so 'cd' will change gemset when dotfiles present

rm -rf ~/tmp/dir_with_gemfile
mkdir -p ~/tmp/dir_with_gemfile

# a Gemfile with no ruby version information
echo "source ''" > ~/tmp/dir_with_gemfile/Gemfile
echo "gem 'rails'" >> ~/tmp/dir_with_gemfile/Gemfile
#end setup

echo 'pre cd ~'
cd ~
echo 'post cd ~'

#exits after "cd"
echo 'pre cd ~/tmp/dir_with_gemfile'
cd ~/tmp/dir_with_gemfile
echo 'post cd ~/tmp/dir_with_gemfile'

The output is: (notice it does not get to the last line)

pre cd ~
post cd ~
pre cd ~/tmp/dir_with_gemfile

running with set -x I get the following as the last few lines of output:

+ [[ -s /Users/dholdren/tmp/dir_with_gemfile/Gemfile ]]
+ __rvm_grep '^#ruby=' /Users/dholdren/tmp/dir_with_gemfile/Gemfile
+ command grep '^#ruby=' /Users/dholdren/tmp/dir_with_gemfile/Gemfile
+ grep '^#ruby=' /Users/dholdren/tmp/dir_with_gemfile/Gemfile


bash won't cause an exit while using errexit if the command is within an if expression, so I moved the greps for a ruby directive in the Gemfile into an if

@mpapis mpapis merged commit 9a23abc into rvm:master Dec 24, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed

mpapis added a commit that referenced this pull request Dec 24, 2014

mpapis added a commit that referenced this pull request Dec 24, 2014


This comment has been minimized.

Show comment
Hide comment

mpapis Dec 24, 2014


thank you!


mpapis commented Dec 24, 2014

thank you!

@mpapis mpapis added this to the rvm-1.26 milestone Dec 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment