Skip to content

fix(mcp): support symbolic links with mode 120000 and target path content - #1837

Open
ManoharPaturi wants to merge 1 commit into
anthropics:mainfrom
ManoharPaturi:fix/symlink-git-mode
Open

ManoharPaturi wants to merge 1 commit into
anthropics:mainfrom
ManoharPaturi:fix/symlink-git-mode

Conversation

@ManoharPaturi

Copy link
Copy Markdown

Closes #1768

Summary

Previously, getFileMode used stat() rather than lstat(). Because stat() follows symbolic links, fileStat.isSymbolicLink() was unreachable dead code, and commit_files would silently dereference symbolic links into regular file blobs. Furthermore, if getFileMode had used lstat() in isolation, Git tree entries would receive mode 120000 while readFile() would still supply the dereferenced file content instead of the link target path, corrupting the tree.

Changes

  • Extracted getFileMode to src/mcp/file-mode.ts and implemented proper symlink detection via lstat() returning 120000.
  • In commit_files (src/mcp/github-file-ops-server.ts), when a file has mode 120000, read the target path with readlink() and set the tree entry's content directly to the symlink target path rather than reading the dereferenced file bytes.
  • Added comprehensive unit tests in test/file-mode.test.ts verifying mode resolution for regular files (100644), executables (100755), directories (040000), symbolic links (120000), and missing files fallback.

Verification

  • bun test test/file-mode.test.ts passed (5/5).
  • Full test suite bun test passed (971 pass, 0 fail).
  • bun run typecheck passed cleanly.
  • bun run format:check passed.

…tent

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 17, 2026 06:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

getFileMode uses stat(), making its isSymbolicLink() branch unreachable dead code

2 participants