diff --git a/extensions/git/src/fileSystemProvider.ts b/extensions/git/src/fileSystemProvider.ts index 6e30118128d..8b8f9fc65af 100644 --- a/extensions/git/src/fileSystemProvider.ts +++ b/extensions/git/src/fileSystemProvider.ts @@ -144,6 +144,12 @@ export class GitFileSystemProvider implements FileSystemProvider { const details = await repository.getObjectDetails(sanitizeRef(ref, path, repository), path); return { type: FileType.File, size: details.size, mtime: this.mtime, ctime: 0 }; } catch { + // Empty tree + if (ref === await repository.getEmptyTree()) { + this.logger.warn(`[GitFileSystemProvider][stat] Empty tree - ${uri.toString()}`); + return { type: FileType.File, size: 0, mtime: this.mtime, ctime: 0 }; + } + // File does not exist in git. This could be because the file is untracked or ignored this.logger.warn(`[GitFileSystemProvider][stat] File not found - ${uri.toString()}`); throw FileSystemError.FileNotFound(); @@ -194,6 +200,12 @@ export class GitFileSystemProvider implements FileSystemProvider { try { return await repository.buffer(sanitizeRef(ref, path, repository), path); } catch { + // Empty tree + if (ref === await repository.getEmptyTree()) { + this.logger.warn(`[GitFileSystemProvider][readFile] Empty tree - ${uri.toString()}`); + return new Uint8Array(0); + } + // File does not exist in git. This could be because the file is untracked or ignored this.logger.warn(`[GitFileSystemProvider][readFile] File not found - ${uri.toString()}`); throw FileSystemError.FileNotFound(); diff --git a/extensions/git/src/timelineProvider.ts b/extensions/git/src/timelineProvider.ts index f29264e4078..90d8d28c396 100644 --- a/extensions/git/src/timelineProvider.ts +++ b/extensions/git/src/timelineProvider.ts @@ -222,6 +222,7 @@ export class GitTimelineProvider implements TimelineProvider { const openComparison = l10n.t('Open Comparison'); + const emptyTree = await repo.getEmptyTree(); const unpublishedCommits = await repo.getUnpublishedCommits(); const remoteHoverCommands = await provideSourceControlHistoryItemHoverCommands(this.model, repo); @@ -243,7 +244,8 @@ export class GitTimelineProvider implements TimelineProvider { const message = emojify(c.message); - const item = new GitTimelineItem(c.hash, commits[index + 1]?.hash ?? `${c.hash}^`, message, date?.getTime() ?? 0, c.hash, 'git:file:commit'); + const previousRef = commits[index + 1]?.hash ?? emptyTree; + const item = new GitTimelineItem(c.hash, previousRef, message, date?.getTime() ?? 0, c.hash, 'git:file:commit'); item.iconPath = new ThemeIcon('git-commit'); if (showAuthor) { item.description = c.authorName;