提交 375411e6 编写于 作者: A Alex Ross

Fixes #48714: Added conversion from local case of the file to git case. This...

Fixes #48714: Added conversion from local case of the file to git case.  This does not fix the view in the Explorer, but this solution should be easy to apply to that issue too.
上级 96248596
......@@ -738,6 +738,27 @@ export class Repository {
return { mode, object, size: parseInt(size) };
}
async lstreeOutput(treeish: string, path: string): Promise<string> {
if (!treeish) { // index
const { stdout } = await this.run(['ls-files', '--stage', '--', path]);
return stdout;
}
const { stdout } = await this.run(['ls-tree', '-l', treeish, '--', path]);
return stdout;
}
async relativePathToGitRelativePath(treeish: string, path: string): Promise<string> {
let gitPath: string = path;
const pathPrefix = path.substring(0, path.lastIndexOf('/'));
const lstOutput = await this.lstreeOutput(treeish, pathPrefix + '/');
const findResult = lstOutput.toUpperCase().indexOf(path.toUpperCase());
if (findResult) {
gitPath = lstOutput.substr(findResult, path.length);
}
return gitPath;
}
async detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }> {
const child = await this.stream(['show', object]);
const buffer = await readBytes(child.stdout, 4100);
......
......@@ -811,12 +811,17 @@ export class Repository implements Disposable {
}
async show(ref: string, filePath: string): Promise<string> {
return this.run(Operation.Show, () => {
const relativePath = path.relative(this.repository.root, filePath).replace(/\\/g, '/');
return this.run(Operation.Show, async () => {
let relativePath = path.relative(this.repository.root, filePath).replace(/\\/g, '/');
const configFiles = workspace.getConfiguration('files', Uri.file(filePath));
const defaultEncoding = configFiles.get<string>('encoding');
const autoGuessEncoding = configFiles.get<boolean>('autoGuessEncoding');
if (ref === '') {
ref = 'HEAD';
}
relativePath = await this.repository.relativePathToGitRelativePath(ref, relativePath);
return this.repository.bufferString(`${ref}:${relativePath}`, defaultEncoding, autoGuessEncoding);
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册