~kris/dots

srice

ref: e98f3b030dc24445bd55c68d95d2d81933fd68b3 srice/.local/bin/gitstat -rw-r--r-- 1.4 KiB
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago
                                                                                
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
#!/bin/sh
# gitstat -- quick git project health overview
# Usage: gitstat [path]

dir="${1:-.}"
cd "$dir" 2>/dev/null || { echo "Not a directory: $dir"; exit 1; }
git rev-parse --git-dir >/dev/null 2>&1 || { echo "Not a git repo: $dir"; exit 1; }

branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
remote=$(git rev-parse --abbrev-ref '@{upstream}' 2>/dev/null || echo "none")
ahead=$(git rev-list --count '@{upstream}'..HEAD 2>/dev/null || echo "?")
behind=$(git rev-list --count 'HEAD..@{upstream}' 2>/dev/null || echo "?")
staged=$(git diff --cached --numstat 2>/dev/null | wc -l)
unstaged=$(git diff --numstat 2>/dev/null | wc -l)
untracked=$(git ls-files --others --exclude-standard 2>/dev/null | wc -l)
last_commit=$(git log -1 --format='%ar - %s' 2>/dev/null)
total_commits=$(git rev-list --count HEAD 2>/dev/null)
contributors=$(git shortlog -sn --all 2>/dev/null | wc -l)

printf "Branch:       %s\n" "$branch"
printf "Tracking:     %s\n" "$remote"
printf "Ahead/Behind: +%s / -%s\n" "$ahead" "$behind"
printf "Staged:       %s files\n" "$staged"
printf "Unstaged:     %s files\n" "$unstaged"
printf "Untracked:    %s files\n" "$untracked"
printf "Last commit:  %s\n" "$last_commit"
printf "Total:        %s commits by %s contributors\n" "$total_commits" "$contributors"

if [ "$unstaged" -gt 0 ] || [ "$staged" -gt 0 ] || [ "$untracked" -gt 0 ]; then
    echo "---"
    git status -sb
fi