Fix: Show only ahead/behind symbols when working directory is clean
All checks were successful
CI Pipeline / shasums (push) Successful in 6s
git-sync-with-mirror / git-sync (push) Successful in 10s
CI Pipeline / build (push) Successful in 1m24s
CI Pipeline / tests (push) Successful in 32s
CI Pipeline / performance (push) Successful in 8s

This commit is contained in:
2025-11-04 11:48:07 -05:00
parent aad97d949a
commit 9d2ca59258
2 changed files with 35 additions and 19 deletions

View File

@@ -7,12 +7,12 @@ _init_git_symbols() {
_colors_bash "$@" _colors_bash "$@"
GIT_SYMBOLS[pipe]="\x7C" GIT_SYMBOLS[pipe]="|"
GIT_SYMBOLS[clean]="" GIT_SYMBOLS[clean]=""
GIT_SYMBOLS[dirty]="" GIT_SYMBOLS[dirty]="*"
GIT_SYMBOLS[ahead]="↑" GIT_SYMBOLS[ahead]="↑"
GIT_SYMBOLS[behind]="↓" GIT_SYMBOLS[behind]="↓"
GIT_SYMBOLS[diverged]="" GIT_SYMBOLS[diverged]=""
GIT_SYMBOLS[untracked]="?" GIT_SYMBOLS[untracked]="?"
GIT_SYMBOLS[added]="+" GIT_SYMBOLS[added]="+"
GIT_SYMBOLS[deleted]="D" GIT_SYMBOLS[deleted]="D"
@@ -46,11 +46,20 @@ _parse_git_status() {
# Single git status call # Single git status call
status_output="$(git status --porcelain=v1 2>/dev/null)" status_output="$(git status --porcelain=v1 2>/dev/null)"
# Get ahead/behind counts in one call # Get ahead/behind counts - use more reliable method
if git rev-parse --abbrev-ref "@{upstream}" >/dev/null 2>&1; then if git rev-parse --abbrev-ref "@{upstream}" >/dev/null 2>&1; then
# Use separate commands for more reliable parsing
GIT_STATUS[ahead]="$(git rev-list --count HEAD ^"@{upstream}" 2>/dev/null || echo 0)"
GIT_STATUS[behind]="$(git rev-list --count "@{upstream}" ^HEAD 2>/dev/null || echo 0)"
# Fallback to original method if separate commands fail
if [[ "${GIT_STATUS[ahead]}" == "0" && "${GIT_STATUS[behind]}" == "0" ]]; then
ahead_behind="$(git rev-list --left-right --count "@{upstream}"...HEAD 2>/dev/null)" ahead_behind="$(git rev-list --left-right --count "@{upstream}"...HEAD 2>/dev/null)"
GIT_STATUS[behind]="${ahead_behind% *}" if [[ "$ahead_behind" =~ ^([0-9]+)[[:space:]]+([0-9]+)$ ]]; then
GIT_STATUS[ahead]="${ahead_behind#* }" GIT_STATUS[behind]="${BASH_REMATCH[1]}"
GIT_STATUS[ahead]="${BASH_REMATCH[2]}"
fi
fi
else else
GIT_STATUS[behind]=0 GIT_STATUS[behind]=0
GIT_STATUS[ahead]=0 GIT_STATUS[ahead]=0
@@ -107,30 +116,32 @@ _get_git_status_fast() {
local output="" local output=""
# Clean repo # Check if completely clean (no dirty files AND no ahead/behind)
if [[ ${GIT_STATUS[dirty]} -eq 0 ]]; then if [[ ${GIT_STATUS[dirty]} -eq 0 && ${GIT_STATUS[ahead]} -eq 0 && ${GIT_STATUS[behind]} -eq 0 ]]; then
echo -n "${BOLD}${CYAN}${GIT_SYMBOLS[clean]}${RESET}" echo -n "${BOLD}${CYAN}${GIT_SYMBOLS[clean]}${RESET}"
return return
fi fi
# Dirty count # Start with dirty indicator if there are dirty files
output="${BOLD}${RED}${GIT_SYMBOLS[dirty]}${GIT_STATUS[dirty]}${RESET}" if [[ ${GIT_STATUS[dirty]} -gt 0 ]]; then
output="${BOLD}${YELLOW}${GIT_SYMBOLS[dirty]}${GIT_STATUS[dirty]}${RESET}"
fi
# Ahead/behind # Add ahead/behind status with semantic colors
if [[ ${GIT_STATUS[ahead]} -gt 0 && ${GIT_STATUS[behind]} -gt 0 ]]; then if [[ ${GIT_STATUS[ahead]} -gt 0 && ${GIT_STATUS[behind]} -gt 0 ]]; then
output+="${BOLD}${YELLOW}${GIT_SYMBOLS[diverged]}${GIT_STATUS[ahead]}/${GIT_STATUS[behind]}${RESET}" output+="${BOLD}${ORANGE}${GIT_SYMBOLS[diverged]}${GIT_STATUS[ahead]}/${GIT_STATUS[behind]}${RESET}"
elif [[ ${GIT_STATUS[ahead]} -gt 0 ]]; then elif [[ ${GIT_STATUS[ahead]} -gt 0 ]]; then
output+="${BOLD}${GREEN}${GIT_SYMBOLS[ahead]}${GIT_STATUS[ahead]}${RESET}" output+="${BOLD}${GREEN}${GIT_SYMBOLS[ahead]}${GIT_STATUS[ahead]}${RESET}"
elif [[ ${GIT_STATUS[behind]} -gt 0 ]]; then elif [[ ${GIT_STATUS[behind]} -gt 0 ]]; then
output+="${BOLD}${RED}${GIT_SYMBOLS[behind]}${GIT_STATUS[behind]}${RESET}" output+="${BOLD}${RED}${GIT_SYMBOLS[behind]}${GIT_STATUS[behind]}${RESET}"
fi fi
# File status indicators # File status indicators with semantic colors
[[ ${GIT_STATUS[staged]} -gt 0 ]] && output+="${BOLD}${GREEN}${GIT_SYMBOLS[staged]}${RESET}" [[ ${GIT_STATUS[staged]} -gt 0 ]] && output+="${BOLD}${GREEN}${GIT_SYMBOLS[staged]}${RESET}"
[[ ${GIT_STATUS[untracked]} -gt 0 ]] && output+="${BOLD}${RED}${GIT_SYMBOLS[untracked]}${RESET}" [[ ${GIT_STATUS[untracked]} -gt 0 ]] && output+="${BOLD}${GREY}${GIT_SYMBOLS[untracked]}${RESET}"
[[ ${GIT_STATUS[added]} -gt 0 ]] && output+="${BOLD}${GREEN}${GIT_SYMBOLS[added]}${RESET}" [[ ${GIT_STATUS[added]} -gt 0 ]] && output+="${BOLD}${GREEN}${GIT_SYMBOLS[added]}${RESET}"
[[ ${GIT_STATUS[deleted]} -gt 0 ]] && output+="${BOLD}${RED}${GIT_SYMBOLS[deleted]}${RESET}" [[ ${GIT_STATUS[deleted]} -gt 0 ]] && output+="${BOLD}${RED}${GIT_SYMBOLS[deleted]}${RESET}"
[[ ${GIT_STATUS[renamed]} -gt 0 ]] && output+="${BOLD}${BLUE}${GIT_SYMBOLS[renamed]}${RESET}" [[ ${GIT_STATUS[renamed]} -gt 0 ]] && output+="${BOLD}${CYAN}${GIT_SYMBOLS[renamed]}${RESET}"
echo -n "$output" echo -n "$output"
} }
@@ -144,7 +155,12 @@ _prompt_get_git_info_fast() {
if [[ -n "$branch" ]]; then if [[ -n "$branch" ]]; then
local status local status
status="$(_get_git_status_fast "$@")" status="$(_get_git_status_fast "$@")"
printf '%b%s%s%b' "${BOLD}${YELLOW}" "git:($branch" "$status" "${BOLD}${YELLOW})" # Use different colors for different parts
printf '%bgit:(%b%s%b%s%b)%b' \
"${GREY}" \
"${BOLD}${LEMON}" "$branch" "${RESET}" \
"$status" \
"${GREY}" "${RESET}"
fi fi
} }

