Skip to content

Instantly share code, notes, and snippets.

@sunscan
Last active October 13, 2017 23:38
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 sunscan/eb25aa4160c4e405f9eadbbc243057b4 to your computer and use it in GitHub Desktop.
Save sunscan/eb25aa4160c4e405f9eadbbc243057b4 to your computer and use it in GitHub Desktop.
#!/bin/sh -e
# git-cache-meta -- file meta data caching for possible use with
# git-bundle, git-fast-export, git-archive, hooks, as a simple
# alternative to etckeeper, metastore, setgitperms. Requires GNU Find.
#
# original version by jidanni: https://marc.info/?l=git&m=123146944027390
# some modifications borrowed from this thread: https://gist.github.com/andris9/1978266
# features:
# - works only on MacOS X with GNU find (brew install findutils)
# - save all files and directories metadata except access time
: ${GIT_CACHE_META_FILE=.git_cache_meta}
case $@ in
--store|--stdout)
case $1 in --store) exec > $GIT_CACHE_META_FILE; esac
# directories
git ls-tree --name-only -rd $(git write-tree) | xargs -I NAME gfind ./NAME -maxdepth 0 \
\( -printf "chown -h '%u':'%g' '%p'\n" \) , \
\( \! -type l -printf "chmod %#m '%p'\n" \) , \
\( -printf "touch -hct '%TY%Tm%Td%TH%TM' '%p'\n" \)
# files
git ls-files | xargs -I NAME gfind ./NAME \
\( -printf "chown -h '%u':'%g' '%p'\n" \) , \
\( \! -type l -printf "chmod %#m '%p'\n" \) , \
\( -printf "touch -hct '%TY%Tm%Td%TH%TM' '%p'\n" \);;
--apply) sh -e ${GIT_CACHE_META_FILE};;
*) 1>&2 echo "Usage: $0 --store|--stdout|--apply"; exit 1;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment