Skip to content

Instantly share code, notes, and snippets.

@mdiener21
Created January 31, 2021 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdiener21/00d9174e66c41968e38f34763dbd7477 to your computer and use it in GitHub Desktop.
Save mdiener21/00d9174e66c41968e38f34763dbd7477 to your computer and use it in GitHub Desktop.
print to sdout user git merge info
#!/bin/bash -e
set -o pipefail
# Any arguments are incorrect. Note that git intercepts --help and tries to
# open the man page.
if [ $# -gt 0 ]; then
echo 'Usage: git merge-stats'
exit 1
fi
echo "% of Total Merges Author # of Merges % of Commits"
# Use --first-parent to only count merges into the current branch; this gets
# rid of commits where you merge upstream into your feature branch.
mergeCounts=`git log --first-parent --merges --pretty='format:%an' | sort | uniq -c | sort -nr`
totalMerges=`git log --first-parent --merges --oneline | wc -l`
if [ $totalMerges -eq 0 ]; then
echo 'No merges found.'
exit 0
fi
while read -r line; do
authorMerges=`awk '{print $1}' <<< "$line"`
author=`sed "s/$authorMerges //" <<< "$line"`
authorCommits=`git log --oneline --author="$author" | wc -l`
totalPercentage=`echo "scale=2; (100*$authorMerges) / $totalMerges" | bc`
authorPercentage=`echo "scale=2; (100*$authorMerges) / $authorCommits" | bc`
printf "%17.2f %20s %12i %13.2f\n" "$totalPercentage" "$author" "$authorMerges" "$authorPercentage"
done <<< "$mergeCounts"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment