On macOS, fish_git_prompt was failing to correctly handle the case where
another git was installed, e.g. /usr/local/bin/git from Homebrew.
Disable the workarounds in that case.
Our macOS workarounds involve running "xcrun" to check if Git is installed.
On a freshly upgraded Ventura system that does not have XCode or
CommandLineTools installed, "xcrun" will print this error:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
on every prompt. Let's silence this error.
The `git` can already have finished here, leading to "disown: There
are no suitable jobs". This has caused a failure on Github Actions.
So we do $last_pid and silence all output, like we do in other spots
git on macOS has two hazards:
1. It comes "preinstalled" as a stub which pops a dialog to install
command line developer tools.
2. It may populate the xcrun cache when run for the first time, which
may take several seconds.
We fix these as follows, both fixes limited to Darwin:
1. If git is `/usr/bin/git` and `xcode-select --print-path` fails,
then do not run git automatically.
2. Second, if there is no file at `xcrun --show-cache-path`, we take it
as an indication that the cache is not yet populated. In this case we
run `git` in the background to populate the cache.
Credit to @floam for the idea.
Fixes#9343. Fixes#6625.
This checked the locale, but did so in a way that's fundamentally
broken:
1. $LANG isn't the only variable ($LC_ALL and $LC_CTYPE)
2. Even if $LANG is set that doesn't mean it's actually working
We could add a `status is-multibyte` here to figure out if we have a
multibyte locale?
But instead, since this is dealing with adding an ellipsis, let's just
add it to `string ellipsize`.
One slight difference is that shortening the branch now counts the ellipsis width.
I.e. assuming the branch is "long-branch-name"
```fish
set -g __fish_git_prompt_shorten_branch_len 8
```
might now print "long-br…" instead of "long-bra…". This is nicer because we can now give the actual maximum width.
The alternative is to add a "--exclusive" option to "string ellipsize" that doesn't count the ellipsis width. So `string ellipsize --char "..." --max 8" long-branch-name` might result in "long-bra...", which is 11 wide.
This makes it so
1. The informative status can work without showing untracked
files (previously it was disabled if bash.showUntrackedFiles was
false)
2. If untrackedfiles isn't explicitly enabled, we use -uno, so git
doesn't have to scan all the files.
In a large repository (like the FreeBSD ports repo), this can improve
performance by a factor of 5 or up.
Arguments to --ignored were introduced in Git 2.16, from January 2018.
The git completions specifically work around this, allowing older
versions to be used; match this in the git prompt.
Fixes the tests on CentOS 7.
When switching this to use `git status`, I neglected to use the
correct definition of what a "dirty" and a "staged" change is.
So this now showed already staged files still as "dirty".
Fixes#8986
fish_git_prompt may run certain git commands which may invoke certain
external programs as specified `.git/config`. Prevent this by suppressing
certain git config options.
Fixes#7926.
Also switches the default status order for non-informative to the informative one:
stagedstate invalidstate dirtystate untrackedfiles stashstate
instead of
dirty staged stash untracked
This allows us to stop descending into untracked directories, which
can be faster.
It's still not *good* - git can still be quite slow here, but if
there's an untracked directory you probably don't care about the
number of files in that.
Fixes#7871.
Because we removed repaint coalescing, currently setting any of the
git prompt variables in fish_prompt leads to a repaint loop (that
presumably aborts once it reaches the recursion limit).
Since repainting on these variables isn't really useful (when you
`set` them interactively you already get a new prompt), just remove
it.
There's two cases this "breaks":
- When you set a variable *after* the call to fish_git_prompt
- When you set a variable via a binding
In both of these it's not too much to expect an explicit "commandline
-f repaint", especially since for bindings that's already needed in
most cases, and setting a variable after using it isn't normal.
Fixes#7775.
This had this weird "pass along the sha, then check" logic to it which
is entirely unnecessary.
This function just says when something is staged, nothing more. Why
that is you can figure out for yourself.
This makes it easier to call this function, and it no longer prints an
empty line if nothing is staged.
This wasn't added to the prompt status order, so it was computed and
then not used for the informative prompt.
We still check later if we should compute it, so this is harmless if
showstashstate is unset.
Fixes#7136.
$__fish_git_prompt_use_informative_chars will use the informative
chars without requiring informative mode (which is really frickin'
slow!).
See #5726.
[ci skip]
If you changed $__fish_git_prompt_show_informative_status, it
triggered a variable handler, which erased the chars, but neglected to
unset $___fish_git_prompt_init, so we just kept chugging along with
empty characters.
What's the hardest thing in CS again? Cache something something?
[ci skip]
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.
If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.