Forked from phpdude/Git hook sync modification time to last commit time
Last active
August 29, 2015 14:02
-
-
Save tdurand/fcb4ca25389f5adca7f1 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 | |
OS=${OS:-`uname`} | |
if [ "$OS" = 'Linux' ] | |
then | |
update_file_timestamp() { | |
file_time=`git log --no-merges --format=%ai "$1" | head -n 1` | |
echo "change timestamp file $file_time $1" | |
touch -d "$file_time" "$1" | |
} | |
elif [ "$OS" = 'FreeBSD' ] || [ "$OS" = 'Darwin' ]; | |
then | |
update_file_timestamp() { | |
file_time=`date -r "$(git log --no-merges --format=%at "$1" | head -n 1)" '+%Y%m%d%H%M.%S'` | |
echo "change timestamp file $file_time $1" | |
touch -h -t "$file_time" "$1" | |
} | |
else | |
echo "timestamp changing not implemented" >&2 | |
exit 1 | |
fi | |
#List all the files of the git repository | |
for file in `git ls-tree -r --name-only HEAD` | |
do | |
if [ -f "$file" ]; then | |
#For each file update the file timestamp with the timestamp of the last commit on this file | |
update_file_timestamp "$file" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment