-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-touch.sh
executable file
·42 lines (35 loc) · 1012 Bytes
/
git-touch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash -e
###############################################################################
# PURPOSE: Update all file timestamps to the original timestamp on
# pulled target git repository
#
# RETURNS: 0 - OK
# 1 - error
#
# USAGE:
# WHERE:
#
# BORROWED/ADAPTED FROM:
# http://stackoverflow.com/questions/1964470/whats-the-equivalent-of-use-commit-times-for-git
# https://copyprogramming.com/howto/git-commit-only-timestamp-modification-of-a-file
#
# CHANGES: DCD at TRIUMF:
# - modified to test for file existance before updating timestamp
# - removed get_file_rev fnc, and use git-log instead of git-show
###############################################################################
unalias -a
PATH=/usr/bin:/bin
update_file_timestamp() {
file_time=$(git log -1 --pretty=format:%ai "$1")
touch -d "$file_time" "$1"
}
OLD_IFS=$IFS
IFS=$'\n'
for file in `git ls-files`
do
if [ -f "$file" ] ; then
update_file_timestamp "$file"
fi
done
IFS=$OLD_IFS
git update-index --refresh