From 7c37eac972872e352ccb22259e288e71d4d2c1f4 Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Mon, 7 Sep 2026 07:54:31 -0700 Subject: [PATCH] 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) --- lib/git.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index 70e81ca06..8d56aba0e 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -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"