Skip to content

Instantly share code, notes, and snippets.

@Xrayez
Last active April 16, 2023 12:09
Show Gist options
  • Save Xrayez/607f1e84170381148567b23559a042b4 to your computer and use it in GitHub Desktop.
Save Xrayez/607f1e84170381148567b23559a042b4 to your computer and use it in GitHub Desktop.
An example git hook which shows how to append an arbitrary bit of information to a commit
#!/bin/sh
#
# An example git hook which shows how to append an arbitrary bit of information to a commit.
# The following appends some version number to a commit message.
#
VERSION=$(command --version) # `command` is any executable
BUILD="Xrayez" # Some arbitrary name
# Ensure that version contains some build name
if [[ $VERSION = *"$BUILD"* ]]; then
# Append only if not already present in the commit message
grep -qs $BUILD "$1" || printf "\n$VERSION" >> "$1"
else
# Build name is not configured
exit -1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment