|
|
|
|
@ -19,26 +19,27 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then |
|
|
|
|
__GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
gitsym=`git symbolic-ref HEAD` |
|
|
|
|
branch=$( git rev-parse --abbrev-ref HEAD ) |
|
|
|
|
|
|
|
|
|
# if "fatal: Not a git repo .., then exit |
|
|
|
|
case "$gitsym" in fatal*) exit 0 ;; esac |
|
|
|
|
#If error code we are not in a repo - exit |
|
|
|
|
if [[ $? != 0 ]]; then exit 0; fi |
|
|
|
|
|
|
|
|
|
# the current branch is the tail end of the symbolic reference |
|
|
|
|
branch="${gitsym##refs/heads/}" # get the basename after "refs/heads/" |
|
|
|
|
#If we are detached, branch name will be HEAD |
|
|
|
|
if [[ "$branch" == "HEAD" ]]; then |
|
|
|
|
unset branch |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
gitstatus=`git diff --name-status 2>&1` |
|
|
|
|
gitstatus=$( git diff --name-status 2>&1 ) |
|
|
|
|
|
|
|
|
|
# if the diff is fatal, exit now |
|
|
|
|
case "$gitstatus" in fatal*) exit 0 ;; esac |
|
|
|
|
|
|
|
|
|
if [[ $? != 0 ]]; then exit 0; fi |
|
|
|
|
|
|
|
|
|
staged_files=`git diff --staged --name-status` |
|
|
|
|
staged_files=$( git diff --staged --name-status ) |
|
|
|
|
|
|
|
|
|
num_changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` )) |
|
|
|
|
num_conflicts=`count_lines "$staged_files" U` |
|
|
|
|
num_staged=$(( `all_lines "$staged_files"` - num_conflicts )) |
|
|
|
|
num_untracked=`git ls-files --others --exclude-standard $(git rev-parse --show-cdup) | wc -l` |
|
|
|
|
num_changed=$(( $( all_lines "$gitstatus" ) - $( count_lines "$gitstatus" U ) )) |
|
|
|
|
num_conflicts=$( count_lines "$staged_files" U ) |
|
|
|
|
num_staged=$(( $( all_lines "$staged_files" ) - num_conflicts )) |
|
|
|
|
num_untracked=$( git ls-files --others --exclude-standard $(git rev-parse --show-cdup) | wc -l ) |
|
|
|
|
|
|
|
|
|
num_stashed=0 |
|
|
|
|
if [[ "$__GIT_PROMPT_IGNORE_STASH" != "1" ]]; then |
|
|
|
|
@ -56,19 +57,20 @@ if (( num_changed == 0 && num_staged == 0 && num_U == 0 && num_untracked == 0 && |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
remote= |
|
|
|
|
upstream= |
|
|
|
|
|
|
|
|
|
if [[ -z "$branch" ]]; then |
|
|
|
|
tag=`git describe --exact-match` |
|
|
|
|
tag=$( git describe --exact-match 2>/dev/null ) |
|
|
|
|
if [[ -n "$tag" ]]; then |
|
|
|
|
branch="$tag" |
|
|
|
|
else |
|
|
|
|
branch="_PREHASH_`git rev-parse --short HEAD`" |
|
|
|
|
branch="_PREHASH_$( git rev-parse --short HEAD )" |
|
|
|
|
fi |
|
|
|
|
else |
|
|
|
|
remote_name=`git config branch.${branch}.remote` |
|
|
|
|
remote_name=$( git config branch.${branch}.remote ) |
|
|
|
|
|
|
|
|
|
if [[ -n "$remote_name" ]]; then |
|
|
|
|
merge_name=`git config branch.${branch}.merge` |
|
|
|
|
merge_name=$( git config branch.${branch}.merge ) |
|
|
|
|
else |
|
|
|
|
remote_name='origin' |
|
|
|
|
merge_name="refs/heads/${branch}" |
|
|
|
|
@ -81,18 +83,20 @@ else |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# detect if the local branch have a remote tracking branch |
|
|
|
|
cmd_output=$(git rev-parse --abbrev-ref ${branch}@{upstream} 2>&1 >/dev/null) |
|
|
|
|
upstream=$( git rev-parse --abbrev-ref ${branch}@{upstream} 2>&1 ) |
|
|
|
|
|
|
|
|
|
if [[ $? == 0 ]]; then |
|
|
|
|
has_remote_tracking=1 |
|
|
|
|
else |
|
|
|
|
has_remote_tracking=0 |
|
|
|
|
unset upstream |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# get the revision list, and count the leading "<" and ">" |
|
|
|
|
revgit=`git rev-list --left-right ${remote_ref}...HEAD` |
|
|
|
|
num_revs=`all_lines "$revgit"` |
|
|
|
|
num_ahead=`count_lines "$revgit" "^>"` |
|
|
|
|
revgit=$( git rev-list --left-right ${remote_ref}...HEAD 2>/dev/null ) |
|
|
|
|
if [[ $? == 0 ]]; then |
|
|
|
|
num_revs=$( all_lines "$revgit" ) |
|
|
|
|
num_ahead=$( count_lines "$revgit" "^>" ) |
|
|
|
|
num_behind=$(( num_revs - num_ahead )) |
|
|
|
|
if (( num_behind > 0 )) ; then |
|
|
|
|
remote="${remote}_BEHIND_${num_behind}" |
|
|
|
|
@ -100,6 +104,7 @@ else |
|
|
|
|
if (( num_ahead > 0 )) ; then |
|
|
|
|
remote="${remote}_AHEAD_${num_ahead}" |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
if [[ -z "$remote" ]] ; then |
|
|
|
|
@ -110,9 +115,14 @@ if [[ "$has_remote_tracking" == "0" ]] ; then |
|
|
|
|
remote='_NO_REMOTE_TRACKING_' |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ |
|
|
|
|
if [[ -z "$upstream" ]] ; then |
|
|
|
|
upstream='^' |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ |
|
|
|
|
"$branch" \ |
|
|
|
|
"$remote" \ |
|
|
|
|
"$upstream" \ |
|
|
|
|
$num_staged \ |
|
|
|
|
$num_conflicts \ |
|
|
|
|
$num_changed \ |
|
|
|
|
|