precommit hg hook wont run when commiting in sourcetree

I have a precommit hook that works fine when running hg commit in terminal. However when I commit in sourcretree, it seems it isn't executed.

How could I debug why the hook wont fire, or isn't it supported?

the config looks like:

[hooks]

precommit=python:my_python_hooks.hghooks.precommit

1 answer

1 accepted

Hmm, we don't specifically turn off any hooks, but does your hook rely on any extensions? For safety, SourceTree disables custom extensions when running to avoid any unexpected behaviour, but you can turn them on again in Preferences > Mercurial. Hooks though, we don't override, and the root ~/.hgrc is still in the configuration stack.

I have tride to add the core extentions and have tried with both emeded mecurial and system. but it dosen't seem to be fired. If i start a terminal from the app and run the same command as the one presented in the commit window (hg commit -y -m "test"). Do you call via a shell or is it done directly through the python package? could it be something with my hook that needs a terminal?

Is there any way for me to get more output from sourcetree to try to debug?

SourceTree just calls 'hg' as a separate process, so except for it not being a full terminal it should behave the same way. You can see more of what's going on by going into Preferences and checking the box 'Always show full output', which will always display the full content of task windows (they normally auto-close on success and hide the detail).

Thank you for the quick response.

I have done some debugging in the python code and verified that the hook gets called.

What I'm curently focusing on is that the python code tries to make command line calls toards pylint and pep8 using subprocess.Popen(...) and mayby it's here things go south.

Thank you for your help, I appologise for not looking at my own code better before posting here.

The issue was that my hook uses binaries in /usr/local/bin, which is in my path when I'm logged in to a terminal. Hovever the scope where sourcetree is executing the hg command /usr/local/bin is not. Once I added full path to the binaries it started to work.

I don't know if it is a security risk, but it would be nice to set some form of shell context for executing commands, in my case bash, and get it to source my .bashrc. This would make sourcetree streamline better with whats happening when I use hg and git in commandline.

Once again, sorry for bloating and thank you for a good product.

Ah yes, it's because the environment for all OS X apps is inherited from launchd and not from your terminal settings. If you want to add to your path in both your terminal and GUI apps in Mac OS X, the easiest way is to edit /etc/paths or add files to /etc/paths.d.

I'm glad you resolved it anyway!

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 ...

798 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