Skip to content

fix(walk): match git when trimming a gitfile path - #18

Merged
maxgfr merged 1 commit into
mainfrom
gitfile-trim-exactness
Sep 3, 2026
Merged

maxgfr merged 1 commit into
mainfrom
gitfile-trim-exactness

Conversation

@maxgfr

@maxgfr maxgfr commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Summary

Two nits from a follow-up review of #17, both confirmed against real git before changing anything.

1. The gitfile path was over-trimmed

gitDirOf stripped all trailing whitespace from a gitfile's path. Git strips exactly \n and \r — so a git directory whose name ends in a space is reachable through a gitfile, and trimming silently resolved it to a different directory whose info/exclude was then never read.

Probed against real git (a repo whose git dir is named store␠):

.git body real git
gitdir: <…/store␠>\n repo found
gitdir: <…/store>\n (path trimmed) fatal: not a git repository
gitdir: <…/store␠>\r\n repo found
gitdir: <…/store␠>␠␠␠\n (extra spaces) fatal: not a git repository

So git trims the line ending and nothing else. .replace(/\s+$/, "").replace(/[\r\n]+$/, "").

2. The size-cap test asserted nothing about the cap

Its body was 200 KB of x, which is not a gitfile at any size — so the subtree was kept with or without the cap and the test passed either way. The cap is only observable on a marker that would otherwise parse. The test now pairs an oversized well-formed gitfile (kept, subtree walked) with the same body under the cap (a boundary), and fails when the cap is raised.

Verification

  • pnpm typecheck, pnpm test (1 291 passed, 50 skipped), pnpm run check:build all pass.
  • Both new assertions are red against the current main: the trailing-space case yields ['dropped.ts', 'kept.ts'] instead of ['kept.ts'], and the cap case fails when MAX_GITFILE_BYTES is raised.
  • graph.json / symbols.json byte-identical on a real 2 924-file repo; the nested-repo fixture still resolves to the same 5 files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YDMVcJNo7WZh9xFAGWs2F8

A gitfile's path was trimmed of ALL trailing whitespace. Git trims
exactly `\n` and `\r`, so a git directory whose NAME ends in a space is
reachable through a gitfile — verified against real git, which resolves
`gitdir: <dir >` and rejects the same path trimmed. Trimming whitespace
silently pointed such a repo at a different directory, and its
`info/exclude` was then never found.

Also replaces the size-cap test's body. It used 200 KB of `x`, which is
not a gitfile at any size, so the assertion held with or without the cap
and proved nothing about reading. An oversized but WELL-FORMED gitfile
is the case the cap actually decides; the test now pairs one over the
cap (kept, subtree walked) with the same body under it (a boundary), and
fails if the cap is removed.

Claude-Session: https://claude.ai/code/session_01YDMVcJNo7WZh9xFAGWs2F8
@maxgfr
maxgfr merged commit 847010f into main Sep 3, 2026
2 checks passed
@maxgfr
maxgfr deleted the gitfile-trim-exactness branch September 3, 2026 04:59
github-actions Bot pushed a commit that referenced this pull request Sep 3, 2026
## [2.28.4](v2.28.3...v2.28.4) (2026-09-03)

### Bug Fixes

* **walk:** match git when trimming a gitfile path ([#18](#18)) ([847010f](847010f))
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.28.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant