From d4b630bf7d62a323c4d1424d0c79b7b841603e05 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 29 Sep 2015 17:00:14 +0200 Subject: [PATCH 1/4] Possible to have dots in branch name --- gitstatus.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 5416fec..ebebd8d 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -50,8 +50,9 @@ if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed = clean=1 fi -IFS="." read -ra line <<< "${branch_line/\#\# }" -branch="${line[0]}" +branch="${branch_line#\#\# }" +branch="${branch%\.\.\.*}" +remote_branch_and_diff="${branch_line#*\.\.\.}" remote= if [[ "$branch" == *"Initial commit on"* ]]; then @@ -66,10 +67,10 @@ elif [[ "$branch" == *"no branch"* ]]; then branch="_PREHASH_$( git rev-parse --short HEAD )" fi else - if [[ "${#line[@]}" -eq 1 ]]; then + if [[ "${remote_branch_and_diff}" == "${branch_line}" ]]; then remote="_NO_REMOTE_TRACKING_" else - IFS="[,]" read -ra remote_line <<< "${line[3]}" + IFS="[,]" read -ra remote_line <<< "${remote_branch_and_diff}" for rline in "${remote_line[@]}"; do if [[ "$rline" == *ahead* ]]; then num_ahead=${rline:6} From 73f3cb75d19f586e8baca0347d93e6c70a3814f6 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Tue, 29 Sep 2015 15:44:25 -0500 Subject: [PATCH 2/4] Handle branches with dots in them --- gitstatus.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 5416fec..3343889 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -27,7 +27,7 @@ num_untracked=0 while IFS='' read -r line || [[ -n "$line" ]]; do status=${line:0:2} case "$status" in - \#\#) branch_line="$line" ;; + \#\#) branch_line="${line/\.\.\./^}" ;; ?M) ((num_changed++)) ;; U?) ((num_conflicts++)) ;; \?\?) ((num_untracked++)) ;; @@ -50,13 +50,13 @@ if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed = clean=1 fi -IFS="." read -ra line <<< "${branch_line/\#\# }" -branch="${line[0]}" +IFS="^" read -ra branch_fields <<< "${branch_line/\#\# }" +branch="${branch_fields[0]}" remote= if [[ "$branch" == *"Initial commit on"* ]]; then - IFS=" " read -ra branch_line <<< "$branch" - branch="${branch_line[3]}" + IFS=" " read -ra fields <<< "$branch" + branch="${fields[3]}" remote="_NO_REMOTE_TRACKING_" elif [[ "$branch" == *"no branch"* ]]; then tag=$( git describe --exact-match ) @@ -66,10 +66,10 @@ elif [[ "$branch" == *"no branch"* ]]; then branch="_PREHASH_$( git rev-parse --short HEAD )" fi else - if [[ "${#line[@]}" -eq 1 ]]; then + if [[ "${#branch_fields[@]}" -eq 1 ]]; then remote="_NO_REMOTE_TRACKING_" else - IFS="[,]" read -ra remote_line <<< "${line[3]}" + IFS="[,]" read -ra remote_line <<< "${branch_fields[1]}" for rline in "${remote_line[@]}"; do if [[ "$rline" == *ahead* ]]; then num_ahead=${rline:6} From dedb19180bb4ab8570425074752535f37528a480 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Tue, 29 Sep 2015 18:10:16 -0500 Subject: [PATCH 3/4] fix issue with parsing ahead/behind --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index e30d29e..3343889 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -69,7 +69,7 @@ else if [[ "${#branch_fields[@]}" -eq 1 ]]; then remote="_NO_REMOTE_TRACKING_" else - IFS="[,]" read -ra remote_line <<< "${line[3]}" + IFS="[,]" read -ra remote_line <<< "${branch_fields[1]}" for rline in "${remote_line[@]}"; do if [[ "$rline" == *ahead* ]]; then num_ahead=${rline:6} From ca7a848ca4efb8cfabb7275bfdbf469b08faa367 Mon Sep 17 00:00:00 2001 From: oGre Date: Wed, 30 Sep 2015 16:34:09 +0200 Subject: [PATCH 4/4] Renamed array variable to _fields to comply with the other arrays --- gitstatus.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 3343889..9f345e5 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -69,14 +69,14 @@ else if [[ "${#branch_fields[@]}" -eq 1 ]]; then remote="_NO_REMOTE_TRACKING_" else - IFS="[,]" read -ra remote_line <<< "${branch_fields[1]}" - for rline in "${remote_line[@]}"; do - if [[ "$rline" == *ahead* ]]; then - num_ahead=${rline:6} + IFS="[,]" read -ra remote_fields <<< "${branch_fields[1]}" + for remote_field in "${remote_fields[@]}"; do + if [[ "$remote_field" == *ahead* ]]; then + num_ahead=${remote_field:6} ahead="_AHEAD_${num_ahead}" fi - if [[ "$rline" == *behind* ]]; then - num_behind=${rline:7} + if [[ "$remote_field" == *behind* ]]; then + num_behind=${remote_field:7} behind="_BEHIND_${num_behind# }" fi done