Created
January 21, 2011 19:48
-
-
Save dreamer/790278 to your computer and use it in GitHub Desktop.
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 | |
# | |
# Place this in your .git/hooks directory. | |
# | |
# This hook looks through commited *.h and *.cpp files and replaces date in | |
# copyright line with current year. After that it generates new commit with | |
# automatic message and makes sure we won't get into git commit loop. | |
# | |
# @author Patryk Obara <dreamer.tan@gmail.com> | |
# | |
AUTO_COMMIT_MSG='Copyright date fixed (automatic message)' | |
YEAR=$(date +%Y) | |
COPYRIGHT_REGEX="* Copyright (C) \([0-9][0-9][0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)" | |
COPYRIGHT_NEW="* Copyright (C) \1-$YEAR" | |
modified_files () | |
{ | |
git log -1 --format=oneline --name-only | tail -n +2 | |
} | |
if [[ $(git log -1 --format=oneline) == *"$AUTO_COMMIT_MSG" ]] | |
then | |
echo 'Copyright date automatically fixed:' | |
modified_files | |
else | |
for file in $(modified_files); | |
do | |
if [[ $file == *'.h' || *.'cpp' ]] | |
then | |
if $(sed -i "s/$COPYRIGHT_REGEX/$COPYRIGHT_NEW/" $file 2>/dev/null) | |
then | |
git add $file | |
fi | |
fi | |
done | |
MSG=$(git commit -m "$AUTO_COMMIT_MSG") | |
#echo $MSG | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment