Repository and Model changes

This commit is contained in:
Krzysztof Cieślak
2017-06-20 22:25:48 +02:00
parent 1531c8d2f4
commit 4cd45c49bd
2 changed files with 63 additions and 4 deletions

View File

@@ -33,6 +33,11 @@ export interface Remote {
url: string;
}
export interface Stash {
id : string;
description: string;
}
export enum RefType {
Head,
RemoteHead,
@@ -277,7 +282,10 @@ export const GitErrorCodes = {
RepositoryNotFound: 'RepositoryNotFound',
RepositoryIsLocked: 'RepositoryIsLocked',
BranchNotFullyMerged: 'BranchNotFullyMerged',
NoRemoteReference: 'NoRemoteReference'
NoRemoteReference: 'NoRemoteReference',
NoLocalChanges: 'NoLocalChanges',
NoStashFound: 'NoStashFound',
LocalChangesOverwritten: 'LocalChangesOverwritten'
};
function getGitErrorCode(stderr: string): string | undefined {
@@ -834,6 +842,32 @@ export class Repository {
}
}
async stash(pop: boolean = false, index?: string): Promise<void> {
try {
const args = ['stash'];
if (pop) {
args.push('pop');
if (index) {
args.push(`"stash{${index}}"`);
}
}
await this.run(args);
} catch (err) {
if (/No local changes to save/.test(err.stderr || '')) {
err.gitErrorCode = GitErrorCodes.NoLocalChanges;
}
else if (/No stash found/.test(err.stderr || '')) {
err.gitErrorCode = GitErrorCodes.NoStashFound;
}
else if (/error: Your local changes to the following files would be overwritten/.test(err.stderr || '')) {
err.gitErrorCode = GitErrorCodes.LocalChangesOverwritten;
}
throw err;
}
}
getStatus(limit = 5000): Promise<{ status: IFileStatus[]; didHitLimit: boolean; }> {
return new Promise<{ status: IFileStatus[]; didHitLimit: boolean; }>((c, e) => {
const parser = new GitStatusParser();
@@ -921,6 +955,18 @@ export class Repository {
.filter(ref => !!ref) as Ref[];
}
async getStashes(): Promise<Stash[]> {
const result = await this.run(['stash', 'list']);
const regex = /^stash@{(\d+)}:(.+)/;
const rawStashes = result.stdout.trim().split('\n')
.filter(b => !!b)
.map(line => regex.exec(line))
.filter(g => !!g)
.map((groups: RegExpExecArray) => ({ id: groups[1], description: groups[2] }));
return uniqBy(rawStashes, remote => remote.id);
}
async getRemotes(): Promise<Remote[]> {
const result = await this.run(['remote', '--verbose']);
const regex = /^([^\s]+)\s+([^\s]+)\s/;