mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-09-28 14:06:12 +02:00
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:
co-authored by
Claude Opus 5
parent
01bbde85c4
commit
7c37eac972
+4
-2
@@ -29,7 +29,8 @@ function _omz_git_prompt_info() {
|
|||||||
# - the current branch name
|
# - the current branch name
|
||||||
# - the tag name if we are on a tag
|
# - the tag name if we are on a tag
|
||||||
# - the short SHA of the current commit
|
# - 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
|
if (( unborn )); then
|
||||||
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) || return 0
|
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) || return 0
|
||||||
elif [[ "$ref" == HEAD ]]; then
|
elif [[ "$ref" == HEAD ]]; then
|
||||||
@@ -253,7 +254,8 @@ function parse_git_dirty() {
|
|||||||
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
|
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
|
||||||
;;
|
;;
|
||||||
esac
|
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
|
fi
|
||||||
if [[ -n $STATUS ]]; then
|
if [[ -n $STATUS ]]; then
|
||||||
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||||
|
|||||||
Reference in New Issue
Block a user