100 Days of Devops Day 34: Git Hook

Hi team, I think I have done the task correctly and i got the expected output of task Day 34. I have tried multiple time but every time system says that my anser is not corrct. I am not sure, what is the issue.
Screenshot_9

Hey @suzaman

I was stuck for about 3 days on this task alone. So I hope I can help.

Here’s a few things to make sure that you’re doing the right thing (just cos your request doesn’t contain a lot of detail, let’s ensure you have the following down):

  1. Make sure that your hook is setup on your bare repo (i.e. /opt/official.git or whatever the question throws at you)
  2. Here’s a snippet of the git hook that worked for me:
#My question was on /opt/media.git folder so-- /opt/media.git/hooks/post-update

#!/usr/bin/sh

# Arguments to post-update
DATE=$(date +%F)        # YYYY-MM-DD
GIT_DIR=$(pwd)

        echo "Creating tag release-$DATE"
        git --git-dir="$GIT_DIR" tag "release-$DATE" master

and rememember to make the file executable chmod +x /opt/media.git/hooks/post-update

  1. In this post, I outline what had me stuck for a few days. I was tagging the release but also forcing the tag unto subsequent commits (cos I was worried that the system would attempt to commit and get a failure). I now believe that I was marked wrong cos I did a git tag -f

  2. change dir into your working directory (in my case it was: cd /usr/src/kodekloudrepos/media
    You should be on the “feature branch”, so switch to “master”

git checkout master
git merge feature
git push

Please let me know if any of that helped.

cheers.

2 Likes

hi @olakunlecrown28 ,

I had the same problem mentioned in the thread. i added -f option. after deleting -f option, its done. Thanks for helping me.

Awesome,

Glad it helped.

Cheers.

It will be work if user git push instead of git push origin master.

you can check this : it contains the solution of Day 34 100-Days-Of-DevOps-KodeKloud-Challenges-Solutions

Oh, okay, I’ll try that too. thanks.

Hello did you face this error?
GIT_DIR=/usr/src/kodekloudrepos/apps
or
GIT_DIR=/usr/src/kodekloudrepos/apps/.git
which one is corect 1st or 2nd line?

Wrong value for GIT_DIR in the second case! The .git directory is a settings directory that sits inside of the git directory. So it should be GIT_DIR=/usr/src/kodekloudrepos/apps

Why does this line GIT_DIR=$(pwd) resolves to GIT_DIR:/opt/official.git ,
when in step 4 working directory was changed to /usr/src/kodekloudrepos/media ?

I am testing both values:

  • If I dont mention .git at the end, I get error ‘not a git repo’ . notice the yellow lines:

  • If I do mention .git at the end, I dont get the error but instead I get identity error

  • And finally if I mention work-tree and git-dir… and git configs: (–work-tree is actually not needed here, i tested)

git is like a 70-headed-hydra in Hercules game