Git hook with every HEAD change

My goal is to save the updated file with the current HEAD commit, branch and some other details. I have a working git post-checkout hook that updates the file, but I want the hook to be triggered whenever the HEAD changes, be it commit, merge or anything else that might be possible.

What is the easiest way to make sure my hook fires whenever the HEAD changes?

More details

The file I create is a javascript file that is part of a statically served website. We are not dependent on server-side scripts, so we would like to avoid such a dependency here.

The script that should be run is as follows:

 #!/bin/sh FILE=js/git-status.js echo "// This file is autogenerated by a post-checkout hook. Your changes here WILL be lost." > $FILE echo "GIT_BRANCH = '$(git rev-parse --abbrev-ref HEAD)';" >> $FILE echo "GIT_COMMIT_HASH = '$(git rev-parse HEAD)';" >> $FILE echo "GIT_COMMIT_TIME = '$(git log -1 -s --format=%ci HEAD)';" >> $FILE echo "Updated $FILE" 

Although there may be another approach that I could take, I would still like to answer the original question.

+5
source share
1 answer

It seems that this may not be possible (although please confirm that I am wrong), so I decided with this reasonably good approach: I run the script from several hooks, which means that it will be run most of the time.

These are the hooks I use:

  • post control
  • after fixation
  • after the merger
  • after relocate
+1
source

Source: https://habr.com/ru/post/1207462/


All Articles