Skip to content

Commit 35ca202

Browse files
authored
Optimize git fetch (#518)
Fixes #473
1 parent 957e071 commit 35ca202

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Diff for: pure.zsh

+24-1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,16 @@ prompt_pure_async_git_fetch() {
292292
# Set SSH `BachMode` to disable all interactive SSH password prompting.
293293
export GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-"ssh"} -o BatchMode=yes"
294294

295+
local ref
296+
ref=$(command git symbolic-ref -q HEAD)
297+
local -a remote
298+
remote=($(command git for-each-ref --format='%(upstream:remotename) %(refname)' $ref))
299+
300+
if [[ -z $remote[1] ]]; then
301+
# No remote specified for this branch, skip fetch.
302+
return 97
303+
fi
304+
295305
# Default return code, which indicates Git fetch failure.
296306
local fail_code=99
297307

@@ -317,7 +327,13 @@ prompt_pure_async_git_fetch() {
317327
fi
318328
' CHLD
319329

320-
command git -c gc.auto=0 fetch >/dev/null &
330+
# Only fetch information for the current branch and avoid
331+
# fetching tags or submodules to speed up the process.
332+
command git -c gc.auto=0 fetch \
333+
--quiet \
334+
--no-tags \
335+
--recurse-submodules=no \
336+
$remote &>/dev/null &
321337
wait $! || return $fail_code
322338

323339
unsetopt monitor
@@ -505,6 +521,13 @@ prompt_pure_async_callback() {
505521
do_render=1
506522
fi
507523
;;
524+
97)
525+
# No remote available, make sure to clear git arrows if set.
526+
if [[ -n $prompt_pure_git_arrows ]]; then
527+
typeset -g prompt_pure_git_arrows=
528+
do_render=1
529+
fi
530+
;;
508531
99|98)
509532
# Git fetch failed.
510533
;;

0 commit comments

Comments
 (0)