Help Git hook not working

Hi recently I’m working in this git lab:

I don’t know what I’m doing wrong here, as far as I know the git hook should work. I checked everything by terminal and should be working. This is the post-update script without the shell script:

!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".

var1="Release-"
var1+=$(date --rfc-3339=date)

exec git tag $var1

By the way, this script is called post-update, and not post-update.sh . Also I checked the file permissions and even dare to use 777 in chmod.

After that I switch to the master branch with git checkout master, also I checked in the hooks folder that the script is there. Then I just do with sudo also:

  git merge features
  git push origin master

I don’t know why the hook never gets activated during the process. It supposed to be, even with making a commit it doesn’t work. I don’t know how to approach this, because I guess the lab also checks if the two branches are exactly identical. So I can’t make a new commit, the hook needs to be activated when you are merging the two branches.

Any help will be aprecciated!

Q1) Where did you install post-update?
Q2) Where should you install post-update?
Read: Git - githooks Documentation

[root@ststor01 blog]# pwd
/usr/src/kodekloudrepos/blog
[root@ststor01 blog]# git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
[root@ststor01 blog]# git remote -v
origin  /opt/blog.git (fetch)
origin  /opt/blog.git (push)
[root@ststor01 blog]# git config --global user.email
[email protected]
[root@ststor01 blog]# git config --global user.name
blackwidow
[root@ststor01 blog]# touch test.txt
[root@ststor01 blog]# git add .
[root@ststor01 blog]# git commit -m "first commit"
[master (root-commit) 1f66785] first commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test.txt
[root@ststor01 blog]# git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 219 bytes | 219.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To /opt/blog.git
 * [new branch]      master -> master
[root@ststor01 blog]# git pull
From /opt/blog
 * [new tag]         release-2023-09-02 -> release-2023-09-02
Already up to date.
[root@ststor01 blog]# git tag
release-2023-09-02
[root@ststor01 blog]#

Note: Demo not using KKE environment.

Hi

I put the post-update under the hooks folder in .git .So in your case should be in /usr/src/kodekloudrepos/blog/.git/hooks/post-update.

I can’t remember well if the folder hooks is hooks or HOOKS, but is inside in the default folder created by git when you initialize a repo.

As far as I know, that should be right, so I don’t know what’s wrong with my implementation.

Best Regards

I do not see the link I posted was clicked.

I will read it then in a couple of hours. I’m little sleepy right now, but I will notify you if I succeed or not. Thanks!

Hi @sauron Thanks for the help. I think maybe there is some issue with the lab right now. I tried the info you said and it didn’t work. I’m thinking now that what I’m doing is not working because of my fault. So I will contact the kodekloud team if they can check if i’m right or not.

Thanks and have a nice day!

Hi @carlos140

In your hook script I can see var1="Release-", however as per the task description it is supposed to be release- (with small r), probably that’s the issue. If you still think there is some other issue, please record your solution and share with us to review the same.

Hi @inderpreetaps currently I know that mistake, but it doesn’t change the result. Currently now I’m talking by this topic to find the solution. Can check if the level 4 lab 3 of git is working right? - #3 by carlos140

Thanks for the help!

1 Like

Hi,
You need modify de hooks post-update in the remote repo, usually the remote repo is in /opt/namerepo.git, the error of you talk is when you modify the clone repo, try this, it is work for me