Skip to content

fix: write gitlink tree entries as commit in toMktreeFormat - #69

Draft
flyingrobots wants to merge 5 commits into
mainfrom
fix/46-gitlink-mktree-type
Draft

flyingrobots wants to merge 5 commits into
mainfrom
fix/46-gitlink-mktree-type

Conversation

@flyingrobots

Copy link
Copy Markdown
Member

Summary

GitTree.toMktreeFormat() takes each entry's type from its mode through GitTreeEntry.type() (which uses GitFileMode.getObjectType()), so a mode-160000 gitlink is written as 160000 commit <id>\t<path> instead of blob. Before this, GitPersistenceService.writeTree() could not write any tree holding a submodule: git mktree refused the line with object type (blob) doesn't match mode type (commit).

Tests

  • Unit: a gitlink serialises to 160000 commit <id>\tsub\n; a tree with every allowed mode carries tree, blob, blob, blob, commit.
  • Integration (real git mktree, SHA-1 and SHA-256 bare repositories): writeTree() of a blob plus a gitlink whose commit is not in the object database, read back with git ls-tree.

Closes #46

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

GitTree.toMktreeFormat() took the type from isTree() alone, so a mode-160000
gitlink was written as blob and git mktree refused it. The type now comes from
GitTreeEntry.type(), which maps the mode through GitFileMode.getObjectType().

Closes #46
@flyingrobots

Copy link
Copy Markdown
Member Author

Pushed 926a002 and b287253.

  • 926a002 test: unit tests for a gitlink and for every tree mode in toMktreeFormat(), and test/GitlinkTreeEntries.test.js running writeTree() through real git mktree in SHA-1 and SHA-256 bare repositories (registered in test/deno_entry.js).
  • RED on the parent: the two unit tests received 160000 blob ...; both integration tests failed with fatal: entry 'sub' object type (blob) doesn't match mode type (commit) (exit 128).
  • b287253 fix: toMktreeFormat() uses entry.type() (GitFileMode.getObjectType()), no new mode table; CHANGELOG entry under Unreleased / Fixed.
  • GREEN: pre-push npm test passed on node, bun and deno; npm run lint clean. The existing serializes to mktree format test is unedited and passes.

@flyingrobots

flyingrobots commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

Footprint

5 files, +124/-4 · origin/main...origin/fix/46-gitlink-mktree-type

Structural, as graft struct review reads it: 0 files changed shape (+0/-0/~0 symbols), 2 labelled formatting.

  • graft's label, not footprint's claim: it saw no symbol added, removed or changed in src/domain/entities/GitTree.js, test/deno_entry.js. A changed value inside an existing symbol (a rule table, a constant) can carry that label, so read the diff.

  • No symbol was added, removed or changed. Nothing's public shape moved.

Composition
pie showData
    title Changed lines by file kind
    "source" : 8
    "test" : 116
    "docs" : 4
Loading
Kind Files +/- Share
source 1 +4/-4 6.3%
test 3 +116/-0 90.6%
docs 1 +4/-0 3.1%
total 5 +124/-4 100%
Files (5)

docs

  • CHANGELOG.md +4/-0

source

  • src/domain/entities/GitTree.js +4/-4

test

  • test/GitlinkTreeEntries.test.js +92/-0
  • test/deno_entry.js +1/-0
  • test/domain/entities/GitTree.test.js +23/-0

Figures computed from git diff --numstat. Composition is a sanity check, not a verdict.

Before merge

  • 1 changed file match the guard rule: CHANGELOG.md (version).

After merge

No landing steps are declared: RELEASE.md is absent; AGENTS.md is absent. footprint states none rather than inventing them.

After-merge steps are read from this repository's own RELEASE.md and AGENTS.md, never invented. The guard rule is path patterns, documented in footprint's docs/topics/landing/README.md.

Blast radius

+0 added / -0 removed / ~0 signature-changed exported symbols · a52ec58eb6f071188e8e2a218b1ca21a28a50fe4 → da7deb911f6b711d8cb1d9908d1433619e260dfd · graft struct exports reads this as a none change

  • No exported symbol was added, removed or re-signed.

Exported symbols from graft struct exports --json (graft.cli.struct_exports 1.0.0). Whatever graft parses counts as an export surface, including fields in config and lock files.

