Hello guys.
I'm quite new with git hooks, so sorry if my question sounds dumb.
I've got a bare repo on my server, and I've set up a post-receive hook to automatically checkout the bare repo to my production directory. Then, in ST, I've set up a remote that writes to the bare repo.
This is the hook:
#!/bin/bash
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to production..."
git --work-tree=[prod_dir] --git-dir=[repo_dir] checkout -f
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done
[prod_dir] and [repo_dir] are correctly set to the directories for the production and the bare repo.
Everything was working good, until I started to change the hook, specifically I added the command for composer to update just under the git command. I performed a push, and the checkout didn't work out (my production directory was not updated).
I then read online that I should place any other command right under the `done`.
Now, I've got a two questions:
1) Is there a way to get the echos from the hook directly in output of ST?
2) Is the post-receive hook triggered if the bare repo is already updated? Because after my first push (that failed) I started to edit the hook in order to test if something was wrong in there, and I kept pushing (ofcourse nothing changed in the files so the status was [up to date]). I tried to do some random stuff, such as echoing "hello" into a file, but nothing happened. I suspect that when everything is up to date, the hook is not triggered.
Thank you!