Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Read echos from hooks / manage hooks

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

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
Community showcase
Published in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

3,266 views 4 5
Read article

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