It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

precommit hg hook wont run when commiting in sourcetree

Johan Sommerfeld Mar 12, 2012

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

0 votes
Answer accepted
Steve Streeting Mar 12, 2012

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.

Johan Sommerfeld Mar 13, 2012

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?

Steve Streeting Mar 13, 2012

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

Johan Sommerfeld Mar 13, 2012

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.

Johan Sommerfeld Mar 13, 2012

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.

Steve Streeting Mar 13, 2012

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Sourcetree

[dev team] Sourcetree for Windows 2019 Preview - Dark Theme

Hi folks, While the full post is over on our blog I'd like to share the dark theme we've got planned for 2019 here directly as well to keep the discussion going.  The ...

1,956 views 14 18
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you