summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hunter <m@lfurio.us>2026-03-30 23:53:25 -0400
committerMatt Hunter <m@lfurio.us>2026-04-22 21:59:29 -0400
commit034ca9256a06a3b384343f722a96219908d356df (patch)
treea9bba4f1d38b950e851a5b4f0eb15fd031866c3c
parent4f88708af94e82e7f8da427d7f3c6a876acbd71a (diff)
downloadgit-sonar-034ca9256a06a3b384343f722a96219908d356df.tar.gz
git-sonar-034ca9256a06a3b384343f722a96219908d356df.zip
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 <m@lfurio.us>
-rwxr-xr-xgit-sonar15
1 files 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"