mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 20:13:32 +01:00
Show empty image instead of error in git diff view for newly staged images
Fixes #86389 Fixes #86776 Uses `fs.stat` to check if we are showing an untracked image in the git diff view. Also required fixing `stat` for `gitfs` so that it can try to return the proper sizes for objects
This commit is contained in:
@@ -8,6 +8,7 @@ import { debounce, throttle } from './decorators';
|
||||
import { fromGitUri, toGitUri } from './uri';
|
||||
import { Model, ModelChangeEvent, OriginalResourceChangeEvent } from './model';
|
||||
import { filterEvent, eventToPromise, isDescendant, pathEquals, EmptyDisposable } from './util';
|
||||
import { Repository } from './repository';
|
||||
|
||||
interface CacheRow {
|
||||
uri: Uri;
|
||||
@@ -116,15 +117,21 @@ export class GitFileSystemProvider implements FileSystemProvider {
|
||||
return EmptyDisposable;
|
||||
}
|
||||
|
||||
stat(uri: Uri): FileStat {
|
||||
const { submoduleOf } = fromGitUri(uri);
|
||||
async stat(uri: Uri): Promise<FileStat> {
|
||||
const { submoduleOf, path, ref } = fromGitUri(uri);
|
||||
const repository = submoduleOf ? this.model.getRepository(submoduleOf) : this.model.getRepository(uri);
|
||||
|
||||
if (!repository) {
|
||||
throw FileSystemError.FileNotFound();
|
||||
}
|
||||
|
||||
return { type: FileType.File, size: 0, mtime: this.mtime, ctime: 0 };
|
||||
let size = 0;
|
||||
try {
|
||||
const details = await repository.getObjectDetails(this.fixRef(ref, path, repository), path);
|
||||
size = details.size;
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
return { type: FileType.File, size: size, mtime: this.mtime, ctime: 0 };
|
||||
}
|
||||
|
||||
readDirectory(): Thenable<[string, FileType][]> {
|
||||
@@ -136,7 +143,7 @@ export class GitFileSystemProvider implements FileSystemProvider {
|
||||
}
|
||||
|
||||
async readFile(uri: Uri): Promise<Uint8Array> {
|
||||
let { path, ref, submoduleOf } = fromGitUri(uri);
|
||||
const { path, ref, submoduleOf } = fromGitUri(uri);
|
||||
|
||||
if (submoduleOf) {
|
||||
const repository = this.model.getRepository(submoduleOf);
|
||||
@@ -165,17 +172,8 @@ export class GitFileSystemProvider implements FileSystemProvider {
|
||||
|
||||
this.cache.set(uri.toString(), cacheValue);
|
||||
|
||||
if (ref === '~') {
|
||||
const fileUri = Uri.file(path);
|
||||
const uriString = fileUri.toString();
|
||||
const [indexStatus] = repository.indexGroup.resourceStates.filter(r => r.resourceUri.toString() === uriString);
|
||||
ref = indexStatus ? '' : 'HEAD';
|
||||
} else if (/^~\d$/.test(ref)) {
|
||||
ref = `:${ref[1]}`;
|
||||
}
|
||||
|
||||
try {
|
||||
return await repository.buffer(ref, path);
|
||||
return await repository.buffer(this.fixRef(ref, path, repository), path);
|
||||
} catch (err) {
|
||||
return new Uint8Array(0);
|
||||
}
|
||||
@@ -196,4 +194,16 @@ export class GitFileSystemProvider implements FileSystemProvider {
|
||||
dispose(): void {
|
||||
this.disposables.forEach(d => d.dispose());
|
||||
}
|
||||
|
||||
private fixRef(ref: string, path: string, repository: Repository): string {
|
||||
if (ref === '~') {
|
||||
const fileUri = Uri.file(path);
|
||||
const uriString = fileUri.toString();
|
||||
const [indexStatus] = repository.indexGroup.resourceStates.filter(r => r.resourceUri.toString() === uriString);
|
||||
return indexStatus ? '' : 'HEAD';
|
||||
} else if (/^~\d$/.test(ref)) {
|
||||
return `:${ref[1]}`;
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user