-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-status
executable file
·46 lines (39 loc) · 1.17 KB
/
git-status
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
#!/bin/bash
# recursively checks directories to see whether they're git repositories
# if so, the repo is checked to see whether there are unpushed commits
RES=""
my_ls() {
# save current directory then cd to "$1"
pushd "$1" >/dev/null
if find . -maxdepth 1 | grep -q "^./.git$" ; then
if git remote | grep -q "origin"; then
BRANCH=$(git branch | grep "\*" | cut -c 3-)
CNT=$(git shortlog origin/master.."$BRANCH" -s | grep -o -E '[0-9]+')
AUTHORS=$(echo "$CNT" | wc -l)
TOTAL=$(echo "$CNT" | tr '\n' '+' | sed -e "s/+$//g")
TOTAL=$(echo "$TOTAL" | bc) # `bc` in the pipe above leads to a syntax error
if [ "$CNT" ]; then
REPO=$(basename "$PWD")
if [ "$AUTHORS" -eq 1 ]; then
RES="$RES"$'\n'$REPO": $CNT commits"
else
RES="$RES"$'\n'$REPO": $TOTAL commits ($AUTHORS authors)"
fi
fi
fi
elif find . -maxdepth 1 | grep -q "^./.hg$" ; then
echo "ignoring mercurial repos" > /dev/null
else
for file in * ; do
if [[ -d "$file" ]]; then
my_ls "$file"
fi
done
fi
# restore directory
popd >/dev/null
}
my_ls "$1"
if [ "$RES" ]; then
echo "${RES:1}"
fi