Created
September 2, 2014 17:32
-
-
Save stilist/c01cdc3568f677de5cf5 to your computer and use it in GitHub Desktop.
line count change for current git branch
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
function parse_git_branch () { | |
local git_status="`git status -unormal 2>&1`" | |
# http://toucware.blogspot.com/2012/05/partial-string-matching-in-bash.html | |
# | |
# TODO Catch case when repo is initialized but not committed. | |
if [[ "$git_status" == fatal* ]] ; then | |
echo "" | |
else | |
# http://stackoverflow.com/a/11958481/672403 | |
git rev-parse --symbolic-full-name --abbrev-ref HEAD | |
fi | |
} | |
# get line count relative to `upstream` | |
function branchstat () { | |
if [ "$#" -eq 0 ] ; then : | |
local upstream="master" | |
else | |
local upstream=$1 | |
fi | |
local branch="$(parse_git_branch)" | |
# http://www.cyberciti.biz/faq/linux-unix-appleosx-bsd-bash-passing-variables-to-awk/ | |
git log --numstat --pretty="%H" $upstream..$branch | awk -v branch=$branch -v upstream=$upstream 'NF==3 {plus+=$1; minus+=$2} END {printf("%s...%s: +%d, -%d, net %d\n", upstream, branch, plus, minus, (plus - minus))}' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment