Adds more protection for uncommitted lines

Adds better uncommitted hover message in blame annotations
This commit is contained in:
Eric Amodio
2016-09-21 10:54:45 -04:00
parent b047fbc394
commit 157928311e
9 changed files with 67 additions and 33 deletions

View File

@@ -7,7 +7,7 @@ import {spawnPromise} from 'spawn-rx';
export * from './gitEnrichment';
export * from './enrichers/blameParserEnricher';
const UncommitedRegex = /^[0]+$/;
const UncommittedRegex = /^[0]+$/;
function gitCommand(cwd: string, ...args) {
return spawnPromise('git', args, { cwd: cwd })
@@ -99,10 +99,11 @@ export default class Git {
const [file, root] = Git.splitPath(Git.normalizePath(fileName), repoPath);
sha = sha.replace('^', '');
if (Git.isUncommitted(sha)) return new Promise<string>((resolve, reject) => reject(new Error(`sha=${sha} is uncommitted`)));
return gitCommand(root, 'show', `${sha}:./${file}`);
}
static isUncommitted(sha: string) {
return UncommitedRegex.test(sha);
return UncommittedRegex.test(sha);
}
}

View File

@@ -1,5 +1,6 @@
'use strict'
import {Uri} from 'vscode';
import Git from './git';
import * as path from 'path';
export interface IGitEnricher<T> {
@@ -46,6 +47,7 @@ export interface IGitCommit {
previousSha?: string;
previousFileName?: string;
readonly isUncommitted: boolean;
previousUri: Uri;
uri: Uri;
}
@@ -55,6 +57,7 @@ export class GitCommit implements IGitCommit {
originalFileName?: string;
previousSha?: string;
previousFileName?: 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) {
@@ -64,6 +67,13 @@ export class GitCommit implements IGitCommit {
this.previousFileName = previousFileName;
}
get isUncommitted(): boolean {
if (this._isUncommitted === undefined) {
this._isUncommitted = Git.isUncommitted(this.sha);
}
return this._isUncommitted;
}
get previousUri(): Uri {
return this.previousFileName ? Uri.file(path.join(this.repoPath, this.previousFileName)) : this.uri;
}