fix(getUncommittedDiff): Avoid false-positive diffs in getUncommittedDiff by detecting symlinked directories and skipping identical files
This commit is contained in:
@@ -156,6 +156,31 @@ export class GitRepo {
|
||||
plugins.path.join(this.repoDir, filepath),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
// Try to read from HEAD anyway - catches false positives from symlinks
|
||||
// where isomorphic-git reports symlink contents as "added" files
|
||||
try {
|
||||
headContent = await plugins.isomorphicGit
|
||||
.readBlob({
|
||||
fs: this.smartgitRef.envDeps.fs,
|
||||
dir: this.repoDir,
|
||||
oid: await plugins.isomorphicGit.resolveRef({
|
||||
fs: this.smartgitRef.envDeps.fs,
|
||||
dir: this.repoDir,
|
||||
ref: 'HEAD',
|
||||
}),
|
||||
filepath,
|
||||
})
|
||||
.then((result) => new TextDecoder().decode(result.blob));
|
||||
} catch (err) {
|
||||
// Check if this is a symlink false positive
|
||||
// Error: "was anticipated to be a tree but it is a blob" means parent path is a symlink
|
||||
if (err.message && err.message.includes('anticipated to be a tree but it is a blob')) {
|
||||
// This file is inside a symlinked directory - skip it entirely
|
||||
continue;
|
||||
}
|
||||
// Otherwise, file truly doesn't exist in HEAD - leave headContent empty for diff
|
||||
}
|
||||
}
|
||||
|
||||
// Handle deleted files
|
||||
@@ -175,6 +200,11 @@ export class GitRepo {
|
||||
}
|
||||
|
||||
if (headContent || workdirContent) {
|
||||
// Skip files with identical content (filters false positives from statusMatrix)
|
||||
if (headContent === workdirContent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const diff = plugins.diff.createTwoFilesPatch(
|
||||
filepath,
|
||||
filepath,
|
||||
|
||||
Reference in New Issue
Block a user