Adds new show repository status command

This commit is contained in:
Eric Amodio
2017-02-25 02:20:23 -05:00
parent bcfb0cd24d
commit 0a4cdd81eb
8 changed files with 336 additions and 78 deletions

View File

@@ -171,13 +171,18 @@ export default class Git {
return gitCommand(root, 'show', `${sha}:./${file}`);
}
static statusForFile(fileName: string, repoPath: string): Promise<string> {
static statusFile(fileName: string, repoPath: string): Promise<string> {
const [file, root]: [string, string] = Git.splitPath(Git.normalizePath(fileName), repoPath);
const params = ['status', file, '--short'];
return gitCommand(root, ...params);
}
static statusRepo(repoPath: string): Promise<string> {
const params = ['status', '--short'];
return gitCommand(repoPath, ...params);
}
static isUncommitted(sha: string) {
return UncommittedRegex.test(sha);
}

View File

@@ -106,4 +106,59 @@ export interface IGitLog {
repoPath: string;
authors: Map<string, IGitAuthor>;
commits: Map<string, GitCommit>;
}
export enum GitFileStatus {
Unknown,
Untracked,
Added,
Modified,
Deleted,
Renamed
}
export class GitFileStatusItem {
staged: boolean;
status: GitFileStatus;
fileName: string;
constructor(public repoPath: string, status: string) {
this.fileName = status.substring(3);
this.parseStatus(status);
}
private parseStatus(status: string) {
const indexStatus = status[0];
const workTreeStatus = status[1];
this.staged = workTreeStatus === ' ';
if (indexStatus === '?' && workTreeStatus === '?') {
this.status = GitFileStatus.Untracked;
return;
}
if (indexStatus === 'A') {
this.status = GitFileStatus.Added;
return;
}
if (indexStatus === 'M' || workTreeStatus === 'M') {
this.status = GitFileStatus.Modified;
return;
}
if (indexStatus === 'D' || workTreeStatus === 'D') {
this.status = GitFileStatus.Deleted;
return;
}
if (indexStatus === 'R') {
this.status = GitFileStatus.Renamed;
return;
}
this.status = GitFileStatus.Unknown;
}
}