-
-
Save adzenith/fad626b625770771d551c6a34e7d74c7 to your computer and use it in GitHub Desktop.
Get number of lines added and deleted per day from your git repo
This file contains hidden or 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 | |
usage() { | |
echo "Usage: $0 BRANCH NUM_DAYS" | |
exit 1 | |
} | |
ds() { | |
date --date="$1 days ago" +%Y-%m-%d | |
} | |
if [ $# -lt 2 ] ; then | |
usage | |
fi | |
BRANCH=$1 | |
NUM_DAYS=$2 | |
if ! git rev-parse --verify $BRANCH ; then | |
echo "Branch with name '$BRANCH' does not exist" | |
echo | |
usage | |
fi | |
echo "Date,LinesAdded,LinesDeleted" | |
for day in $(seq 1 $NUM_DAYS) | |
do | |
lines=$(git --no-pager log --after=$(ds $day) --before=$(ds $(($day - 1))) --format=format: --numstat $BRANCH | awk '{s+=$1; t+=$2;} END {printf "+%s,-%s",s,t}') | |
if [[ "$lines" != "+,-" ]]; then | |
echo "$(ds $day),$lines" | |
else | |
echo "$(ds $day),0,0" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment