I have a script, that I need to run after committing to a project under git revision control. Therefore I created a post-commit hook in my projects .git directory in the subdirectory /hooks, named it 'post-commit' and gave it the following contents:
#!/bin/sh # I am a post-commit hook /usr/local/bin/my_script &
my_script is executable and runs fine in /bin/sh. In fact it has a runtime of several seconds, so I want it to be backgrounded and detached from the current shell. That's why I put the trailing '&' to my hook.
The problem now is, that the '&' seems to be ignored. When I commit using gitx 0.7.1 under OSX Lion, gitx hangs for exactly the period that my_script needs to run.
I tried a lot, but do not get the process itself into the background.
What is wrong here?
The post-commit hook is called immediately after the commit-msg hook. It can't change the outcome of the git commit operation, so it's used primarily for notification purposes. The script takes no parameters and its exit status does not affect the commit in any way.
pre-commit hooks are a mechanism of the version control system git. They let you execute code right before the commit. Confusingly, there is also a Python package called pre-commit which allows you to create and use pre-commit hooks with a way simpler interface.
Here's how it works for me:
#!/bin/sh # I am a post-commit hook nohup /usr/local/bin/my_script &>/dev/null &
You could also use the at
command. You may have to install it first
echo /path/to/your/executable | at now
OR:
echo bash /path/to/your/script | at now
See the at(1) manual page for more info about at (man at
or the online version)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With