Skip to content

fix(hooks): resolve the package config through a pub workspace root - #1137

Merged
koniz-dev merged 4 commits into
mainfrom
fix/pre-commit-pub-workspace
Nov 1, 2026
Merged

koniz-dev merged 4 commits into
mainfrom
fix/pre-commit-pub-workspace

Conversation

@koniz-dev

@koniz-dev koniz-dev commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Refs #1131

Problem

In a pub workspace (a root pubspec.yaml with workspace:, the app with resolution: workspace), pub writes .dart_tool/package_config.json only at the workspace root. A member app gets .dart_tool/pub/workspace_ref.json instead.

.githooks/pre-commit required the app's own package_config.json, so it refused every commit. The flutter pub get it advised never created the file.

Change

  • .githooks/pre-commit: if the app has no package_config.json but has workspace_ref.json, the hook:

    • reads workspaceRoot, which is relative to that file's directory. Windows-style escaped backslashes become slashes.
    • requires the config at that root, and names the missing file when it is absent;
    • copies the config and package_graph.json into 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 misleading pub get advice. Plain and monorepo layouts are unchanged: config_dir is 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:

    • the fixture resolves at the root only and commits no .dart_tool/;
    • clean tree: exit 0;
    • staged format violation: fail;
    • a Windows-style workspaceRoot (derived from the real one): exit 0;
    • unresolved workspace: refuses and advises flutter pub get, and passes after it.

Verified

Under macOS /bin/bash 3.2.57:

Hook under test Result
New hook All 14 cases pass
main's hook 4 workspace cases fail
M1: new hook without the root-config copy 3 fail
M2: new hook without the backslash normalization The Windows-style case fails

Also:

  • shellcheck is clean on both files.
  • ./scripts/dev/audit_template.sh exits 0 (4126 tests).

Pre-merge review

A fresh reviewer subagent ran on b2f954c with 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):

  • The fixture committed the root's .dart_tool/, so the config copy was never tested. Mutation M1 passed before the fix and fails now.
  • workspaceRoot with Windows backslashes was not parsed.
  • The refusal did not name the missing file.
  • The outside-repo refusal gave unworkable advice.
  • An unneeded workspace_ref.json copy was removed.

Filed: the pre-existing re-resolve of dependencies by flutter analyze in the export, on every commit, as a box in the 2026-11-01 P3 list (#1132).

🤖 Generated with Claude Code

koniz-dev and others added 4 commits November 1, 2026 23:43
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>
@koniz-dev
koniz-dev merged commit ef4ee12 into main Nov 1, 2026
7 checks passed
@koniz-dev
koniz-dev deleted the fix/pre-commit-pub-workspace branch November 1, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant