Skip to content

Instantly share code, notes, and snippets.

@mathewjosephh
Created February 1, 2017 07:49
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 mathewjosephh/d3d8b2073c670e81d8f5d344e271f027 to your computer and use it in GitHub Desktop.
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)
#!/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