Call sites are footprint's own whole-word identifier scan, not graft's: every whole-word occurrence of the name in the tracked, non-binary files of the working tree (grep -w's boundary -- a letter, digit or underscore in any script). It counts the declaration itself and a mention in a comment, a string or prose, and it cannot see a call through dynamic dispatch or a re-export under another name. Evidence to check, not a call graph.

The grouping. A system is the first path segment of a call site's repository-relative path: the directory immediately under the repository root, however deep the file sits inside it. A file at the repository root has no such segment and is grouped under (unassigned), which is listed last and never dropped. Systems are ordered by name so the grouping follows the tree rather than the order the scan found the sites in. The mitigations. Every row's mitigation is derived from two reported facts about that call site and nothing else: whether it is in the very file the symbol is exported from, and what classify() calls that file. A call site in the symbol's own declaring file, or in a test file, is "None needed"; any other call site states the system it is in, or that it is outside every known system. No mitigation is a judgement about importance, risk or coverage, and none is advice: footprint reports and does not judge (AGENTS.md).

Every changed source file was in a language footprint recognises graft's grammars can parse.

Open pull requests

1 of 1 other open pull request touches a file this change touches.

Proposed merge order (2 waves)

Wave 1 — #69

Wave 2 — #83, after wave 1

Pull requests from gh pr list; their files from gh pr diff --name-only; the symbols of a shared file from git diff -U0 against each side's merge base and the top-level symbols of graft read outline at both ends (0 of at most 24 outline calls this run). Merge waves are greedy first-fit over the conflict graph: a proposal, not a minimum, and not a gate.

Changelog
Timestamp SHA Change Reason Remarks
2026-12-01T14:28:00Z b287253 First report: 5 files, +94/-4; no export added, removed or re-signed Pull request opened No call-site rows to assess: no export moved; toMktreeFormat output changes only for mode-160000 entries
2026-12-01T14:41:48Z da7deb9 Test isolates host git config; CHANGELOG reworded; still no export moved Review fix No call-site rows to assess

@flyingrobots

Copy link
Copy Markdown
Member Author

Automated review, round 1 (head b287253)

No findings. I found no P0–P3 defect introduced by git diff origin/main...HEAD at b287253031fb553d8aac2ba41f195adccb1d1998.

The change at src/domain/entities/GitTree.js:112 correctly uses entry.type(). That delegates to the existing GitFileMode.getObjectType(), which returns commit for mode 160000. String interpolation serializes the returned GitObjectType correctly. No new mode-to-type table, dependency, or architectural layer is introduced.

The constructor already normalizes plain-object entries into GitTreeEntry instances, so calling type() preserves the documented input contract. The method remains synchronous and introduces no resource ownership or asynchronous race. Regular files, executable files, symlinks, directories, ordering, and newline behavior remain unchanged.

The tests provide meaningful coverage:

  • The new unit assertions compare complete serialized strings against explicit expected values, including all five supported modes. They do not derive expected types from the implementation.
  • The integration tests execute real git in fresh bare SHA-1 and SHA-256 repositories, write through GitPersistenceService.writeTree(), and independently inspect the result with cat-file and ls-tree.
  • The gitlink deliberately names a missing commit, covering normal submodule behavior without requiring --missing. The assertions can fail, and temporary repositories are registered for cleanup before initialization.

Validation ran in disposable Docker copies with the repository mounted read-only:

Check Result
Node, the two focused test files 7 passed
Bun, the two focused test files 7 passed
Deno, filtered tree and gitlink suites 5 suites passed, 14 steps
Restored old serialization behavior in a disposable Node copy Both new unit tests and both integration cases failed
git diff --check origin/main...HEAD Passed

The CHANGELOG accurately describes the fix. I found no README or documentation claim contradicted by the change. This was focused validation, not a full-suite run. Repository files remain unchanged, and the worktree is clean.

🎬 plumbing review 🟢 100% (1/1) [plumbing:🟢]
→ no change

VERDICT: APPROVE

@flyingrobots

Copy link
Copy Markdown
Member Author

Baker Street review (head b287253): CHANGES_REQUIRED

The #46 fix itself was found correct: RED on base and GREEN at head for all four new tests (Node, Bun), Deno subset green, lint clean, CHANGELOG accurate.

The blocking finding is pre-existing and outside #46's scope:

  • F-1 (HIGH, pre-existing): GitTreeEntrySchema (src/domain/schemas/GitTreeEntrySchema.js:11) accepts \n (and NUL) in path, and toMktreeFormat() joins lines with \n for git mktree without -z. A path such as "a\n160000 commit <id>\tsmuggled" makes writeTree() succeed with an entry the caller never supplied. This happens on base too. The suggested repair is to reject \n and NUL in tree-entry paths; -z alone is not enough.

#46 lists "Other changes to GitTree, GitTreeEntry or GitFileMode" as out of scope, so I have not made that change here. I've left this PR as a draft and handed it back to the coordinator to decide: a separate issue merged first, widening #46, or recording explicit acceptance of F-1.

Informational follow-ups (not blocking): F-2, the plumbing under test in test/GitlinkTreeEntries.test.js inherits host git config (only the oracle is pinned). F-3, the RED evidence for the integration tests is a bare code 128; the exact git message was captured separately in the earlier comment. F-4, the CHANGELOG's "holds a submodule" means the gitlink entry only, not .gitmodules. F-5, GitTreeEntry is not a public export.

@flyingrobots

Copy link
Copy Markdown
Member Author

Pushed 8a208c7 and da7deb9, following the coordinator's decision. F-1 is now tracked separately in #84, which merges first, and stays out of this PR.

  • F-2: test/GitlinkTreeEntries.test.js now runs inside one suite that sets GIT_CONFIG_GLOBAL=/dev/null, GIT_CONFIG_NOSYSTEM=1 and GIT_ATTR_NOSYSTEM=1, unsets XDG_CONFIG_HOME, and sets HOME to a temporary directory for the whole file, then restores the original environment afterwards. This is the same pattern test/Sha256Repositories.test.js uses. The settings reach both the plumbing under test and the git oracle.
  • F-4: the CHANGELOG entry now says writeTree() writes the gitlink tree entry only. Plumbing does not write .gitmodules, and it does not clone, fetch or update submodules.
  • The pre-push npm test passed on node, bun and deno, and lint is clean.
  • The PR stays a draft until A tree entry path with a newline or NUL can inject extra entries into git mktree #84 merges and a fresh Baker Street review runs.

This branch has not been deployed

No deployments
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.

GitTree.toMktreeFormat() labels a mode-160000 gitlink entry commit, not blob

1 participant