Created
June 1, 2024 04:15
-
-
Save AfzalivE/2143ec1a5d04427846863d1f4fd1c074 to your computer and use it in GitHub Desktop.
pre-push git hook to generate changelog 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/sh | |
# Save input for use in git lfs and for changelog generation. | |
stdin_input=`cat` | |
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } | |
echo "$stdin_input" | git lfs pre-push "$@" | |
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0') | |
echo "Handling pre-push" | |
echo "$stdin_input" | while read local_ref local_oid remote_ref remote_oid | |
do | |
if test "$local_oid" = "$zero" | |
then | |
# Handle delete | |
: | |
else | |
changelog_file="changelog/$(git branch --show-current | tr '/' '.').txt" | |
# Only create the file if it doesn't exist. | |
if [ ! -f "$changelog_file" ] | |
then | |
echo "🐛🕶⭐⛳️ $(git log main.. --format=format:%s)" > $changelog_file | |
else | |
echo "Not overwriting existing changelog file" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment