I have a pre-commit hook that calls grunt to lint before checking in. When commiting from the command line it works fine. When commiting via SourceTree it doesn't work. The pre-commit hook runs...
#!/bin/sh BRANCH="$(git rev-parse --abbrev-ref HEAD)" ROOT="$(git rev-parse --show-toplevel)" cd $ROOT git stash -q --keep-index cd $ROOT/build /usr/local/bin/grunt $BRANCH RESULT=$? cd $ROOT git stash pop -q [ $RESULT -ne 0 ] && exit 1 exit 0
gives the error :
git -c diff.mnemonicprefix=false -c core.quotepath=false commit -q -F /var/folders/Ta/Ta3HaDmvGz8e5G+8MKxNvLtVItU/-Tmp-/SourceTreeTemp.bXmip3 env: node: No such file or directory Completed with errors, see above
If I try to run the ST generated git command from the shell manually it works fine too, so I'm guessing it's something up with the paths. I tried creating a launchctl.conf and adding /usr/local/bin to it but that didn't change the error. The path appears to be correct in env.
> which node /usr/local/bin/node > env | grep /usr/local/bin PATH=/usr/local/share/python:/usr/local/opt/php54/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/adamr/bin:/Users/adamr/Applications/AWS-ElasticBeanstalk-CLI-2-1.3/eb/macosx/python2.7:/Users/adamr/Applications/AWS-ElasticBeanstalk-CLI-2-1.3/api/bin
It really works with two important points to avoid wasting time:
I have been scouring around to see what's going on in this case. We should definitely have access to env vars as these are used in many cases. Using 'which node' doesn't necessarily mean it's correct unfortunately, it locates an application in the user's path, so just a few things to check. First, actually browser to /usr/local/bin/node and ensure it's installed there. If it's installed there, is it usable from there? Regarding env vars, have a look here to see if there's anything you're missing. 'node' has been discussed and changed at some point to 'nodejs' instead, but I can't determine when that happened, or if it has happened on Mac OS - users seem to be aliasing 'node' to 'nodejs'.
If all that fails, check out this guys blog regarding the exact error you're getting. Some env vars (dependent on how they're set, and from what app they're set from) don't get set on the same path which means they're unavailable in perhaps this context.
It will be a case of poke it and see, especially when it comes to the path var being set and env vars in general. With the error you're getting, I'm thinking that the env var isn't set in the correct place which is why I've linked those two articles which should hopefully shed some light on it.
Hey thanks again for looking into this.
Turns out it was the same issue as described in the last post you linked to. If I launch ST via the command line ($open /Applications/SourceTree.app/Contents/MacOS/SourceTree) it works fine. It only fails when launched by clicking on the app or via spotlight. I'm a bit wary of creating a new $path in environment.plist as this will eventually get out of synch with the real $path and I'll invariably forget about it and end up even more confused later :) So for now I've just symlinked node and phpunit binaries from /usr/local/bin into /bin/ . Not ideal but seems to fix it.
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
As discussed in an earlier post you could just symlink the missing paths?
For example my SourceTree application doesn't look in /usr/local/bin (the location of grunt and node on my machine) however it does look in /usr/bin (do 'echo $PATH' in a hook file for example and you will see what paths it is looking in) - so i just did the following in the terminal:
ln -s /usr/local/bin/grunt /usr/bin/grunt
ln -s /usr/local/bin/node /usr/bin/node
Hacky but works.
This works better in my environment
#!/usr/bin/env sh export HOOK_NAME=$0 export HOOK_ARGS=$@ source ~/.bash_profile `which node` << `tail -n +5 $0` console.log('test ' + process.env['HOOK_NAME']); console.log('args ' + process.env['HOOK_ARGS']);
All other advices have caused troubles. Inspired by Universal node.js shebang
If you're using OS X, and want to be able to launch SourceTree from the dock while having the correct envrionment... you can follow this simple guide to create a sort of proxy app which will launch SourceTree from the terminal, having sourced your bash_profile...
My shell script...
Confirmed that this works!
I'm facing the same issues on my mac with SourceTree 2.5. The precommit hook should lint some php files which are written in php7 syntax.
The problem is that SourceTree uses the system php (version 5.x) which can't parse the files.
Triggering the precommit hook manually works fine - it uses the correct php version specified as path variable.
So I printed the path in the commit hook and the order of the path variables is different in SourceTree than in terminal. Any suggestions?
Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda ...
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!
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
We're bringing product updates and pro tips on teamwork to ten cities around the world.Save your spot