diff --git a/extensions/git/src/fileSystemProvider.ts b/extensions/git/src/fileSystemProvider.ts index 8b8f9fc65af..19928863832 100644 --- a/extensions/git/src/fileSystemProvider.ts +++ b/extensions/git/src/fileSystemProvider.ts @@ -18,7 +18,7 @@ interface CacheRow { const THREE_MINUTES = 1000 * 60 * 3; const FIVE_MINUTES = 1000 * 60 * 5; -function sanitizeRef(ref: string, path: string, repository: Repository): string { +function sanitizeRef(ref: string, path: string, submoduleOf: string | undefined, repository: Repository): string { if (ref === '~') { const fileUri = Uri.file(path); const uriString = fileUri.toString(); @@ -30,6 +30,11 @@ function sanitizeRef(ref: string, path: string, repository: Repository): string return `:${ref[1]}`; } + // Submodule HEAD + if (submoduleOf && (ref === 'index' || ref === 'wt')) { + return 'HEAD'; + } + return ref; } @@ -141,7 +146,7 @@ export class GitFileSystemProvider implements FileSystemProvider { } try { - const details = await repository.getObjectDetails(sanitizeRef(ref, path, repository), path); + const details = await repository.getObjectDetails(sanitizeRef(ref, path, submoduleOf, repository), path); return { type: FileType.File, size: details.size, mtime: this.mtime, ctime: 0 }; } catch { // Empty tree @@ -198,7 +203,7 @@ export class GitFileSystemProvider implements FileSystemProvider { this.cache.set(uri.toString(), cacheValue); try { - return await repository.buffer(sanitizeRef(ref, path, repository), path); + return await repository.buffer(sanitizeRef(ref, path, submoduleOf, repository), path); } catch { // Empty tree if (ref === await repository.getEmptyTree()) { diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 1026faefacb..2944f1d2f17 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -1392,7 +1392,7 @@ export class Repository { } const { mode, object, size } = elements[0]; - return { mode, object, size: parseInt(size) }; + return { mode, object, size: parseInt(size) || 0 }; } async lstree(treeish: string, path?: string): Promise {