Skip to content

Instantly share code, notes, and snippets.

@apeckham
Forked from davidwindell/git-timestamp.sh
Last active March 2, 2016 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeckham/9d1ad7e7e14d95358d1c to your computer and use it in GitHub Desktop.
Save apeckham/9d1ad7e7e14d95358d1c to your computer and use it in GitHub Desktop.
Set the files' last modified times to match their git commit timestamps
#!/bin/bash -e
####
# based on http://www.clock.co.uk/blog/a-guide-on-how-to-cache-npm-install-with-docker
#
# Set's the last modified timestamp of a file to it's repositories commit timestamp.
#
# Particularly useful with docker when building after a new git checkout has been made,
# can improve docker build times for composer, bower, npm, etc
#
# @see https://github.com/docker/docker/issues/3556
####
set -e
if test $# = 0; then
echo "Usage: git-timestamp <files>"
echo "Set the files' last modified times to match their git commit timestamps."
exit
fi
for FILE in "$@"
do
REV=$(git rev-list -n 1 HEAD "$FILE");
STAMP=$(git log -1 --pretty=format:%ct "$REV")
touch -d @"$STAMP" "$FILE"
echo "Set $FILE to $STAMP"
done
@apeckham
Copy link
Author

apeckham commented Mar 2, 2016

in circle.yml:

checkout:
  post:
    - bash <(curl -s https://gist.githubusercontent.com/apeckham/9d1ad7e7e14d95358d1c/raw/git-timestamp.sh) package.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment