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
merged 1 commit into from Dec 24, 2014

Conversation

Projects
None yet
2 participants
@dholdren
Contributor

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:

#!/bin/bash
set -e

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

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

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

#works
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
+ GREP_OPTIONS=
+ command grep '^#ruby=' /Users/dholdren/tmp/dir_with_gemfile/Gemfile
+ grep '^#ruby=' /Users/dholdren/tmp/dir_with_gemfile/Gemfile

Solution

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
Details

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

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

@mpapis

This comment has been minimized.

Show comment
Hide comment
@mpapis

mpapis Dec 24, 2014

Member

thank you!

Member

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