forked from Hopsan/hopsan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetGitInfo.sh
executable file
·39 lines (33 loc) · 917 Bytes
/
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
#!/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
date -d @`git log -n1 --pretty=format:%ct -- $dir` +%Y%m%d
exit $?
elif [ "$1" == "date.time" ]; then
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}
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