diff options
| -rwxr-xr-x | git-sonar | 81 |
1 files changed, 29 insertions, 52 deletions
@@ -69,12 +69,9 @@ branch_name() { } remote_branch_name() { - local localRef - local remote localRef="$(branch_name)" remote="$(git config --get "branch.${localRef}.remote")" if [ -n "$remote" ]; then - local remoteBranch remoteBranch="$(git config --get "branch.${localRef}.merge" | sed -e 's/^refs\/heads\///')" if [ -n "$remoteBranch" ]; then printf '%s/%s' "$remote" "$remoteBranch" @@ -145,17 +142,11 @@ porcelain_status() { } staged_status() { - local gitStatus=${1:-"$(porcelain_status)"} - local prefix=${2:-""} - local suffix=${3:-""} - - local staged_string="" - local filesModified - local filesAdded - local filesDeleted - local filesRenamed - local filesCopied - local typeChanged + gitStatus="${1:-"$(porcelain_status)"}" + prefix="${2:-""}" + suffix="${3:-""}" + staged_string="" + filesModified="$(printf '%s' "$gitStatus" | grep -oE "M[ACDRM ] " | wc -l | grep -oEi '[1-9][0-9]*')" filesAdded="$(printf '%s' "$gitStatus" | grep -oE "A[MCDR ] " | wc -l | grep -oEi '[1-9][0-9]*')" filesDeleted="$(printf '%s' "$gitStatus" | grep -oE "D[AMCR ] " | wc -l | grep -oEi '[1-9][0-9]*')" @@ -185,14 +176,11 @@ staged_status() { } conflicted_status() { - local gitStatus=${1:-"$(porcelain_status)"} - local prefix=${2:-""} - local suffix=${3:-""} - local conflicted_string="" - - local filesUs - local filesThem - local filesBoth + gitStatus="${1:-"$(porcelain_status)"}" + prefix="${2:-""}" + suffix="${3:-""}" + conflicted_string="" + filesUs="$(printf '%s' "$gitStatus" | grep -oE "[AD]U " | wc -l | grep -oEi '[1-9][0-9]*')" filesThem="$(printf '%s' "$gitStatus" | grep -oE "U[AD] " | wc -l | grep -oEi '[1-9][0-9]*')" filesBoth="$(printf '%s' "$gitStatus" | grep -oE "(UU|AA|DD) " | wc -l | grep -oEi '[1-9][0-9]*')" @@ -210,14 +198,11 @@ conflicted_status() { } unstaged_status() { - local gitStatus=${1:-"$(porcelain_status)"} - local prefix=${2:-""} - local suffix=${3:-""} - local unstaged_string="" - - local filesModified - local filesDeleted - local typeChanged + gitStatus="${1:-"$(porcelain_status)"}" + prefix="${2:-""}" + suffix="${3:-""}" + unstaged_string="" + filesModified="$(printf '%s' "$gitStatus" | grep -oE "[ACDRM ]M " | wc -l | grep -oEi '[1-9][0-9]*')" filesDeleted="$(printf '%s' "$gitStatus" | grep -oE "[AMCR ]D " | wc -l | grep -oEi '[1-9][0-9]*')" typeChanged="$(printf '%s' "$gitStatus" | grep -oE "[AMDR ]T " | wc -l | grep -oEi '[1-9][0-9]*')" @@ -235,12 +220,11 @@ unstaged_status() { } untracked_status() { - local gitStatus=${1:-"$(porcelain_status)"} - local prefix=${2:-""} - local suffix=${3:-""} - local untracked_string="" + gitStatus="${1:-"$(porcelain_status)"}" + prefix="${2:-""}" + suffix="${3:-""}" + untracked_string="" - local filesUntracked filesUntracked="$(printf '%s' "$gitStatus" | grep "?? " | wc -l | grep -oEi '[1-9][0-9]*')" if [ -n "$filesUntracked" ]; then @@ -250,17 +234,11 @@ untracked_status() { } color_changes_status() { - local separator="${1:- }" - - local porcelain + separator="${1:- }" porcelain="$(porcelain_status)" - local changes="" + changes="" if [ -n "$porcelain" ]; then - local staged_changes - local unstaged_changes - local untracked_changes - local conflicted_changes staged_changes="$(staged_status "$porcelain" "$COLOR_CHANGES_STAGED" "$RESET_COLOR_CHANGES")" unstaged_changes="$(unstaged_status "$porcelain" "$COLOR_CHANGES_UNSTAGED" "$RESET_COLOR_CHANGES")" untracked_changes="$(untracked_status "$porcelain" "$COLOR_CHANGES_UNTRACKED" "$RESET_COLOR_CHANGES")" @@ -287,11 +265,11 @@ color_changes_status() { } color_local_commits() { - local green_ahead_arrow="${COLOR_LOCAL_AHEAD}↑$RESET_COLOR_LOCAL" - local red_behind_arrow="${COLOR_LOCAL_BEHIND}↓$RESET_COLOR_LOCAL" - local yellow_diverged_arrow="${COLOR_LOCAL_DIVERGED}⇵$RESET_COLOR_LOCAL" + green_ahead_arrow="${COLOR_LOCAL_AHEAD}↑$RESET_COLOR_LOCAL" + red_behind_arrow="${COLOR_LOCAL_BEHIND}↓$RESET_COLOR_LOCAL" + yellow_diverged_arrow="${COLOR_LOCAL_DIVERGED}⇵$RESET_COLOR_LOCAL" + local_commits="" - local local_commits="" if remote_branch="$(remote_branch_name)"; then local_ahead="$(commits_ahead_of_remote "$remote_branch")" local_behind="$(commits_behind_of_remote "$remote_branch")" @@ -308,7 +286,7 @@ color_local_commits() { } color_missing_upstream() { - local not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE" + not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE" if remote_branch="$(remote_branch_name)"; then if ! git rev-parse "$remote_branch" -- >/dev/null 2>&1; then @@ -318,9 +296,9 @@ color_missing_upstream() { } color_remote_commits() { - local green_ahead_arrow="${COLOR_REMOTE_AHEAD}↑$RESET_COLOR_REMOTE" # "←" - local red_behind_arrow="${COLOR_REMOTE_BEHIND}↓$RESET_COLOR_REMOTE" # "→" - local yellow_diverged_arrow="${COLOR_REMOTE_DIVERGED}⇵$RESET_COLOR_REMOTE" # "⇄" + green_ahead_arrow="${COLOR_REMOTE_AHEAD}↑$RESET_COLOR_REMOTE" # "←" + red_behind_arrow="${COLOR_REMOTE_BEHIND}↓$RESET_COLOR_REMOTE" # "→" + yellow_diverged_arrow="${COLOR_REMOTE_DIVERGED}⇵$RESET_COLOR_REMOTE" # "⇄" remote="" if remote_branch="$(remote_branch_name)"; then @@ -348,7 +326,6 @@ stashed_status() { } stash_status() { - local number_stashes number_stashes="$(stashed_status)" if [ "$number_stashes" -gt 0 ]; then printf $PRINT_F_OPTION "${number_stashes}${COLOR_STASH}≡${RESET_COLOR_STASH}" |
