diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index dd10c0a8f4cb1ee5afa95f9b209cbe3bd2f55011..37c91fac74c7f6a557ffe0794e36b2014078c8d2 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -762,9 +762,12 @@ export class Repository { async log(options?: LogOptions): Promise { const maxEntries = options && typeof options.maxEntries === 'number' && options.maxEntries > 0 ? options.maxEntries : 32; const args = ['log', '-' + maxEntries, `--pretty=format:${COMMIT_FORMAT}%x00%x00`]; - const gitResult = await this.run(args); - if (gitResult.exitCode) { - // An empty repo. + + let gitResult: IExecutionResult; + try { + gitResult = await this.run(args); + } catch (err) { + // An empty repo return []; } @@ -1164,9 +1167,15 @@ export class Repository { let mode: string; let add: string = ''; + let treeish: string = ''; + const commits = await this.log({ maxEntries: 1 }); + + if (commits.length > 0) { + treeish = 'HEAD'; + } try { - const details = await this.getObjectDetails('HEAD', path); + const details = await this.getObjectDetails(treeish, path); mode = details.mode; } catch (err) { if (err.gitErrorCode !== GitErrorCodes.UnknownPath) {