View File

@@ -2,7 +2,7 @@ cdfe049ec07f02a1893cda29c13085d06709e09a30b0c2e1111585278315f03139d61080c883cb3f
f363606f41a2c2c8f1cc44110c64fe23b1c8feb4c788ee006222db0f5c7a3adeac2b0948626b313adc985e9b8d303a0b9ce1c5ba42746810accb54efddcd4b84 ./hyperterm.sh f363606f41a2c2c8f1cc44110c64fe23b1c8feb4c788ee006222db0f5c7a3adeac2b0948626b313adc985e9b8d303a0b9ce1c5ba42746810accb54efddcd4b84 ./hyperterm.sh
b760a908a3f6222b974abc1f7464bde0f5427f120f1e7ef1c6d97ae61769e552ef3b5cb88e193e955da72a592f07eadb812413dd50a691cd3dbb33e3da581ea6 ./core/update.sh b760a908a3f6222b974abc1f7464bde0f5427f120f1e7ef1c6d97ae61769e552ef3b5cb88e193e955da72a592f07eadb812413dd50a691cd3dbb33e3da581ea6 ./core/update.sh
1cfba599047d84a17ff92b695ebf527a505a30acc9ec21a2b9f410a7ea6dde4b23b5cf62e557d82f2fe9a8980649942424b879ca53baae4d4cb3057681baa7b6 ./core/colors.sh 1cfba599047d84a17ff92b695ebf527a505a30acc9ec21a2b9f410a7ea6dde4b23b5cf62e557d82f2fe9a8980649942424b879ca53baae4d4cb3057681baa7b6 ./core/colors.sh
e3bacd715a327802c18de9b3c9f958f704eec4055295433403df284130e23f956f330bdf737c524bec3a89ef67a44ff0ab5dec40ffad5363aced3396bff54283 ./core/git.sh 9d5920540d17873ea79d8737d3450c3de895b1f4820d3fa4e09c03179ef6360960796340e65da8c397840749d5655e345b7aec41ea7c320659454b335e833ac8 ./core/git.sh
f3e00b2aa8ab9f3ab44570adaa2520408ed66fd00f551654d60b64a4be3546ec781b7efa39bcd774937e654b6ffb4c7af3f21eeb36caf9c01f82f85cf28e2b4d ./core/languages.sh f3e00b2aa8ab9f3ab44570adaa2520408ed66fd00f551654d60b64a4be3546ec781b7efa39bcd774937e654b6ffb4c7af3f21eeb36caf9c01f82f85cf28e2b4d ./core/languages.sh
b205de01644af11ef1dc96230e4bf12087482e26b7c0472fb6a153bf94662e4dfc01b2da0c3ca0da4af93bce05faf0e33be5422fbee85e6b69ca1cccbe194cff ./core/autodep.sh b205de01644af11ef1dc96230e4bf12087482e26b7c0472fb6a153bf94662e4dfc01b2da0c3ca0da4af93bce05faf0e33be5422fbee85e6b69ca1cccbe194cff ./core/autodep.sh
7447d3e167ab207d3ef4218e201a06bf5a3fc23281639f16f7f405f1d66b73923845d450fdb0a94672757866a9da0324f728564a1b61b2ed1678fe576eb565cf ./core/autocomplete.sh 7447d3e167ab207d3ef4218e201a06bf5a3fc23281639f16f7f405f1d66b73923845d450fdb0a94672757866a9da0324f728564a1b61b2ed1678fe576eb565cf ./core/autocomplete.sh