Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Read echos from hooks / manage hooks

Enrico Mensa February 25, 2018

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!

1 answer

0 votes
Mike Corsaro
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 27, 2018

Hello!

  1. All "echos" will output in the output in Sourcetree. To ensure you even see that output, make sure "Tools > Options > General > Always display full console output" is checked. You should then see the output from the hook
  2. That's a git-specific question, but if I had to guess it probably won't do anything if there isn't anything to push. You could commit using "--allow-empty" though, and then push (you'll need to do that via command-line as Sourcetree doesn't have a setting for that though)
Enrico Mensa February 28, 2018

Thank you for your suggestion.

I've activated the 'Always display...' (was in the advanced tab).

 

I'm pretty sure that the echos were not shown tho, I'll have to verify on my next commit.

 

In the meanwhile, thank you.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events