{ "intent": "Make it impossible for the Flutter SDK to misidentify itself when invoked from a git hook, so Flutter gates in any repo stop failing with 'The current Flutter SDK version is 0.0.0-unknown'.", "scope": [ "linux_configuration/scripts/single_use/fixes/fix_flutter_git_env.sh (new)", "Installs to ~/.local/share/flutter-git-env/wrapper.sh with ~/.local/bin/{flutter,dart} symlinks", "Non-goal: patching /opt/flutter/bin/internal/shared.sh — pacman-owned by flutter-bin, an update would silently restore the bug", "Non-goal: CI runners, which do not set GIT_DIR because they call flutter from workflow steps rather than hooks" ], "changes": [ "Root cause: git exports GIT_DIR to its hooks, and `git -C \"$FLUTTER_ROOT\" rev-parse HEAD` in shared.sh does not beat it — `-C` only changes directory while GIT_DIR overrides repository discovery. flutter therefore reads the repo being committed as its own SDK, reports that repo's HEAD as the framework revision, resolves the SDK as 0.0.0-unknown, and caches the wrong answer in bin/cache/flutter.version.json where it poisons later callers in other repos.", "Adds a PATH wrapper ahead of /usr/bin that strips GIT_DIR and the other git hook variables, then execs the real binary. Covers flutter and dart (both are aur_* shims into /opt/flutter).", "The wrapper removes its own directory from PATH before exec, so the Flutter entry point's internal `which flutter` lookup cannot loop back into it.", "Ships --check (re-verify, e.g. after a flutter update) and --uninstall. Install is idempotent.", "Verification is built in: the installer creates a throwaway git repo, runs flutter with GIT_DIR pointed at it, and fails unless flutter still reports github.com/flutter/flutter." ], "verification": [ { "command": "GIT_DIR=/home/kuhy/diet-guard/.git git -C /opt/flutter rev-parse HEAD", "result": "reproduced", "evidence": "84bd5503316568914ed93b9451c397ff517a09d4 (diet-guard's HEAD) vs 058e0af2c2... without GIT_DIR — confirms `git -C` loses to GIT_DIR" }, { "command": "GIT_DIR=/home/kuhy/diet-guard/.git flutter --version # before the fix", "result": "reproduced", "evidence": "Flutter 3.47.0-0.1.pre • channel main • https://github.com/kuhyx/diet-guard — the SDK reporting the project as itself" }, { "command": "cd /home/kuhy/diet-guard/app && GIT_DIR=/home/kuhy/diet-guard/.git flutter analyze # after the fix, no per-call env -u", "result": "pass", "evidence": "Analyzing app... No issues found! (ran in 1.2s) — previously failed with 'url_launcher_platform_interface ^2.3.2 is forbidden' against 0.0.0-unknown" }, { "command": "GIT_DIR=... dart --version; flutter --version; command -v flutter dart", "result": "pass", "evidence": "Dart SDK version: 3.12.2 (stable); Flutter 3.44.8 • channel stable • github.com/flutter/flutter; both resolve to /home/kuhy/.local/bin — normal use unaffected, no exec loop" }, { "command": "bash fix_flutter_git_env.sh --check && bash fix_flutter_git_env.sh", "result": "pass", "evidence": "verified: Flutter 3.44.8 • channel stable • https://github.com/flutter/flutter.git; reinstall is idempotent" }, { "command": "shellcheck linux_configuration/scripts/single_use/fixes/fix_flutter_git_env.sh", "result": "pass", "evidence": "no findings" } ], "risks": [ "Shadows /usr/bin/flutter and /usr/bin/dart on PATH for this user. Mitigated by exec'ing the real binary by absolute path and by the installer refusing to overwrite a non-symlink at either location.", "If ~/.local/bin ever stops being on PATH the wrapper silently stops applying; the installer and --check both fail loudly on that, but only when run.", "Per-call `env -u GIT_DIR` remains in screen-locker's and diet-guard's hooks on purpose: those repos may be cloned onto machines without this wrapper." ], "rollback": [ "bash linux_configuration/scripts/single_use/fixes/fix_flutter_git_env.sh --uninstall", "Confirm `command -v flutter` is /usr/bin/flutter again and `flutter --version` reports 3.x on channel stable", "Expect Flutter gates run from git hooks to start failing with 0.0.0-unknown again unless the per-call env -u fixes are present" ] }