Reputation: 3300
I am startign to have fun with Git. Today I am starting a jQuery plugin to populate HTML elements with JSON feed and its been built with CoffeeScript.
As a result I am needing to compile the output once in a while. Currently I run a set of commands but its a paint to call it all the time.
Since I commit quite often, I thought it would be good to hook the compile step to the pre-commit. The idea is, compile the script, minify it, run git add .
and finally commit it.
So I came up with some thing like this in the .git/hooks/pre-commit
file.
echo "Compiling cofee scripts..."
exec coffee --compile --output ./dist/ ./src/
echo "DONE..."
echo "Minifying JavaScripts..."
exec minify dist/jquery.jsonPopulate.js dist/jquery.jsonPopulate.min.js
echo "DONE..."
echo ""
echo "Adding files to Git..."
exec git add .
echo "Done..."
echo ""
echo ""
exit 1
Once I run git add .
followed by git commit
and some message...
I see...
Compiling coffee scripts...
Looks like it is not continuing after exec
, should I use some thing else ?
Thanks in advance... Have a nice week end!
Upvotes: 2
Views: 1555
Reputation: 33203
The exec
command there replaced the current process with the new process. So the rest of your script will never be run. Just drop the exec and it will run 'coffee' and wait for it to terminate then continue to the next command. In hook scripts it is a good idea to only do the next command if the current one succeeded. So something more like the following might be better.
echo "Compiling cofee scripts..." &&
coffee --compile --output ./dist/ ./src/ &&
echo "Minifying JavaScripts..." &&
minify dist/jquery.jsonPopulate.js dist/jquery.jsonPopulate.min.js
This way of chaining the commands with the logical AND operator means the script will exit with the failure code of the command that errored and not continue to run later commands.
Upvotes: 4