Skip to content

Instantly share code, notes, and snippets.

@Cojad
Forked from andris9/git-cache-meta.sh
Last active October 16, 2021 08:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Cojad/9205547 to your computer and use it in GitHub Desktop.
Save Cojad/9205547 to your computer and use it in GitHub Desktop.
git-cache-meta -- simple file meta data caching and applying.
#!/bin/sh -e
#git-cache-meta -- simple file meta data caching and applying.
#Simpler than etckeeper, metastore, setgitperms, etc.
# 2014-02-25 change filetime from accessed time to modifpeied time by cojad
# 2012-03-05 - added filetime, andris9
#modified by n1k
# - save all files metadata not only from other users
# - save numeric uid and gid
#from http://www.kerneltrap.org/mailarchive/git/2009/1/9/4654694
: ${GIT_CACHE_META_FILE=.git_cache_meta}
case $@ in
--store|-f|--stdout|-c)
case $1 in --store|-f) exec > $GIT_CACHE_META_FILE; esac
find $(git ls-files)\
\( -printf 'chown %U "%p"\n' \) \
\( -printf 'chgrp %G "%p"\n' \) \
\( -printf 'touch -c -d "%AY-%Am-%Ad %AH:%AM:%AS" "%p"\n' \) \
\( -printf 'chmod %#m "%p"\n' \) ;;
--apply|-r) sh -e $GIT_CACHE_META_FILE;;
*) 1>&2 echo "Usage:"
echo " $0 --store|--stdout|--apply";
echo " --store -f store meta in file";
echo " --stdout -c output to cosole";
echo " --apply -r restore meta"; exit 1;;
esac
#!/bin/sh -e
#git-cache-time -- simple file timestamp caching and applying.
#Simple solution to store/restore timestamp from git repository
# - save only file modification timestamp
# 2014-02-25 change filetime from accessed time to modified time by cojad
# 2012-03-05 - added filetime, andris9
#modified by n1k
#from http://www.kerneltrap.org/mailarchive/git/2009/1/9/4654694
: ${GIT_CACHE_META_FILE=.git_cache_meta}
case $@ in
--store|-f|--stdout|-c)
case $1 in --store|-f) exec > $GIT_CACHE_META_FILE; esac
find $(git ls-files)\
\( -printf 'touch -c -d "%TY-%Tm-%Td %TH:%TM:%TS" "%p"\n' \) ;;
--apply|-r) sh -e $GIT_CACHE_META_FILE;;
*) 1>&2 echo "Usage:"
echo " $0 --store|--stdout|--apply";
echo " --store -f store timestamp in file";
echo " --stdout -c output to cosole";
echo " --apply -r restore timestamp"; exit 1;;
esac

source:

git-cache-time              Works like git-cache-meta but only store file timestamp

git-cache-meta --store      Cache all meta include numeric uid/gid/permission in .git_cache_meta
git-cache-meta -f           Alias of --store

git-cache-meta --stdout     Same as --store but output in console
git-cache-meta -c           Alias of --stdout

destination:

git-cache-meta              Works like git-cache-meta but only store file timestamp
                            but restore "all" the meta in .git_cache_meta
                            
git-cache-meta --apply      Apply/Restore meta saved in .git_cache_meta
git-cache-meta -r           Alias of --apply
@danimesq
Copy link

danimesq commented Oct 16, 2021

It is wonderful the collaboration level the humans can naturally organize 🥰
andris9 have started this and y'all started appending into it, respecting/including the previous contributions
All of that not on a git repository, but providing a frugal way into a gist!

In case of any interest/need (and personally this script've helped me as I have a compulsion for preserving dates), here is a unified repository with all of your contributions! 🎉🥳 (🎊 look like a beach bikini)

https://github.com/Floflis/git-meta

AntonioMeireles brayrobert201 stefanbj Explorer09 Cojad the-mars mkortleven-emg danny0838 bizonix

Sorry arno01 for not including yours, as it seemed very incomplete and cmw reported it didn't worked.

https://gist.github.com/andris9/1978266#gistcomment-3929036

Interesting updates, please head into the original gist.

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