Skip to content

Commit

Permalink
Default to updating all git branches on fetch (#571)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
mafredri and sindresorhus committed Nov 1, 2020
1 parent dfc8062 commit 8eef013
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
27 changes: 16 additions & 11 deletions pure.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,23 @@ prompt_pure_async_git_dirty() {
prompt_pure_async_git_fetch() {
setopt localoptions noshwordsplit

local only_upstream=${1:-0}

# Sets `GIT_TERMINAL_PROMPT=0` to disable authentication prompt for Git fetch (Git 2.3+).
export GIT_TERMINAL_PROMPT=0
# Set SSH `BachMode` to disable all interactive SSH password prompting.
export GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-"ssh"} -o BatchMode=yes"

local ref
ref=$(command git symbolic-ref -q HEAD)
local -a remote
remote=($(command git for-each-ref --format='%(upstream:remotename) %(refname)' $ref))

if [[ -z $remote[1] ]]; then
# No remote specified for this branch, skip fetch.
return 97
if ((only_upstream)); then
local ref
ref=$(command git symbolic-ref -q HEAD)
# Set remote to only fetch information for the current branch.
remote=($(command git for-each-ref --format='%(upstream:remotename) %(refname)' $ref))
if [[ -z $remote[1] ]]; then
# No remote specified for this branch, skip fetch.
return 97
fi
fi

# Default return code, which indicates Git fetch failure.
Expand Down Expand Up @@ -340,8 +344,8 @@ prompt_pure_async_git_fetch() {
fi
' CHLD

# Only fetch information for the current branch and avoid
# fetching tags or submodules to speed up the process.
# Do git fetch and avoid fetching tags or
# submodules to speed up the process.
command git -c gc.auto=0 fetch \
--quiet \
--no-tags \
Expand Down Expand Up @@ -438,8 +442,9 @@ prompt_pure_async_refresh() {

# Do not perform `git fetch` if it is disabled or in home folder.
if (( ${PURE_GIT_PULL:-1} )) && [[ $prompt_pure_vcs_info[top] != $HOME ]]; then
# Tell the async worker to do a `git fetch`.
async_job "prompt_pure" prompt_pure_async_git_fetch
zstyle -t :prompt:pure:git:fetch only_upstream
local only_upstream=$((? == 0))
async_job "prompt_pure" prompt_pure_async_git_fetch $only_upstream
fi

# If dirty checking is sufficiently fast,
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,16 @@ prompt pure
| **`PURE_GIT_UP_ARROW`** | Defines the git up arrow symbol. | `` |
| **`PURE_GIT_STASH_SYMBOL`** | Defines the git stash symbol. | `` |

## Zstyle options

Showing git stash status as part of the prompt is not activated by default. To activate this you'll need to opt in via `zstyle`:

`zstyle :prompt:pure:git:stash show yes`

You can set Pure to only `git fetch` the upstream branch of the current local branch. In some cases, this can result in faster updates for Git arrows, but for most users, it's better to leave this setting disabled. You can enable it with:

`zstyle :prompt:pure:git:fetch only_upstream yes`

## Colors

As explained in ZSH's [manual](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting), color values can be:
Expand Down

0 comments on commit 8eef013

Please sign in to comment.