Create a gist now

Instantly share code, notes, and snippets.

@mtinsley /pre-commit
Last active Aug 29, 2015

What would you like to do?
#!/bin/sh
# The following demonstrates how to add build numbers to your project.
# This script can be added to your .git/hooks/pre-commit file. Alternatively
# you can add it as a separate shell script and call it from your pre-commit
# file.
# Fetch and increment the build number
buildnumber=`git rev-list HEAD --count`
((buildnumber++))
# Write the build number to a file
echo $buildnumber > build
# Update a PHP class constant with the build number
sed -i "s/const BUILD.*/const BUILD = $buildnumber;/" Class.php>/dev/null 2>&1
# Add the modified files
git add build
git add Class.php
echo "Build Number: $buildnumber"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment