fix(git): take the branch from the last rev-parse line, keep one status line

A git dir path may contain a newline, so splitting the combined
rev-parse output on newlines can leave the branch somewhere past
element 2. The branch is always the final line, so read it from the end.

parse_git_dirty only needs to know whether the porcelain output is
empty. Read a single line with the read builtin instead of capturing
every line, so a worktree with many changes doesn't build a large
string on each prompt.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Robby Russell
2026-09-07 07:54:31 -07:00
co-authored by Claude Opus 5
parent 01bbde85c4
commit 7c37eac972
+4 -2
View File
@@ -29,7 +29,8 @@ function _omz_git_prompt_info() {
# - the current branch name
# - the tag name if we are on a tag
# - the short SHA of the current commit
local ref="$info[2]"
# a git dir path may contain newlines, so the branch is the last line
local ref="$info[-1]"
if (( unborn )); then
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) || return 0
elif [[ "$ref" == HEAD ]]; then
@@ -253,7 +254,8 @@ function parse_git_dirty() {
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
;;
esac
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null)
# only non-emptiness matters, so keep one line instead of the whole list
__git_prompt_git status ${FLAGS} 2> /dev/null | read -r STATUS
fi
if [[ -n $STATUS ]]; then
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"