Skip to content

fix(model-stamp): a model in another git repository no longer blocks every commit (#805) - #810

Open
MendixMau wants to merge 3 commits into
masterfrom
triage/805-model-stamp-external-repo
Open

MendixMau wants to merge 3 commits into
masterfrom
triage/805-model-stamp-external-repo

Conversation

@MendixMau

@MendixMau MendixMau commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Fixes #805

Direct lane

What changed and why (one paragraph): When a project uses its model in place from another git repository (CLAUDE.local.md "Project MPR" points at a Team Server clone outside the project repo), the mxtk-model-stamp pre-commit hook refused every commit, docs-only commits included, with "refusing to fingerprint an empty set".

The cause:

  1. git commit exports GIT_INDEX_FILE.
  2. project-bin/model-stamp.sh makes it absolute and exports it (the 2026-09-26 worktree fix).
  3. Every later git -C "$MODEL_DIR" then read the project repo's index, found no model files there, and refused.

The fix, per the triage sketch: check --staged first asks the model folder for its own top level, with GIT_DIR / GIT_INDEX_FILE / GIT_WORK_TREE unset in a subshell. It compares that with the committing repo's top.

  • Tops differ: the commit cannot stage the model, so it passes with "the model is in another repository () — nothing staged here to verify".
  • Tops match: behaviour is unchanged, including the worktree and --git-dir commits the 2026-09-26 fix protects.

Exit codes are unchanged.

Impact

Row Answer
Process One false refusal removed. Nothing new blocks.
Dependencies project-bin/model-stamp.sh only (reaches projects via sync). No new tools; a subshell unset works on bash 3.2/macOS and Git Bash.
Context cost none: no routed or always-loaded file touched
Behaviour n/a: scripts only
Runtime Two extra git rev-parse --show-toplevel per check --staged: ~8 ms per commit, measured.

Time cost: per commit · ~0.008 s on Linux · can force rework: n · offset: removes a false refusal that forced MODEL_UNVERIFIED_OK=1 on every commit in the two-repository layout

Field evidence: reported by thanarat in #805, on macOS (git 2.50.1 Apple, bash 3.2 hook) with a separate Team Server clone. The fixture now builds that layout from two real git repos.

Fixture: tests/wave2/test-model-stamp.sh, new case T11. It uses a project repo plus a separate model repo, with the hook installed and MPR_FILE pointing at the other repo.

Results:

  • master: 36 passed, 2 failed. The docs-only commit is refused.
  • branch: 38 passed, 0 failed.

The T9 worktree / --git-dir / commit -a / commit -- app cases still refuse an unverified model inside the repo. A new check confirms that an unverified model staged in its own repo is still refused.

Other fixtures that exercise check --staged, all green on the branch:

  • module-close-cadence 67/0
  • exec-gate-kind 32/0
  • restatement-git-hooks 28/0
  • mx-metadata-note 40/0
  • common-root-multiapp 67/0

check-scripts, check-portability, the leak guard and check-pr-discipline are clean.

Known limits: a commit in the main checkout passes when MPR_FILE points at a different linked worktree's model, since that model is outside this work tree (needs a mis-pointed config; the mirror case, worktree → main checkout, is already accepted on master).

Review: pending independent review


Generated by Claude Code

…every commit (#805)

git commit exports GIT_INDEX_FILE; model-stamp.sh made it absolute (the
2026-09-26 worktree fix) and every `git -C <model folder>` then read the
committing repo's index. With the model in a different repository (a Team
Server clone used in place), that index never holds model files, so
check --staged refused with "refusing to fingerprint an empty set" on every
commit, docs-only included.

check --staged now asks the model folder for its own top with GIT_DIR,
GIT_INDEX_FILE and GIT_WORK_TREE unset (subshell unset, no env -u), and
compares it with the top of the repo being committed to. When they differ
it passes with "the model is in another repository". Same repo, worktree
and --git-dir commits included, behaves exactly as before.

Fixture test-model-stamp.sh T11: two real repos, hook installed; master
36/2, branch 38/0 (T9 worktree/--git-dir cases unchanged).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HXpQSjXefSNicGGqP4aiSC
@MendixMau

Copy link
Copy Markdown
Owner Author

Review: MERGE-AFTER-FIX. This fixes #805, but comparing repository tops opens a bypass. A commit made with GIT_DIR/GIT_WORK_TREE, whose work tree has no .git and sits inside another repo, now lets an unverified model through.

Value: Fixes #805 as reported: with the model in a separate repo, a docs-only commit is now accepted. The change is small, with unchanged exit codes.

Regression risk: Fixtures green on head:

Fixture Result
model-stamp 38/0
module-close-cadence 67/0
exec-gate-kind 32/0
restatement-git-hooks 28/0
mx-metadata-note 40/0
common-root-multiapp 67/0
model-scope 50/1 (the failure is already on master)

Adversarial cases:

Case master head
symlinked model dir in the same repo refused refused
symlinked root refused refused
external non-git model accepted accepted
nested separate model repo refused accepted (correct)
GIT_DIR=sep.git GIT_WORK_TREE=<wt>, with <wt> inside an unrelated outer repo, unverified model staged refused accepted

The cause is at project-bin/model-stamp.sh:+350. _mtop is computed with the git variables unset, so it falls through to the outer repo, while _htop is the real work tree. This is a blocking guard, so a rare layout still matters. Bash 3.2 and Git Bash are fine.

Correctness: T11 builds two real repos and runs the real hook.

Context cost: none.

Time cost: ~ms per commit.

Exact fixes required:

  1. Skip only when the model is really outside this work tree, or is a separate repo nested strictly inside it:
    • resolve m=$(cd "$MODEL_DIR" && pwd -P) and h=$(cd "$_htop" && pwd -P);
    • pass when m is not under h/, or when _mtop resolves strictly under h/;
    • otherwise fall through to the existing check.
  2. Add two T11 cases: the GIT_DIR/GIT_WORK_TREE-inside-an-outer-repo case must be refused, and the nested model repo must be accepted.

Generated by Claude Code

…n a nested repo (#805)

Independent review (MERGE-AFTER-FIX): comparing repo tops opened a bypass. A
GIT_DIR/GIT_WORK_TREE commit whose work tree has no .git and sits inside an unrelated outer
repo made the model folder's "own top" the outer repo, so an unverified model passed as "in
another repository". check --staged now passes only when the model's real path is not under
the committing work tree, or the model's own top (git variables unset) is strictly under it,
i.e. a separate nested repo. Everything else falls through to the existing check.

T11 gains two cases: a nested separate model repo (docs-only commit accepted) and the
GIT_DIR/GIT_WORK_TREE work tree inside an outer repo (unverified model refused; this case
FAILs on the previous branch head). test-model-stamp 41/0 (master 38/3, previous head 39/2);
module-close-cadence 67/0, exec-gate-kind 32/0, restatement-git-hooks 28/0;
check-portability clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HXpQSjXefSNicGGqP4aiSC
@MendixMau

Copy link
Copy Markdown
Owner Author

Review fix pushed in 774b1be. check --staged now resolves both paths with pwd -P. It passes only when the model is outside the work tree, or when the model's own top level is strictly under it. Every other case falls through to the existing check.

T11 adds two cases:

  • a nested separate model repo, where a docs-only commit is accepted;
  • the GIT_DIR/GIT_WORK_TREE-inside-an-outer-repo case, where an unverified model is refused.
Fixture Result
test-model-stamp 41/0 (previous head 39/2, master 38/3)
module-close-cadence 67/0
exec-gate-kind 32/0
restatement-git-hooks 28/0

Needs a re-review.


Generated by Claude Code

@MendixMau

Copy link
Copy Markdown
Owner Author

Review: MERGE — re-review of 774b1be: the bypass is closed. The hook skips only when the model's real path is outside the work tree, or when its own repo top is strictly under it (project-bin/model-stamp.sh:353-363).
Value: Both required fixes landed, and T11 has both new cases (tests/wave2/test-model-stamp.sh:143-169). My adversarial cases, on master / previous head / this head:

Case master previous head this head
Symlinked model dir in the same repo, unverified refused refused refused
cwd via a symlinked root, MPR_FILE via the symlink refused refused refused
External non-git model, docs-only accepted accepted accepted
Nested model repo, docs-only refused accepted accepted
Nested repo's own unverified commit refused refused refused
GIT_DIR/GIT_WORK_TREE inside an outer repo, unverified refused accepted refused ("UNVERIFIED")
Linked worktree, unverified refused refused refused

Regression risk: One new accept that master refused. A main-checkout commit that stages an unverified model while MPR_FILE points at a different linked worktree's model now passes as "outside this work tree". This needs a mis-pointed config, and its mirror (worktree → main checkout) is already accepted on master. Record it as a known limit; it does not block. The changes are bash 3.2-safe: case with quoted "$_h", subshell unset, pwd -P.
Correctness: Fixtures on head:

Fixture Passed / failed
test-model-stamp 41/0
test-module-close-cadence 67/0
test-exec-gate-kind 32/0
test-restatement-git-hooks 28/0

Minor: the new outer-repo check (:167-168) passes on any refusal. Grep for UNVERIFIED so a hook crash cannot pass it.
Context cost: 65,568 → 65,568 (measured).
Time cost: a few git rev-parse/cd calls per commit.
CI / merge: checks was in progress, authoring-audit passed. Merges cleanly on origin/master; the CHANGELOG line conflicts with sibling PRs, which is trivial.


Generated by Claude Code

@MendixMau

Copy link
Copy Markdown
Owner Author

Review: MERGE stands — re-check of 1ec86a6: T11 now fails unless the refusal says UNVERIFIED, so a hook crash can no longer pass it. test-model-stamp 41/0. The known limit is now in the PR body. Merges cleanly on origin/master.


Generated by Claude Code

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.

pre-commit model-stamp refuses every commit when the .mpr lives in a separate git repo (GIT_INDEX_FILE leaks into git -C $MODEL_DIR)

2 participants