fix: make GitWalkerFs#content handle symlinks correctly#2271
fix: make GitWalkerFs#content handle symlinks correctly#2271jcubic merged 5 commits intoisomorphic-git:mainfrom
GitWalkerFs#content handle symlinks correctly#2271Conversation
📝 WalkthroughWalkthroughGitWalkerFs now returns symlink targets (via readlink) as entry content; tests and fixture-copy helpers were updated to preserve and validate symlink behavior. A new contributor, Mateusz Burzyński (Andarist), was added to contributors metadata and README. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Walker as GitWalkerFs
participant FS as Filesystem (OS)
participant Cache as Cache
participant Git as Git object store
Walker->>Cache: lookup(entry.path)
alt cached
Cache-->>Walker: cached entry
else not cached
Walker->>FS: stat(entry.path)
FS-->>Walker: mode
alt mode is symlink (0o120000)
Walker->>FS: readlink(entry.path)
FS-->>Walker: targetPath
Walker->>Git: hashBlob(targetPath) %% (hash blob of targetPath string as content)
Git-->>Walker: blobOid
Walker->>Cache: store(entry with content=targetPath, oid=blobOid, mode=symlink)
Walker-->>Caller: entry(content=targetPath, oid=blobOid, mode=symlink)
else regular file
Walker->>FS: readFile(entry.path)
FS-->>Walker: fileContent
Walker->>Walker: apply core.autocrlf if configured
Walker->>Git: hashBlob(fileContent)
Git-->>Walker: blobOid
Walker->>Cache: store(entry with content=fileContent, oid=blobOid, mode=file)
Walker-->>Caller: entry(content=fileContent, oid=blobOid, mode=file)
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
| expect(entry.content).toBe('a.txt') | ||
| }) | ||
|
|
||
| it('symlink oid works for non-existent targets', async () => { |
There was a problem hiding this comment.
I ran into a crash caused by null content here:
isomorphic-git/src/models/GitWalkerFs.js
Line 108 in 93d3ef9
The content method was called by oid method and the stack trace looked like this:
TypeError: Cannot read properties of null (reading 'length')
at GitWalkerFs.content (/ghcommit/node_modules/.pnpm/[email protected]/node_modules/isomorphic-git/index.cjs:4249:37)
at /ghcommit/node_modules/.pnpm/[email protected]/node_modules/isomorphic-git/index.cjs:4276:27
at /ghcommit/node_modules/.pnpm/[email protected]/node_modules/isomorphic-git/index.cjs:1026:16
|
If |
|
@sdarwin thank you for a promp review, I pushed out the requested change |
|
There are broken tests: |
|
@jcubic initially I ran into some classic jest/esm/node/whatever issues when trying to run tests locally so I couldn't quickly verify everything. I solved this and was able to investigate and fix those failures. It turns out that:
|
|
Can you explain why you don't read the target of the symlink? What is the use of the walk function if it doesn't return the content of the file, only a path? If you run the walk on the code base, you will need to check if the content is path or file content. Isn't it supposed to be something like: let filepath = `${dir}/${entry._fullpath}`;
if ((await entry.mode()) >> 12 === 0b1010) {
filepath = await fs.readlink(filepath);
}
const config = await this._getGitConfig(fs, gitdir)
const autocrlf = await config.get('core.autocrlf')
const content = await fs.read(filepath, { autocrlf }) |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@__tests__/test-walk-in-submodule.js`:
- Around line 592-649: Replace the hardcoded symlink mode 0o120000 in both
tests' assertions (the expect(entry.mode).toBe(0o120000) lines) with the
BrowserFS-aware mode value computed earlier in this file (the same
helper/variable used above to adapt for BrowserFS’ 555/exec-bit quirk), so both
symlink-mode assertions use that shared expected-mode variable instead of the
literal 0o120000.
It's about:
From what I understand, I added new tests to demo what I mean. |
|
ok, make sense. |
|
🎉 This PR is included in version 1.36.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I'm fixing a bug or typo
npm run add-contributorand follow the prompts to add yourself to the READMESummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.