fixed a bug : stand alone expression was failing
[ikh.git] / git / git-update-timestamp
blob851ca7a52a71454d03607b72754bcf9ea89bac49
1 #!/bin/sh -e
3 OS=${OS:-`uname`}
4 rev="${1-HEAD}"
5 pattern="${2-*}"
7 #echo "git-update-timestamp: '$OS', '$rev', '$pattern'"
9 get_file_rev() {
10 git rev-list "$rev" "$1" | head -n 1
13 report() {
14 echo "$2 $1"
17 if [ "$OS" = 'Linux' ]
18 then
19 update_file_timestamp() {
20 file_time=`git show --pretty=format:%ai --abbrev-commit "$(get_file_rev "$1")" | head -n 1`
21 touch -d "$file_time" "$1"
22 report "$1" "$file_time"
24 elif [ "$OS" = 'FreeBSD' ]
25 then
26 update_file_timestamp() {
27 file_time=`date -r "$(git show --pretty=format:%at --abbrev-commit "$(get_file_rev "$1")" | head -n 1)" '+%Y%m%d%H%M.%S'`
28 touch -h -t "$file_time" "$1"
29 report "$1" "$file_time"
31 elif [ "$OS" = 'Darwin' ]
32 then
33 update_file_timestamp() {
34 file_time=`date -j -f '%s' "$(git show --pretty=format:%at --abbrev-commit "$(get_file_rev "$1")" | head -n 1)" '+%Y%m%d%H%M.%S'`
35 #stat -t '%Y%m%d%H%M.%S' -f "stat1: %Sa %Sm %Sc %i %N" "$1"
36 touch -t "$file_time" "$1"
37 report "$1" "$file_time"
38 #stat -t '%Y%m%d%H%M.%S' -f "stat2: %Sa %Sm %Sc %i %N" "$1"
40 else
41 echo "error: timestamp fix not implemented for $OS" >&2
42 exit 1
45 for file in `git ls-files "$pattern"`
47 update_file_timestamp "$file"
48 done