Skip to content

fix(statusMatrix): do not traverse symlinks in GitWalkerFs (#1215) - #2382

Merged
jcubic merged 3 commits into
isomorphic-git:mainfrom
minutechreview:fix/symlink-ignored-dir-statusMatrix
Jul 21, 2026
Merged

jcubic merged 3 commits into
isomorphic-git:mainfrom
minutechreview:fix/symlink-ignored-dir-statusMatrix

Conversation

@minutechreview

@minutechreview minutechreview commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #1215.

When a repository contains a symlink targeting an ignored directory (such as node_modules), statusMatrix() was previously traversing the symlink target because GitWalkerFs.readdir() called fs.readdir(), which follows directory symlinks. As a result, files within the ignored directory were incorrectly reported as untracked/new files.

This change adds a check in GitWalkerFs.readdir() to ensure readdir is only performed on tree entries (actual directories), matching the behavior of GitWalkerRepo and GitWalkerIndex.

Changes Made

  1. src/models/GitWalkerFs.js: Added if ((await entry.type()) !== 'tree') return null inside GitWalkerFs.readdir(entry).
  2. __tests__/test-statusMatrix.js: Added unit test statusMatrix with symlink targeting ignored directory to prevent regression.

Verification

  • Added unit test passes cleanly in Jest.
  • Tested against reproduction case, confirming statusMatrix() output matches native git status --porcelain=v1.

Summary by CodeRabbit

  • Bug Fixes

    • Improved directory reading behavior by safely short-circuiting when encountering non-directory entries.
  • Tests

    • Added coverage for status matrix behavior when a symlink points to an ignored directory, ensuring expected paths and status/stage counts are produced.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 88f16881-69a6-4ba4-afed-60f18b080345

📥 Commits

Reviewing files that changed from the base of the PR and between 5f8efc3 and 6595f84.

📒 Files selected for processing (1)
  • __tests__/server-only.test-statusMatrix-symlink.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/server-only.test-statusMatrix-symlink.js

📝 Walkthrough

Walkthrough

GitWalkerFs.readdir now returns null for non-tree entries, preventing symlink traversal into directory contents. A new test verifies statusMatrix handling for symlinks targeting ignored directories.

Changes

Status matrix symlink handling

Layer / File(s) Summary
Guard non-tree traversal
src/models/GitWalkerFs.js, __tests__/server-only.test-statusMatrix-symlink.js
readdir skips non-tree entries, and a Jasmine test verifies that an ignored-directory symlink produces only the expected .gitignore and symlink status entries.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit hopped through a symlink bright,
Found no ignored files in sight.
The tree stood still, the guard said “no,”
Status counts now neatly show.
Carrots cheer the tidy flow!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix to prevent statusMatrix from traversing symlinks in GitWalkerFs.
Linked Issues check ✅ Passed The code and regression test address #1215 by skipping traversal for symlinked ignored directories and matching git status behavior.
Out of Scope Changes check ✅ Passed The changes are limited to the symlink traversal fix and its regression test, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@__tests__/test-statusMatrix.js`:
- Line 426: Move the symlink test block around the existing symlink setup in
__tests__/test-statusMatrix.js into an appropriate server-only.test-* file,
preserving its assertion and behavior. Remove the now-unused native fs promises
import from __tests__/test-statusMatrix.js; both affected sites in that file
require changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f9434fb-b887-4f82-8590-24c876a92921

📥 Commits

Reviewing files that changed from the base of the PR and between b41b1ab and 21281e1.

📒 Files selected for processing (2)
  • __tests__/test-statusMatrix.js
  • src/models/GitWalkerFs.js

Comment thread __tests__/test-statusMatrix.js Resolved
@jcubic

jcubic commented Jul 20, 2026

Copy link
Copy Markdown
Member

Please run:

npx eslint --fix __tests__/server-only.test-statusMatrix-symlink.js

to fix linting errors

@jcubic

jcubic commented Jul 21, 2026

Copy link
Copy Markdown
Member

Thanks for the PR.

@jcubic
jcubic merged commit 90ea101 into isomorphic-git:main Jul 21, 2026
4 checks passed
@jcubic

jcubic commented Jul 21, 2026

Copy link
Copy Markdown
Member

🎉 This PR is included in version 1.38.10 🎉

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.

statusMatrix() does not work correctly when there is a symlink that targets an ignored directory

2 participants