Created
August 5, 2019 04:45
-
-
Save kujyp/8d73f63f0658a59ddd63fae921ad8edf 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 -e | |
OS=${OS:-`uname`} | |
old_rev="$1" | |
new_rev="$2" | |
get_file_rev() { | |
git rev-list -n 1 "$new_rev" "$1" | |
} | |
filename=README.md | |
rev=$(git log --oneline | head -n 1 | awk '{ print $1 }') | |
abbrev_commit=$(git rev-list -n 1 ${rev} ${filename}) | |
time_in_millis=$(git show --pretty=format:%at --abbrev-commit ${abbrev_commit} | head -n 1) | |
file_time=$(date -r ${time_in_millis} '+%Y%m%d%H%M.%S') | |
echo "$file_time" | |
touch -h -t "${file_time}" "${filename}" | |
if [ "$OS" = 'Linux' ] | |
then | |
update_file_timestamp() { | |
file_time=`git show --pretty=format:%ai --abbrev-commit "$(get_file_rev "$1")" | head -n 1` | |
touch -d "$file_time" "$1" | |
} | |
elif [ "$OS" = 'FreeBSD' ] | |
then | |
update_file_timestamp() { | |
file_time=`date -r "$(git show --pretty=format:%at --abbrev-commit "$(get_file_rev "$1")" | head -n 1)" '+%Y%m%d%H%M.%S'` | |
touch -h -t "$file_time" "$1" | |
} | |
else | |
echo "timestamp changing not implemented" >&2 | |
update_file_timestamp() { | |
echo "update_file_timestamp $1" | |
file_time=`date -r "$(git show --pretty=format:%at --abbrev-commit "$(get_file_rev "$1")" | head -n 1)" '+%Y%m%d%H%M.%S'` | |
echo "update_file_timestamp $file_time" | |
} | |
# exit 1 | |
fi | |
IFS=`printf '\t\n\t'` | |
rev=$(git log --oneline | head -n 1 | awk '{ print $1 }') | |
git ls-files | while read -r filename | |
do | |
echo ${filename} | |
abbrev_commit=$(git rev-list -n 1 "${rev}" "${filename}") | |
#time_in_millis=$(git show --pretty=format:%at --abbrev-commit "${abbrev_commit}" | head -n 1) | |
file_time=`git show --pretty=format:%ai --abbrev-commit "$abbrev_commit" | head -n 1` | |
# time_in_millis=$(git show --pretty=format:%ai --abbrev-commit "${abbrev_commit}" | head -n 1) | |
# file_time=$(date -r "${time_in_millis}" '+%Y%m%d%H%M.%S') | |
echo "file_time=${file_time}" | |
echo "file_name=${filename}" | |
ll -a "${filename}" | |
# touch -h -t "${file_time}" "${filename}" | |
touch -d "${file_time}" "${filename}" | |
ll -a "${filename}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment