Forked from ThomDietrich/git-create-revisioninfo-hook.sh
Created
April 10, 2019 06:47
-
-
Save bunam/1ab211299e5bb01a7ba45a3e38ce6b44 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` | |
shorthash=`git log --pretty=format:'%h' -n 1` | |
revcount=`git log --oneline | wc -l` | |
latesttag=`git describe --tags --abbrev=0 --always` | |
VERSION="[$branch]$latesttag-$revcount($shorthash)" | |
echo $VERSION > $FILENAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment