From 0c348cdb0f52679ed85ea123873deb3109874969 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 22 Mar 2017 00:55:01 -0400 Subject: [PATCH] Fixes exception when commit has no file --- src/git/models/commit.ts | 184 +++++++++++++++++++++++------------------------ 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/src/git/models/commit.ts b/src/git/models/commit.ts index 5adbd81..4f01ad1 100644 --- a/src/git/models/commit.ts +++ b/src/git/models/commit.ts @@ -1,94 +1,94 @@ -'use strict'; -import { Uri } from 'vscode'; -import { Git } from '../git'; -import * as path from 'path'; - -export interface IGitAuthor { - name: string; - lineCount: number; -} - -export interface IGitCommit { - repoPath: string; - sha: string; - fileName: string; - author: string; - date: Date; - message: string; - lines: IGitCommitLine[]; - originalFileName?: string; - previousSha?: string; - previousFileName?: string; - - readonly isUncommitted: boolean; - previousUri: Uri; - uri: Uri; -} - -export interface IGitCommitLine { - sha: string; - previousSha?: string; - line: number; - originalLine: number; - code?: string; -} - -export class GitCommit implements IGitCommit { - - lines: IGitCommitLine[]; - originalFileName?: string; - previousSha?: string; - previousFileName?: string; - workingFileName?: string; - private _isUncommitted: boolean | undefined; - - constructor( - public repoPath: string, - public sha: string, - public fileName: string, - public author: string, - public date: Date, - public message: string, - lines?: IGitCommitLine[], - originalFileName?: string, - previousSha?: string, - previousFileName?: string - ) { - this.fileName = this.fileName.replace(/, ?$/, ''); - - this.lines = lines || []; - this.originalFileName = originalFileName; - this.previousSha = previousSha; - this.previousFileName = previousFileName; - } - - get shortSha() { - return this.sha.substring(0, 8); - } - - get isUncommitted(): boolean { - if (this._isUncommitted === undefined) { - this._isUncommitted = Git.isUncommitted(this.sha); - } - return this._isUncommitted; - } - - get previousShortSha() { - return this.previousSha && this.previousSha.substring(0, 8); - } - - get previousUri(): Uri { - return this.previousFileName ? Uri.file(path.resolve(this.repoPath, this.previousFileName)) : this.uri; - } - - get uri(): Uri { - return Uri.file(path.resolve(this.repoPath, this.originalFileName || this.fileName)); - } - - getFormattedPath(separator: string = ' \u00a0\u2022\u00a0 '): string { +'use strict'; +import { Uri } from 'vscode'; +import { Git } from '../git'; +import * as path from 'path'; + +export interface IGitAuthor { + name: string; + lineCount: number; +} + +export interface IGitCommit { + repoPath: string; + sha: string; + fileName: string; + author: string; + date: Date; + message: string; + lines: IGitCommitLine[]; + originalFileName?: string; + previousSha?: string; + previousFileName?: string; + + readonly isUncommitted: boolean; + previousUri: Uri; + uri: Uri; +} + +export interface IGitCommitLine { + sha: string; + previousSha?: string; + line: number; + originalLine: number; + code?: string; +} + +export class GitCommit implements IGitCommit { + + lines: IGitCommitLine[]; + originalFileName?: string; + previousSha?: string; + previousFileName?: string; + workingFileName?: string; + private _isUncommitted: boolean | undefined; + + constructor( + public repoPath: string, + public sha: string, + public fileName: string, + public author: string, + public date: Date, + public message: string, + lines?: IGitCommitLine[], + originalFileName?: string, + previousSha?: string, + previousFileName?: string + ) { + this.fileName = this.fileName && this.fileName.replace(/, ?$/, ''); + + this.lines = lines || []; + this.originalFileName = originalFileName; + this.previousSha = previousSha; + this.previousFileName = previousFileName; + } + + get shortSha() { + return this.sha.substring(0, 8); + } + + get isUncommitted(): boolean { + if (this._isUncommitted === undefined) { + this._isUncommitted = Git.isUncommitted(this.sha); + } + return this._isUncommitted; + } + + get previousShortSha() { + return this.previousSha && this.previousSha.substring(0, 8); + } + + get previousUri(): Uri { + return this.previousFileName ? Uri.file(path.resolve(this.repoPath, this.previousFileName)) : this.uri; + } + + get uri(): Uri { + return Uri.file(path.resolve(this.repoPath, this.originalFileName || this.fileName)); + } + + getFormattedPath(separator: string = ' \u00a0\u2022\u00a0 '): string { const directory = Git.normalizePath(path.dirname(this.fileName)); - return (!directory || directory === '.') - ? path.basename(this.fileName) - : `${path.basename(this.fileName)}${separator}${directory}`; - } + return (!directory || directory === '.') + ? path.basename(this.fileName) + : `${path.basename(this.fileName)}${separator}${directory}`; + } } \ No newline at end of file