Created
February 1, 2017 07:49
-
-
Save mathewjosephh/d3d8b2073c670e81d8f5d344e271f027 to your computer and use it in GitHub Desktop.
Git get commit count Files changed (total), Lines added (total), Lines deleted (total), Total lines (delta)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
dir="$1" | |
# No directory has been provided, use current | |
if [ -z "$dir" ] | |
then | |
dir="`pwd`" | |
fi | |
# Make sure directory ends with "/" | |
if [[ $dir != */ ]] | |
then | |
dir="$dir/*" | |
else | |
dir="$dir*" | |
fi | |
#set the headers | |
echo 'Repo Name, Commits, Files changed (total), Lines added (total), Lines deleted (total), Total lines (delta), Folder Path' >> /var/www/test.csv | |
# Loop all sub-directories | |
for f in $dir | |
do | |
# Only interested in directories | |
[ -d "${f}" ] || continue | |
echo "${f}" | |
# Check if directory is a git repository | |
if [ -d "$f/.git" ] | |
then | |
cd $f | |
#get reponame | |
reponame=`git remote -v | head -n1 | awk '{print $2}' | sed -e 's,.*:\(.*/\)\?,,' -e 's/\.git$//'` | |
#get commits | |
repocommits=`git rev-list --all --count` | |
#get Files changed (total), Lines added (total), Lines deleted (total), Total lines (delta) | |
repocount=`git log --shortstat | grep -E "fil(e|es) changed" | awk '{files+=$1; inserted+=$4; deleted+=$6; delta+=$4-$6} END {printf "%s,%s,%s,%s", files, inserted, deleted, delta }'` | |
echo $reponame,$repocommits,$repocount,$f >> /var/www/test.csv | |
cd ../ | |
else | |
echo "Not a git repository" | |
fi | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment