Repository navigation
fix(hooks): resolve the package config through a pub workspace root - #1137
Merged
Merged
Conversation
In a pub workspace pub writes package_config.json only at the workspace root, and a member app gets .dart_tool/pub/workspace_ref.json instead. The pre-commit hook required the app's own package_config.json, so in such a monorepo it refused every commit, and the flutter pub get it advised never created the file. It now follows workspace_ref.json to the root, checks the config there and copies it into the staged export at the root's place. The hook test gains a workspace case. Refs #1131 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Case 3 leaves a staged format violation in the monorepo copy, which the workspace case copied in with the app. Refs #1131 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r real Review of the workspace support found that the test fixture committed the workspace root's .dart_tool/, so the export already held the config and the hook's copy of it went untested; the fixture now ignores .dart_tool/ as a real workspace does. pub on Windows writes workspaceRoot with escaped backslashes, which the hook now turns into slashes, and a test case covers it. The refusal names the missing file, the outside-the-repo refusal says how to commit anyway, and the unneeded workspace_ref.json copy is gone. Refs #1131 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hand-written fixture had one level too many for this layout. Refs #1131 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1131
Problem
In a pub workspace (a root
pubspec.yamlwithworkspace:, the app withresolution: workspace), pub writes.dart_tool/package_config.jsononly at the workspace root. A member app gets.dart_tool/pub/workspace_ref.jsoninstead..githooks/pre-commitrequired the app's ownpackage_config.json, so it refused every commit. Theflutter pub getit advised never created the file.Change
.githooks/pre-commit: if the app has nopackage_config.jsonbut hasworkspace_ref.json, the hook:workspaceRoot, which is relative to that file's directory. Windows-style escaped backslashes become slashes.package_graph.jsoninto the staged export at the root's own place.A workspace root outside the git repository (a submodule, or a repo nested in the workspace) is refused with how to commit anyway: run the checks by hand, then
--no-verify. Before this change that layout was refused too, with misleadingpub getadvice. Plain and monorepo layouts are unchanged:config_diris the app.scripts/test/pre_commit_hook_test.sh, case 4: a real workspace whose root ignores.dart_tool/, as a real one does. That way the export gets the config only through the hook's copy. It checks:.dart_tool/;workspaceRoot(derived from the real one): exit 0;flutter pub get, and passes after it.Verified
Under macOS
/bin/bash3.2.57:main's hookAlso:
shellcheckis clean on both files../scripts/dev/audit_template.shexits 0 (4126 tests).Pre-merge review
A fresh reviewer subagent ran on
b2f954cwith the PR, issue and diff, not the implementer's verdict. It exercised a linked worktree at a path with a space, a symlinked checkout, a shared hooks directory and a stale app config, and found no regression.Fixed on this branch (
625e04b,a5607bf):.dart_tool/, so the config copy was never tested. Mutation M1 passed before the fix and fails now.workspaceRootwith Windows backslashes was not parsed.workspace_ref.jsoncopy was removed.Filed: the pre-existing re-resolve of dependencies by
flutter analyzein the export, on every commit, as a box in the 2026-11-01 P3 list (#1132).🤖 Generated with Claude Code