From bc940f11122b08f87e9186ed3561befb14d107dc Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sun, 26 Jul 2026 15:28:52 +0200 Subject: [PATCH] Run the flutter hooks with the git hook's environment stripped Same defect diet-guard's pre-push gate hit today, latent here: git exports GIT_DIR to its hooks, and the flutter tool shells out to git to identify its own SDK. With GIT_DIR set it reads THIS repository instead of /opt/flutter, so `flutter --version` reports our own HEAD as the framework revision and our URL as the repository, pub resolves the SDK as "0.0.0-unknown", and every dependency constraint becomes unsatisfiable. flutter also caches that answer, so the damage outlives the hook run and follows the next caller into another repo. Both flutter gates now clear the git variables at the point of use. Verified by running the analyze hook with GIT_DIR set, which failed before and passes now. Also fixes the SC2295 shellcheck finding the coverage script had been carrying -- it only surfaced now because no change had touched a shell file. Co-Authored-By: Claude Opus 5 (1M context) --- .pre-commit-config.yaml | 6 +++++- scripts/check_flutter_coverage.sh | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bb260ee..ea307cc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -155,7 +155,11 @@ repos: types: [python] - id: flutter-analyze name: flutter analyze (workout app) - entry: bash -c 'cd stronglift_replacement/workout_app && flutter analyze' + # env -u GIT_DIR: git exports it to hooks, and flutter shells out to + # git to identify its own SDK -- with it set, flutter reads THIS repo + # as the SDK and pub resolves every constraint against 0.0.0-unknown. + entry: bash -c 'cd stronglift_replacement/workout_app && + env -u GIT_DIR -u GIT_WORK_TREE -u GIT_INDEX_FILE flutter analyze' language: system files: '^stronglift_replacement/workout_app/.*\.(dart|yaml)$' pass_filenames: false diff --git a/scripts/check_flutter_coverage.sh b/scripts/check_flutter_coverage.sh index 38513cc..67076a1 100755 --- a/scripts/check_flutter_coverage.sh +++ b/scripts/check_flutter_coverage.sh @@ -15,7 +15,11 @@ LCOV_INFO="$APP_DIR/coverage/lcov.info" cd "$APP_DIR" echo "Running flutter test --coverage ..." -flutter test --coverage +# env -u GIT_DIR: git exports it to hooks, and the flutter tool shells out to +# git to identify its own SDK. With it set, flutter reads THIS repository as +# the SDK -- reporting our HEAD as the framework revision -- and pub then +# resolves every version constraint against "0.0.0-unknown" and fails. +env -u GIT_DIR -u GIT_WORK_TREE -u GIT_INDEX_FILE flutter test --coverage cd - > /dev/null @@ -29,7 +33,7 @@ fi # Unreferenced files silently score 100% by absence — catch that here. missing=0 while IFS= read -r dart_file; do - rel="${dart_file#$APP_DIR/}" + rel="${dart_file#"$APP_DIR"/}" if ! grep -qF "SF:$rel" "$LCOV_INFO" && \ ! grep -qF "SF:lib/${rel#lib/}" "$LCOV_INFO"; then echo "MISSING FROM COVERAGE: $dart_file" >&2