mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 18:48:45 -05:00
Fixes exception when commit has no file
This commit is contained in:
@@ -1,94 +1,94 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Uri } from 'vscode';
|
import { Uri } from 'vscode';
|
||||||
import { Git } from '../git';
|
import { Git } from '../git';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export interface IGitAuthor {
|
export interface IGitAuthor {
|
||||||
name: string;
|
name: string;
|
||||||
lineCount: number;
|
lineCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IGitCommit {
|
export interface IGitCommit {
|
||||||
repoPath: string;
|
repoPath: string;
|
||||||
sha: string;
|
sha: string;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
author: string;
|
author: string;
|
||||||
date: Date;
|
date: Date;
|
||||||
message: string;
|
message: string;
|
||||||
lines: IGitCommitLine[];
|
lines: IGitCommitLine[];
|
||||||
originalFileName?: string;
|
originalFileName?: string;
|
||||||
previousSha?: string;
|
previousSha?: string;
|
||||||
previousFileName?: string;
|
previousFileName?: string;
|
||||||
|
|
||||||
readonly isUncommitted: boolean;
|
readonly isUncommitted: boolean;
|
||||||
previousUri: Uri;
|
previousUri: Uri;
|
||||||
uri: Uri;
|
uri: Uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IGitCommitLine {
|
export interface IGitCommitLine {
|
||||||
sha: string;
|
sha: string;
|
||||||
previousSha?: string;
|
previousSha?: string;
|
||||||
line: number;
|
line: number;
|
||||||
originalLine: number;
|
originalLine: number;
|
||||||
code?: string;
|
code?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GitCommit implements IGitCommit {
|
export class GitCommit implements IGitCommit {
|
||||||
|
|
||||||
lines: IGitCommitLine[];
|
lines: IGitCommitLine[];
|
||||||
originalFileName?: string;
|
originalFileName?: string;
|
||||||
previousSha?: string;
|
previousSha?: string;
|
||||||
previousFileName?: string;
|
previousFileName?: string;
|
||||||
workingFileName?: string;
|
workingFileName?: string;
|
||||||
private _isUncommitted: boolean | undefined;
|
private _isUncommitted: boolean | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public repoPath: string,
|
public repoPath: string,
|
||||||
public sha: string,
|
public sha: string,
|
||||||
public fileName: string,
|
public fileName: string,
|
||||||
public author: string,
|
public author: string,
|
||||||
public date: Date,
|
public date: Date,
|
||||||
public message: string,
|
public message: string,
|
||||||
lines?: IGitCommitLine[],
|
lines?: IGitCommitLine[],
|
||||||
originalFileName?: string,
|
originalFileName?: string,
|
||||||
previousSha?: string,
|
previousSha?: string,
|
||||||
previousFileName?: string
|
previousFileName?: string
|
||||||
) {
|
) {
|
||||||
this.fileName = this.fileName.replace(/, ?$/, '');
|
this.fileName = this.fileName && this.fileName.replace(/, ?$/, '');
|
||||||
|
|
||||||
this.lines = lines || [];
|
this.lines = lines || [];
|
||||||
this.originalFileName = originalFileName;
|
this.originalFileName = originalFileName;
|
||||||
this.previousSha = previousSha;
|
this.previousSha = previousSha;
|
||||||
this.previousFileName = previousFileName;
|
this.previousFileName = previousFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
get shortSha() {
|
get shortSha() {
|
||||||
return this.sha.substring(0, 8);
|
return this.sha.substring(0, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
get isUncommitted(): boolean {
|
get isUncommitted(): boolean {
|
||||||
if (this._isUncommitted === undefined) {
|
if (this._isUncommitted === undefined) {
|
||||||
this._isUncommitted = Git.isUncommitted(this.sha);
|
this._isUncommitted = Git.isUncommitted(this.sha);
|
||||||
}
|
}
|
||||||
return this._isUncommitted;
|
return this._isUncommitted;
|
||||||
}
|
}
|
||||||
|
|
||||||
get previousShortSha() {
|
get previousShortSha() {
|
||||||
return this.previousSha && this.previousSha.substring(0, 8);
|
return this.previousSha && this.previousSha.substring(0, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
get previousUri(): Uri {
|
get previousUri(): Uri {
|
||||||
return this.previousFileName ? Uri.file(path.resolve(this.repoPath, this.previousFileName)) : this.uri;
|
return this.previousFileName ? Uri.file(path.resolve(this.repoPath, this.previousFileName)) : this.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
get uri(): Uri {
|
get uri(): Uri {
|
||||||
return Uri.file(path.resolve(this.repoPath, this.originalFileName || this.fileName));
|
return Uri.file(path.resolve(this.repoPath, this.originalFileName || this.fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormattedPath(separator: string = ' \u00a0\u2022\u00a0 '): string {
|
getFormattedPath(separator: string = ' \u00a0\u2022\u00a0 '): string {
|
||||||
const directory = Git.normalizePath(path.dirname(this.fileName));
|
const directory = Git.normalizePath(path.dirname(this.fileName));
|
||||||
return (!directory || directory === '.')
|
return (!directory || directory === '.')
|
||||||
? path.basename(this.fileName)
|
? path.basename(this.fileName)
|
||||||
: `${path.basename(this.fileName)}${separator}${directory}`;
|
: `${path.basename(this.fileName)}${separator}${directory}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user