SourceTree running a ruby git hook on OSX

I'm using SourceTree 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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

762 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you