Skip to content

Commit

Permalink
Optimize git fetch (#518)
Browse files Browse the repository at this point in the history
Fixes #473
  • Loading branch information
mafredri committed Feb 8, 2020
1 parent 957e071 commit 35ca202
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pure.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ prompt_pure_async_git_fetch() {
# 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
fi

# Default return code, which indicates Git fetch failure.
local fail_code=99

Expand All @@ -317,7 +327,13 @@ prompt_pure_async_git_fetch() {
fi
' CHLD

command git -c gc.auto=0 fetch >/dev/null &
# Only fetch information for the current branch and avoid
# fetching tags or submodules to speed up the process.
command git -c gc.auto=0 fetch \
--quiet \
--no-tags \
--recurse-submodules=no \
$remote &>/dev/null &
wait $! || return $fail_code

unsetopt monitor
Expand Down Expand Up @@ -505,6 +521,13 @@ prompt_pure_async_callback() {
do_render=1
fi
;;
97)
# No remote available, make sure to clear git arrows if set.
if [[ -n $prompt_pure_git_arrows ]]; then
typeset -g prompt_pure_git_arrows=
do_render=1
fi
;;
99|98)
# Git fetch failed.
;;
Expand Down

0 comments on commit 35ca202

Please sign in to comment.