SourceTree running a ruby git hook on OSX

Ayal Spitz July 16, 2013

I'm using SourceTree 1.6.2.2 on OSX 10.8.4 and as part of my companies commit process we've created a commit-msg hook, in ruby, that is designed to prevent a user from commiting code unless their commit message conforms to a specific set of rules.

Unfortunitly, it seems that SourceTree makes use of the ruby v1.8.7 that Apple distributes with OSX in 'System/Library/Frameworks/Ruby.framework/Versions/current/usr/bin' instead of using '/usr/bin/env ruby'. This causes all kinds of havoc especially since some of the gems we want to use depend on ruby 1.9+.

Is there anyway to switch the ruby which SourceTree utilizes to run git hooks? or is this something that Atlassian has to change in SourceTree? if so would you please.

Thanks - AYAL

1 answer

1 accepted

0 votes
Answer accepted
KieranA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 16, 2013

Hi Ayal,

We'd use whatever's available on the $PATH, but this is a per-instance concept. Just because the PATH was set somewhere else doesn't mean it's available in the current execution. Steve's comments from another thread better explain it than I can:

It's not something we can fix ourselves, it's an effect of the fact that terminals and full .apps have compeletely different environments (and PATH variables), so just adding something to your PATH in the terminal isn't going to make it visible to something launched by SourceTree. The way to resolve it is to add this folder to your global PATH for .apps too, which you do by editing /etc/paths or adding a new entry to /etc/paths.d

So you'd need to add /usr/bin/env to your global PATH making sure it takes precedence so it's the first ruby version that's called when running your hook.

Hope that helps, feel free to ask more questions if you need more help.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events