jish / pre-commit

A slightly improved pre-commit hook for git
https://jish.github.io/pre-commit/
Other
796 stars 96 forks source link

Cannot run hooks from SourceTree #245

Closed wenga86 closed 7 years ago

wenga86 commented 7 years ago

RVM

Since terminals and full .apps have completely different environments (and PATH variables) the default path used by SourceTree did not expose rvm to SourceTree. In order to ensure SourceTree knows about rvm we added the following a conditional to the hook to add the rvm path if it wasn't included already. This exposed rvm so the hook could successfully execute rvm.

RVM_PATH=$HOME/.rvm/bin
if [ -d "$RVM_PATH" ] && [[ ! $PATH =~ (^|:)$RVM_PATH(:|$) ]]; then
  PATH+=:$RVM_PATH
fi

LC_CTYPE

We are running on Mac OSX 10.11.6. SourceTree's default encoding is C rather than UTF-8 which caused an encoding issue in ExecJS.

gems/execjs-2.2.1/lib/execjs/encoding.rb:22

Enforcing a LC_CTYPE of UTF-8 resolved the issue.

export LC_CTYPE="en_US.UTF-8"

Ruby Version 2.1.2

jish commented 7 years ago

Cool, thanks for the information. It sounds like you have everything working properly, then?

Would it be helpful to create another hook template that automatically configures SourceTree properly? https://github.com/jish/pre-commit/tree/master/templates/hooks

$ pre-commit install --source-tree
jish commented 7 years ago

I have released a new version of the gem that supports the --sourcetree option.

pre-commit install --sourcetree

cf. https://github.com/jish/pre-commit/pull/248