Skip to content

Commit 3f9e717

Browse files
committed
Merge commit 'refs/pull/49397/head' of github.com:Microsoft/vscode into pr/49397
2 parents 95773dc + 375411e commit 3f9e717

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

extensions/git/src/git.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,27 @@ export class Repository {
751751
return { mode, object, size: parseInt(size) };
752752
}
753753

754+
async lstreeOutput(treeish: string, path: string): Promise<string> {
755+
if (!treeish) { // index
756+
const { stdout } = await this.run(['ls-files', '--stage', '--', path]);
757+
return stdout;
758+
}
759+
760+
const { stdout } = await this.run(['ls-tree', '-l', treeish, '--', path]);
761+
return stdout;
762+
}
763+
764+
async relativePathToGitRelativePath(treeish: string, path: string): Promise<string> {
765+
let gitPath: string = path;
766+
const pathPrefix = path.substring(0, path.lastIndexOf('/'));
767+
const lstOutput = await this.lstreeOutput(treeish, pathPrefix + '/');
768+
const findResult = lstOutput.toUpperCase().indexOf(path.toUpperCase());
769+
if (findResult) {
770+
gitPath = lstOutput.substr(findResult, path.length);
771+
}
772+
return gitPath;
773+
}
774+
754775
async detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }> {
755776
const child = await this.stream(['show', object]);
756777
const buffer = await readBytes(child.stdout, 4100);

extensions/git/src/repository.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,12 +876,17 @@ export class Repository implements Disposable {
876876
}
877877

878878
async show(ref: string, filePath: string): Promise<string> {
879-
return this.run(Operation.Show, () => {
880-
const relativePath = path.relative(this.repository.root, filePath).replace(/\\/g, '/');
879+
return this.run(Operation.Show, async () => {
880+
let relativePath = path.relative(this.repository.root, filePath).replace(/\\/g, '/');
881881
const configFiles = workspace.getConfiguration('files', Uri.file(filePath));
882882
const defaultEncoding = configFiles.get<string>('encoding');
883883
const autoGuessEncoding = configFiles.get<boolean>('autoGuessEncoding');
884884

885+
if (ref === '') {
886+
ref = 'HEAD';
887+
}
888+
889+
relativePath = await this.repository.relativePathToGitRelativePath(ref, relativePath);
885890
return this.repository.bufferString(`${ref}:${relativePath}`, defaultEncoding, autoGuessEncoding);
886891
});
887892
}

0 commit comments

Comments
 (0)