forked from Hopsan/hopsan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getGitInfo.sh
executable file
·52 lines (47 loc) · 1.41 KB
/
getGitInfo.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
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
if [[ $# -lt 2 ]]; then
dir="."
fi
if [[ -d "$2" ]]; then
dir="$2"
elif [[ -f "$2" ]]; then
dir="$2"
else
echo Error $2 is not a file or directory
exit 1
fi
if [[ "$1" == "shorthash" ]]; then
git log -n1 --pretty=format:%h -- $dir
exit $?
elif [[ "$1" == "date" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
# date is one of those system commands that differes on BSD-clones, /magse
date -j -f %s `git log -n1 --pretty=format:%ct -- $dir` +%Y%m%d
exit $?
else
date -d @`git log -n1 --pretty=format:%ct -- $dir` +%Y%m%d
exit $?
fi
elif [[ "$1" == "date.time" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
commitdate=$(date -j -f %s `git log -n1 --pretty=format:%ct -- $dir` +%Y%m%d)
committime=$(date -j -f %s `git log -n1 --pretty=format:%ct -- $dir` +%H%M)
ret_code=$?
echo ${commitdate}.${committime}
exit ${ret_code}
else
commitdate=$(date -d @`git log -n1 --pretty=format:%ct -- $dir` +%Y%m%d)
committime=$(date -d @`git log -n1 --pretty=format:%ct -- $dir` +%H%M)
ret_code=$?
echo ${commitdate}.${committime}
exit ${ret_code}
fi
else
echo Incorrect request: $1
exit 1
fi
#git log --pretty=format:%cd --date=format:'%Y%m%d' -- $dir
#commitdate=`git log -n1 --pretty=format:%cd --date=short -- $dir`
#echo ${commitdate//-/}
#git log -n1 --pretty=format:%cd -- $dir
#date -d @`git log -n1 --pretty=format:%ct -- $dir` +%Y%m%d%H%M