For git prompt, allow repos to disable prefetch.

This commit is contained in:
Darren 'Tadgy' Austin 2023-10-12 20:30:36 +01:00
commit fba4a7c40a

10
.bashrc
View file

@ -15,6 +15,8 @@ __prompt_git_status() {
# << or <x - Working tree is behind upstream (x = commits behind when used with next option).
# GIT_PROMPT_SHOW_UPSTREAM_EXTENDED=1 In addition to upstream status, show the number of commits difference (inplies above).
# GIT_PROMPT_AUTO_PREFETCH=1 Automatically 'prefetch' upstream refs for comparisons (requires GIT_PROMPT_SHOW_UPSTREAM above).
# This can be disabled on a per repository basis using:
# git config --add --bool maintenance.promptprefetchdisabled true
# GIT_PROMPT_SHOW_IGNORED=1 Show a ! if the current directory is ignored.
# GIT_PROMPT_SHOW_UNSTAGED=1 Show a * if there are unstaged changes (superceeded by above).
# GIT_PROMPT_SHOW_UNCOMMITTED=1 Show a & if there are staged but uncommitted changes (superceeded by above).
@ -63,11 +65,9 @@ __prompt_git_status() {
# Add upstream status.
[[ -n "$GIT_PROMPT_SHOW_UPSTREAM" ]] || [[ -n "$GIT_PROMPT_SHOW_UPSTREAM_EXTENDED" ]] && {
# Whether to run prefetch tasks.
[[ -n "$GIT_PROMPT_AUTO_PREFETCH" ]] && {
# Only prefetch remotes if in the top-level working directory and if the repository is configured for maintenance work.
[[ "$PWD" == "${GIT_REPO_INFO[0]}" ]] && git config --global --get --fixed-value maintenance.repo "$PWD" >/dev/null 2>&1 && {
git maintenance run --task=prefetch 2>/dev/null || printf "\\033[1;31m%s\\033[39m\\n" "Git maintenance 'prefetch' task failed." >&2
}
[[ -n "$GIT_PROMPT_AUTO_PREFETCH" ]] && [[ "$PWD" == "${GIT_REPO_INFO[0]}" ]] && \
[[ "$(git config --get --bool maintenance.promptprefetchdisabled 2>/dev/null)" != "true" ]] && {
git maintenance run --task=prefetch 2>/dev/null || printf "\\033[1;31m%s\\033[39m\\n" "Git maintenance 'prefetch' task failed." >&2
}
COUNT="$(git rev-list --count --left-right "${BRANCH:+refs/prefetch/remotes/origin/}${BRANCH:-@{upstream\}}...HEAD" 2>/dev/null | tr '[:blank:]' ' ')"
case "$COUNT" in