Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize git fetch #518

Merged
merged 1 commit into from
Feb 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -490,6 +506,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