Skip to content

Instantly share code, notes, and snippets.

@gdyrrahitis
Last active June 11, 2017 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdyrrahitis/d3277df411d0e8d0e649921446421028 to your computer and use it in GitHub Desktop.
Save gdyrrahitis/d3277df411d0e8d0e649921446421028 to your computer and use it in GitHub Desktop.
Git prepare commit hook to alter a file. Append commit id to the version.js file with a prepare-commit hook
# Disclaimer: Commits should have the following format
# <PROJNAME>: <DESCRIPTION>
# Example:
# JIRA-450: My description
# Following code will substring the JIRA-450 and append it as last value of the `window.version` variable, replacing the `SAMPLE`
# This is just a sample, it is not recommended to do such mission, versions should be handled by CI and should follow the SEMVER specification: http://semver.org/
# Should add validation to ensure one is committing following the conventions
# Git hooks documentation https://git-scm.com/docs/githooks
# Get commit message
MESSAGE=`cat $1`
# Substring, get characters, starting from 1 (first) until ':'
MESSAGE=$( echo $MESSAGE | cut -d ':' -f 1 )
# Your js contents
CONTENTS="window.version = '1.2.3-"
# Concatenating message with contents
CONTENTS+=$MESSAGE
CONTENTS+="';"
# Writing to file before commiting
cat > version.js << EOF
$CONTENTS
window.version = '1.2.3-SAMPLE';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment