Skip to content

Commit

Permalink
fixes #38298
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Dec 7, 2017
1 parent c1b95bc commit ce38ff3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,29 +207,31 @@ export class CommandCenter {
}

try {
if (ref === '~') {
let gitRef = ref;

if (gitRef === '~') {
const uriString = uri.toString();
const [indexStatus] = repository.indexGroup.resourceStates.filter(r => r.resourceUri.toString() === uriString);
ref = indexStatus ? '' : 'HEAD';
gitRef = indexStatus ? '' : 'HEAD';
}

const { size, object } = await repository.lstree(ref, uri.fsPath);
const { size, object } = await repository.lstree(gitRef, uri.fsPath);
const { mimetype, encoding } = await repository.detectObjectType(object);

if (mimetype === 'text/plain') {
return toGitUri(uri, ref);
}

if (size > 1000000) { // 1 MB
return Uri.parse(`data:;label:${path.basename(uri.fsPath)};description:${ref},`);
return Uri.parse(`data:;label:${path.basename(uri.fsPath)};description:${gitRef},`);
}

if (ImageMimetypes.indexOf(mimetype) > -1) {
const contents = await repository.buffer(ref, uri.fsPath);
return Uri.parse(`data:${mimetype};label:${path.basename(uri.fsPath)};description:${ref};size:${size};base64,${contents.toString('base64')}`);
const contents = await repository.buffer(gitRef, uri.fsPath);
return Uri.parse(`data:${mimetype};label:${path.basename(uri.fsPath)};description:${gitRef};size:${size};base64,${contents.toString('base64')}`);
}

return Uri.parse(`data:;label:${path.basename(uri.fsPath)};description:${ref},`);
return Uri.parse(`data:;label:${path.basename(uri.fsPath)};description:${gitRef},`);

} catch (err) {
return toGitUri(uri, ref);
Expand Down

0 comments on commit ce38ff3

Please sign in to comment.