Created
February 15, 2015 18:20
-
-
Save talbright/ae923c8961d38e421144 to your computer and use it in GitHub Desktop.
Sets file mtimes to latest git commit timestamp
This file contains hidden or 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
# Ensures mtimes are consistent with the git commit to utilize ADD caching | |
# Re-written from https://github.com/docker-library/official-images/blob/1dd9118804a06fef308e613cdbabe44bf0529043/bashbrew/git-set-mtimes | |
# This version is more platform compatible (assuming you have ruby), works on os x and *nix | |
git_set_mtimes() { | |
pushd $1 | |
IFS=$'\n' | |
files=( $({ git ls-files | xargs dirname | sort -u && git ls-files; } | sort -r) ) | |
unset IFS | |
for f in "${files[@]}"; do | |
stamp="$(git --no-pager log -1 --format='format:%ai' -- "$f")" | |
tstamp=$(echo $stamp | ruby -r 'date' -ne 'puts DateTime.parse($_).strftime("%Y%m%d%H%M.%S")') | |
touch -h -t "$tstamp" "$f" | |
done | |
popd | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment