Last active
December 19, 2022 15:23
-
-
Save ThomDietrich/7127ca6e45dd4747e86ad9a609e1aeeb to your computer and use it in GitHub Desktop.
git hook for revision and branch version file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Automatically generate a file with git branch and revision info | |
## | |
## Example: | |
## [master]v2.0.0-beta-191(a830382) | |
## Install: | |
## cp git-create-revisioninfo-hook.sh .git/hooks/post-commit | |
## cp git-create-revisioninfo-hook.sh .git/hooks/post-checkout | |
## cp git-create-revisioninfo-hook.sh .git/hooks/post-merge | |
## chmod +x .git/hooks/post-* | |
FILENAME='public/gitrevision.txt' | |
exec 1>&2 | |
branch=`git rev-parse --abbrev-ref HEAD` | |
longhash=`git log --no-show-signature --pretty=format:'%H' -n 1` | |
shorthash=`git log --no-show-signature --pretty=format:'%h' -n 1` | |
revcount=`git log --no-show-signature --oneline | wc -l | tr -d ' '` | |
latesttag=`git describe --tags --abbrev=0 --always` | |
#VERSION="[$branch]$latesttag-$revcount($shorthash)" | |
#VERSION="[$branch]rev$revcount($shorthash)" | |
JSON="{\"branch\": \"$branch\", \"shorthash\": \"$shorthash\", \"longhash\": \"$longhash\", \"revcount\": \"$revcount\", \"latesttag\": \"$latesttag\"}" | |
echo $JSON > $FILENAME |
Fyi: Slight bugfix update and added json output
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the
post-commit
hook will do: update${FILENAME}
every time aftergit commit -am <message>
, so the "new"${FILENAME}
actually won't be published into remote repository due to the status ismodified
(instead ofstaged
).So, is there any way that using git-hook to modify files in post-commit steps, and put changed file into
staged
status (for push)?