stevenharman / git_tracker

Some simple tricks that make working with Pivotal Tracker even better... and easier... um, besier!
https://github.com/stevenharman/git_tracker
MIT License
170 stars 11 forks source link

Commits break when git-tracker can't find the right Ruby #14

Closed tubbo closed 11 years ago

tubbo commented 11 years ago

I've installed this awesome plugin with Homebrew, and I now have a globally-available command named git-tracker. Pretty cool!

The only time I ever find fault with it is when I'm using git inside other programs or plugins, like a Thor script that executes shell commands...

Here's an example output from when I try to run Git commands inside another Ruby (using Thor) process:

♬  rain on stage
Making it rain on stage...
No version type detected, assuming you meant '--patch' (as it is default)
executing... git commit -m '[RELEASE][stage] Update release tag for stage to rel_1.1.553' /Users/necromancer/Sites/elocal.com/config/versions.yml
Gemfile syntax error:
/Users/necromancer/Sites/elocal.com/Gemfile:22: syntax error, unexpected ':', expecting $end
gem 'thor', require: false
                    ^
executing... git push origin master
^CKilled by signal 2.
/Users/necromancer/Sites/elocal.com/vendor/gems/gems/activesupport-3.2.13/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``': Interrupt
    from /Users/necromancer/Sites/elocal.com/vendor/gems/gems/activesupport-3.2.13/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
    from /Users/necromancer/Sites/elocal.com/vendor/gems/bundler/gems/rain-5befc3a4ebca/lib/rain/git_tools.rb:88:in `run_cmd'
    from /Users/necromancer/Sites/elocal.com/vendor/gems/bundler/gems/rain-5befc3a4ebca/lib/rain/git_tools.rb:112:in `update_release_tag'
    from /Users/necromancer/Sites/elocal.com/vendor/gems/bundler/gems/rain-5befc3a4ebca/lib/rain/deployer.rb:23:in `on'
    from /Users/necromancer/Sites/elocal.com/vendor/gems/gems/thor-0.17.0/lib/thor/task.rb:27:in `run'
    from /Users/necromancer/Sites/elocal.com/vendor/gems/gems/thor-0.17.0/lib/thor/invocation.rb:120:in `invoke_task'
    from /Users/necromancer/Sites/elocal.com/vendor/gems/gems/thor-0.17.0/lib/thor.rb:344:in `dispatch'
    from /Users/necromancer/Sites/elocal.com/vendor/gems/gems/thor-0.17.0/lib/thor/base.rb:434:in `start'
    from /Users/necromancer/Sites/elocal.com/vendor/gems/bundler/gems/rain-5befc3a4ebca/bin/rain:11:in `<top (required)>'
    from /Users/necromancer/Sites/elocal.com/bin/rain:16:in `load'
    from /Users/necromancer/Sites/elocal.com/bin/rain:16:in `<main>'

Not sure if you guys had to deal with it in any other capacity, or if there was a way I should be calling Git commands in my deployment tool that would mitigate this issue?

stevenharman commented 11 years ago

The git-tracker script installed by Homebrew uses the #!/usr/bin/ruby shebang line. On modern OS X that is typically some flavor of Ruby 1.8.x. The hash syntax referenced in that error is only valid for Ruby 1.9+. So that is why you're seeing the error.

The real WTF is why the git-tracker script is running in the context of your app's Gemfile. As it turns out, Bundler pollutes several ENV variables, including RUBYOPT, BUNDLE_GEMFILE, etc. and those are propagated subshells.

I believe a fix for your tooling would be to execute your subshells like so:

# rain/lib/rain/git_tools.rb#86
def run_cmd(cmd)
  puts "executing... #{cmd}"
  Bundler.with_clean_env do
    %x(#{cmd}) unless ENV['RAILS_ENV'] == "test"
  end
end

It's not pretty, but I think that should resolve the issue. Please let me know what you find!

stevenharman commented 11 years ago

Oh, and @alindeman just told me about Bundler.clean_system and Bundler.clean_exec, so you could use one of those too, depending on your needs.

tubbo commented 11 years ago

Hmm, I'll give that a shot. Seems like it would prevent a bunch of other problems down the line too. Thanks for the tip!