forked from OpenGamma/OG-Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitstats.sh
executable file
·86 lines (76 loc) · 1.65 KB
/
gitstats.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
usage() {
echo "Usage: `basename $0` [-f] directory"
exit 1
}
while getopts ":f" opt; do
case $opt in
f)
RUNFETCH=yes
;;
\?)
usage
;;
esac
done
shift $((OPTIND-1))
if [ $# != 1 ]; then
usage
fi
upstream() {
count="$(git rev-list --count --left-right @{upstream}...HEAD 2>/dev/null)"
regex="(.*) (.*)"
if [[ "$count" =~ $regex ]]; then
#echo "$BASH_REMATCH"
ucount="${BASH_REMATCH[1]}"
lcount="${BASH_REMATCH[2]}"
printf "%8.8s %8.8s" "$ucount" "$lcount"
else
printf "%8.8s %8.8s" "-" "-"
fi
return
}
lsuntrackedfiles() {
printf "%10.10s" $(git ls-files --others --exclude-standard| wc -l)
}
showbranch() {
local b=''
b=$(git symbolic-ref -q HEAD) || b='(detached HEAD)'
b=${b##refs/heads/}
printf "%-15.15s" "${b}"
}
showstaged() {
local w=''
local i=''
git diff --no-ext-diff --quiet --exit-code || w='*'
if git rev-parse --quiet --verify HEAD >/dev/null; then
git diff-index --cached --quiet HEAD -- || i='+'
else
i='#'
fi
printf "%10.10s" "${w}${i}"
}
printf "%-25.25s" "Path"
printf "%-15.15s" "branch"
printf "%10.10s" "stage"
printf "%10.10s" "untracked"
printf "%8.8s %8.8s" "origin" "local"
echo
find "${1}" -name .git -type d -print0 | while read -r -d $'\0' gitdirs
do
project=`dirname "$gitdirs"`
# Not needed really"
if [ -d "${project}" -a -d "${project}/.git" ]; then
pushd "${project}" >/dev/null;
if [ ! -z $RUNFETCH ]; then
git fetch -q > /dev/null >& /dev/null
fi
printf "%-25.25s" "$(basename "${project}")"
showbranch
showstaged
lsuntrackedfiles
upstream
echo
popd >/dev/null
fi
done