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>
`_omz_git_prompt_info` ran `git rev-parse --git-dir` and then
`git symbolic-ref --short HEAD` as two separate processes. Ask for both
in one `git rev-parse --git-dir --abbrev-ref HEAD` call; a detached HEAD
prints "HEAD" and falls through to the tag/SHA lookups as before, and an
unborn branch (exit 128 after printing the git dir) falls back to
`symbolic-ref` so freshly initialised repositories still show their
branch.
`parse_git_dirty` piped `git status --porcelain` through `tail -n 1`,
but only tests whether the output is empty, so the pipe is dropped.
Output verified identical for: outside a repo, unborn, unborn with
staged files, clean, dirty, detached, detached on a tag, hide-info,
hide-dirty, subdirectory. Two fewer forks per prompt; ~13 ms less on
macOS arm64 for a clean branch.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
We removed this mitigation in 0c80a063 because of an assumption
that the issue had been fixed, but it looks like zsh < 5.0.6 has
other issues (see #12360), so we need to disable it for real.
Fixes#12360
This is important for themes using it, since it is usually a little slower than git_prompt_info.
Also two small fixes :
- the handler for git_prompt_info was incorrectly named _omz_git_prompt_status
- _defer_async_git_register was kept in precmd, there is no need to call it on each prompt
BREAKING CHANGE: the new async prompt feature will render prompt information
asyncronously and degrade nicely when the calls take too long to finish, as
the prompt will already be first drawn and interactive. This is
enabled by default for the git prompt and themes that use it (`git_prompt_info`).
If you find that it's not working for you, please open an issue if one is
not already opened, and see https://github.com/ohmyzsh/ohmyzsh#disable-async-git-prompt
for how to turn it off.
This fix conditionally registers the git prompt async handler only
if `git_prompt_info` is used anywhere in the prompt variables.
This is done in the proper order, so that the async request is
processed once the handler has been registered.
This fix also passes the return value of the previous command
to each of the async handlers, in case they are needed.
BREAKING CHANGE: the `git_prompt_info` prompt function has been
reworked by default to use the new async prompt feature. If you're
experiencing issues see #12257.
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Show the remote branch the local branch is tracking if `ZSH_THEME_GIT_SHOW_UPSTREAM`
is set, like so: `ZSH_THEME_GIT_SHOW_UPSTREAM=1`.
Co-authored-by: Marc Cornellà <marc.cornella@live.com>
DISABLE_UNTRACKED_FILES_DIRTY, DISABLE_AUTO_TITLE, GIT_STATUS_IGNORE_SUBMODULES are not set
Handle these variables not being set with conditional access.
If the user has set -u option to report attempts to use undeclared / unassigned variable, accessing the variables needs to be conditional.
$GIT_STATUS_IGNORE_SUBMODULES can be used to specify handling of
submodules. It can be:
not set : ignore dirty submodules (this was default zsh behavior)
"git" : do not use "--ignore-submodules" and let git choose,
this obeys setting in .gitmodules
other : comes into "--ignore-submodules=$GIT_STATUS_IGNORE_SUBMODULES"