Skip to content

Instantly share code, notes, and snippets.

@BR0kEN-
Last active August 11, 2019 22:37
Show Gist options
  • Save BR0kEN-/33872aabf8c2f83ec4d4 to your computer and use it in GitHub Desktop.
Save BR0kEN-/33872aabf8c2f83ec4d4 to your computer and use it in GitHub Desktop.
Per-user repository statistic (commits, additions and deletions counter)
#!/usr/bin/env bash
set -e
BRANCH="$1"
IFS="|"
# Show help.
if [ "help" == "$BRANCH" ]; then
echo "$0 BRANCH"
exit 0
fi
: "${BRANCH:="master"}"
# Ensure that we're inside of directory with initialized Git repository.
git status > /dev/null
# Check local branch existence.
git rev-parse --verify "$BRANCH" > /dev/null
echo "Statistics for \"$BRANCH\":"
for DATA in $(git shortlog -sn --no-merges "$BRANCH" | awk 'BEGIN {FS = "\t"}; {print $1 "+" $2 "|"}'); do
DATA=$(echo "$DATA" | xargs)
COMMITS="${DATA%+*}"
USERNAME="${DATA#*+}"
echo "------------------------------------------------------------------"
echo "$USERNAME ($COMMITS commits)"
git log --author="$USERNAME" --shortstat | awk '/^ [0-9]/ {f += $1; i += $4; d += $6} \
END {printf("%d files changed, %d insertions(+), %d deletions(-)", f, i, d)}'
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment