Skip to content

fix: introduce GitRootPath branded type and fix getModifiedFiles bug - #3620

Draft
suzuki-shunsuke wants to merge 1 commit into
mainfrom
feat/git-root-path-branded-type
Draft

fix: introduce GitRootPath branded type and fix getModifiedFiles bug#3620
suzuki-shunsuke wants to merge 1 commit into
mainfrom
feat/git-root-path-branded-type

Conversation

@suzuki-shunsuke

Copy link
Copy Markdown
Owner

Summary

  • Introduce GitRootPath branded type (subtype of AbsolutePath) that can only be obtained from getRootDir(), preventing arbitrary absolute paths from being passed where a git root is required
  • Fix bug in scaffold-module and scaffold-working-dir where replaceInFiles called getModifiedFiles with a subdirectory as cwd, causing git ls-files to return paths relative to that subdirectory instead of the git root
  • Update git functions (getModifiedFiles, getCurrentBranch, hasFileChangedPorcelain, listWorkingDirFiles, checkGitDiff) to require GitRootPath instead of AbsolutePath
  • Change Config.git_root_dir type from AbsolutePath to GitRootPath

Test plan

  • npm t — all 794 tests pass
  • npm run lint — no type errors
  • npm run fmt — code formatted

🤖 Generated with Claude Code

GitRootPath is a subtype of AbsolutePath that can only be obtained from
getRootDir() (git rev-parse --show-toplevel). This prevents passing
arbitrary absolute paths where a git root is required.

The replaceInFiles functions in scaffold-module and scaffold-working-dir
were calling getModifiedFiles with a subdirectory as cwd, but git ls-files
returns paths relative to cwd. Since cwd was not the git root, the
returned paths were incorrectly typed as GitRelativePath. Now these
callers pass the git root as cwd and use toGitRelative to compute the
directory argument, fixing the path resolution bug.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@suzuki-shunsuke
suzuki-shunsuke marked this pull request as draft February 8, 2026 12:54
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