Skip to content

Instantly share code, notes, and snippets.

@gorenje
Created July 10, 2013 08:07
Show Gist options
  • Save gorenje/5964348 to your computer and use it in GitHub Desktop.
Save gorenje/5964348 to your computer and use it in GitHub Desktop.
parse_git_branch ()
{
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
local a="";
lb=${ref#refs/heads/};
local ro=$(git config --get branch.${lb}.remote || echo "origin");
local rb=$(git config --get branch.${lb}.merge);
rb=${rb#refs/heads/};
local ab=;
if [ "" != "${rb}" ]; then
ab="(+$(git log --pretty=format:%H ${ro}/${rb}..${lb} | wc -w | sed s'/ //'g))";
if [ "(+0)" = "${ab}" ]; then
ab="(-$(git log --pretty=format:%H ${lb}..${ro}/${rb} | wc -w | sed s'/ //'g))";
fi;
if [ "(-0)" = "${ab}" ]; then
ab="";
fi;
fi;
echo "("${ref#refs/heads/}")${ab}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment