From 034ca9256a06a3b384343f722a96219908d356df Mon Sep 17 00:00:00 2001 From: Matt Hunter Date: Mon, 30 Mar 2026 23:53:25 -0400 Subject: Only invoke git-precheck once Cache the exit code from git-precheck to be used later by the condition feature. Ensure git-precheck is run with the --ignore-dirty and --ignore-untracked options, to avoid an unnecessary call to git-status. Signed-off-by: Matt Hunter --- git-sonar | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/git-sonar b/git-sonar index fa2237e..1a73949 100755 --- a/git-sonar +++ b/git-sonar @@ -41,11 +41,6 @@ prepare_colors() { } -is_repo() { - git-precheck --quiet - [ $? -lt 4 ] -} - fetch() { FETCH_TIME="${GIT_RADAR_FETCH_TIME:-"$((5 * 60))"}" TS_FILE="$(git rev-parse --git-path lastupdatetime 2>/dev/null)" @@ -327,8 +322,7 @@ stash_status() { } repo_special_condition() { - git-precheck --quiet --ignore-dirty --ignore-untracked \ - || printf "$COLOR_CONDITION!$RESET_COLOR_CONDITION" + [ "$precheck_status" -lt 3 ] || printf '%b' "$COLOR_CONDITION!$RESET_COLOR" } render_prompt() { @@ -487,8 +481,11 @@ if [ $# -ne 0 ]; then exit 1 fi -# Guard all active operations by this is_repo check -if is_repo; then +git-precheck --quiet --ignore-dirty --ignore-untracked >/dev/null 2>&1 +precheck_status=$? + +# Guard all active operations by this "is in repo" check +if [ "$precheck_status" -lt 4 ]; then # Merge configuration from accepted RC files [ -f "$HOME/.gitradarrc" ] && . "$HOME/.gitradarrc" [ -f "$HOME/.gitradarrc.bash" ] && . "$HOME/.gitradarrc.bash" -- cgit v1.2.3