Last active
July 4, 2023 14:06
-
-
Save micaelbergeron/d0b9180415c2c5e992e7 to your computer and use it in GitHub Desktop.
Git pre-commit hook to automatically write version numbers.
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 | |
# Called by "git commit" with no arguments. The hook should | |
# exit with non-zero status after issuing an appropriate message if | |
# it wants to stop the commit. | |
# | |
# Author: Micael Bergeron <micael.bergeron@solutionstlm.com> | |
# Goal: | |
# Automatic version numbering from the latest tag on the branch. | |
# The output format is <branch name>-<tag>-<HEAD sha>-<dirty?> | |
versionfilename=$(git config hooks.versionfilename) | |
if [[ -z $versionfilename ]] | |
then | |
versionfilename=".version" | |
fi | |
# Version number | |
#echo \# Generated using git pre-commit hook > $versionfilename | |
echo -n $(git rev-parse --abbrev-ref HEAD) > $versionfilename | |
echo -n "-" >> $versionfilename | |
echo $(git describe --tags --long --dirty) >> $versionfilename | |
exec git add $versionfilename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment