show the number of added/deleted lines, if changes have been made in a GIT repository

This commit is contained in:
nojhan 2012-08-04 19:52:24 +02:00
parent 6dea91ecf6
commit 20d2e909bc
2 changed files with 8 additions and 4 deletions

View File

@ -48,7 +48,8 @@ preserving the first two directories;
* the name of the current branch if you are in a version control repository * the name of the current branch if you are in a version control repository
(git, mercurial or subversion), in green if everything is up to date, in red if (git, mercurial or subversion), in green if everything is up to date, in red if
there is changes, in yellow if there is pending commits to push; there is changes, in yellow if there is pending commits to push;
* the number of pending commits, if any; * the number of added/deleted lines, if changes have been made and the number
of pending commits, if any;
* the error code of the last command, if it has failed in some way; * the error code of the last command, if it has failed in some way;
* a smart mark: ± for VCS directories, $ for simple user, a red # for root. * a smart mark: ± for VCS directories, $ for simple user, a red # for root.

View File

@ -454,6 +454,8 @@ __git_branch()
# - green if the repository is up to date # - green if the repository is up to date
# - yellow if there is some commits not pushed # - yellow if there is some commits not pushed
# - red if there is changes to commit # - red if there is changes to commit
#
# Add the number of pending commits and the impacted lines.
__git_branch_color() __git_branch_color()
{ {
command -v git >/dev/null 2>&1 || return 1; command -v git >/dev/null 2>&1 || return 1;
@ -470,11 +472,12 @@ __git_branch_color()
has_commit=0 has_commit=0
fi fi
if [[ "$GD" -eq 1 || "$GDC" -eq "1" ]] ; then if [[ "$GD" -eq 1 || "$GDC" -eq "1" ]] ; then
has_lines=$(git diff --numstat | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d/-%d\n", plus, minus)}')
if [[ "$has_commit" -gt "0" ]] ; then if [[ "$has_commit" -gt "0" ]] ; then
# changes to commit and commits to push # Changes to commit and commits to push
ret="${RED}${branch}${NO_COL}(${YELLOW}$has_commit${NO_COL})" ret="${RED}${branch}${NO_COL}(${RED}$has_lines${NO_COL}${YELLOW}$has_commit${NO_COL})"
else else
ret="${RED}${branch}${NO_COL}" # changes to commit ret="${RED}${branch}${NO_COL}(${RED}$has_lines${NO_COL})" # changes to commit
fi fi
else else
if [[ "$has_commit" -gt "0" ]] ; then if [[ "$has_commit" -gt "0" ]] ; then