Git Hook - task failed

For the task (details below). I made a copy of the post-update.sample file and name as post-update.
The post-update file content (details below). I executed manually to see if it will create a tag and it did. Then checkout master branch (git checkout master) and merge the feature branch (git merge feature) at the end I push all my changes (git push --all).

I get the below error and I have no idea why.

  • seems like ‘post-update’ hook is not working
    FAILED git_hooks.py::test_git_hooks - AssertionError: - seems like 'post-upda…

Task details

The Nautilus application development team was working on a git repository /opt/blog.git which is cloned under /usr/src/kodekloudrepos directory present on Storage server in Stratos DC. The team want to setup a hook on this repository, please find below more details:

Merge the feature branch into the master branch`, but before pushing your changes complete below point.

Create a post-update hook in this git repository so that whenever any changes are pushed to the master branch, it creates a release tag with name release-2023-06-15, where 2023-06-15 is supposed to be the current date. For example if today is 20th June, 2023 then the release tag must be release-2023-06-20. Make sure you test the hook at least once and create a release tag for today’s release.

Finally remember to push your changes.

post-update (file content)

current_date=date +"%Y-%m-%d"
release_name=“release-$current_date”

exec git tag $release_name

Its anybody else try to complete the task “Git Hook” or I’m the only one?
I will be very happy if anybody could point to right direction.

Hi @tsanghan
Thank you for your respond. I set up my git hooks on the cloned repo /usr/src/kodekloudrepos and I should set it up in the bare repo /opt/blog.git.

All working now

Thank you for your help

1 Like

@maciejws can you share your whole post-update file content?

I am not able to understand how it did work for you, I am trying but I am not able to complete the task

Done, Thank you so much

Hello ,

I have this hook set up in remote repo location. /opt/ecommerce.git/

cat post-update
#!/bin/bash

Get the current date

DATE=$(date +“%Y-%m-%d”)

Create the release tag

exec git tag “release-$DATE”
exec git push origin “release-$DATE”

but still i dont see push triggering commit and creating tag.
I am seeing this error message.
seems like release tag was not created from the ‘master’ branch
what did you do it differently ?

  • cd to bare repo

/opt/cluster.git/hooks

  • Then create the post-update hook

#!/bin/bash

#Get the current date

date=$(date +“%Y-%m-%d”)

#Create a release tag with the current date

git tag release-$date

  • Once the tag is created go to cloned repo

Git checkout master

Git merge feature

You will see the tag has been release with current date.

2 Likes

Thank you , that worked .
so we need to create a tag first and then do the merge and push.

1 Like

Yes. That’s great I was able to help!

Thank you!!! create tag when I do git pull after merge and push

Thank you,it worked for me!