mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-18 01:35:36 -05:00
Adds new show repository status command
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user