diff options
| -rwxr-xr-x | git-sonar | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -52,7 +52,7 @@ prepare_colors() { COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH:-"\\033[0m"}\x02" MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"\\x01\\033[0m\\x02\\xF0\\x9D\\x98\\xAE\\x01\\033[0m\\x02"}" - PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{condition}%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :stash}%{ :changes}"}" + PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{condition}%{missingups}%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :stash}%{ :changes}"}" RESET_COLOR_LOCAL="\x01${GIT_RADAR_COLOR_LOCAL_RESET:-"\\033[0m"}\x02" RESET_COLOR_REMOTE="\x01${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}\x02" @@ -372,11 +372,20 @@ color_local_commits() { printf $PRINT_F_OPTION "$local_commits" } +color_missing_upstream() { + local 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 + printf "$not_upstream" + fi + fi +} + 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" - local not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE" if remote_branch="$(remote_branch_name)"; then remote_ahead="$(remote_ahead_of_master "$remote_branch")" @@ -389,8 +398,6 @@ color_remote_commits() { elif [[ "$remote_behind" -gt "0" ]]; then remote="$MASTER_SYMBOL $remote_behind $red_behind_arrow" fi - else - remote="upstream $not_upstream" fi printf $PRINT_F_OPTION "$remote" @@ -438,6 +445,14 @@ render_prompt() { condition_sed="s/${sed_pre}condition${sed_post}//" fi fi + if [[ $PROMPT_FORMAT =~ ${if_pre}missingups${if_post} ]]; then + missingups_result="$(color_missing_upstream)" + if [[ -n "$missingups_result" ]]; then + missingups_sed="s/${sed_pre}missingups${sed_post}/\2${missingups_result}\4/" + else + missingups_sed="s/${sed_pre}missingups${sed_post}//" + fi + fi if [[ $PROMPT_FORMAT =~ ${if_pre}remote${if_post} ]]; then remote_result="$(color_remote_commits)" if [[ -n "$remote_result" ]]; then @@ -481,6 +496,7 @@ render_prompt() { printf '%b' "$PROMPT_FORMAT" | sed \ -e "$condition_sed" \ + -e "$missingups_sed" \ -e "$remote_sed" \ -e "$branch_sed" \ -e "$changes_sed" \ |
