From dd227d103448274e1142119c0c9f657dcfc2ad18 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Wed, 13 Nov 2013 11:49:47 -0500 Subject: 'untouchcores' target (see README) --- contrib/git_untouch.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 contrib/git_untouch.sh (limited to 'contrib/git_untouch.sh') diff --git a/contrib/git_untouch.sh b/contrib/git_untouch.sh new file mode 100755 index 0000000..c9d3ede --- /dev/null +++ b/contrib/git_untouch.sh @@ -0,0 +1,40 @@ +#!/bin/bash -e + +# From http://stackoverflow.com/questions/1964470/whats-the-equivalent-of-use-commit-times-for-git +# Modified to only run on files passed on command line + +OS=${OS:-`uname`} + +get_file_rev() { + git rev-list -n 1 HEAD "$1" +} + +if [ "$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 + update_file_timestamp() { + file_time=`git show --pretty=format:%ai --abbrev-commit "$(get_file_rev "$1")" | head -n 1` + touch -d "$file_time" "$1" + } +fi + +OLD_IFS=$IFS +IFS=$'\n' + +for file in $@ +do + if [ ! `git status --ignored --porcelain $file` ] + then + update_file_timestamp "$file" + fi +done + +IFS=$OLD_IFS + +git update-index --refresh &> /dev/null || true + +exit 0 -- cgit v1.2.3