提交 4cd45c49 编写于 作者: K Krzysztof Cieślak

Repository and Model changes

上级 1531c8d2
......@@ -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/;
......
......@@ -6,7 +6,7 @@
'use strict';
import { Uri, Command, EventEmitter, Event, SourceControlResourceState, SourceControlResourceDecorations, Disposable, ProgressLocation, window, workspace, WorkspaceEdit } from 'vscode';
import { Git, Repository, Ref, Branch, Remote, Commit, GitErrorCodes } from './git';
import { Git, Repository, Ref, Branch, Remote, Commit, GitErrorCodes, Stash } from './git';
import { anyEvent, eventToPromise, filterEvent, EmptyDisposable, combinedDisposable, dispose } from './util';
import { memoize, throttle, debounce } from './decorators';
import * as path from 'path';
......@@ -215,7 +215,8 @@ export enum Operation {
DeleteBranch = 1 << 16,
Merge = 1 << 17,
Ignore = 1 << 18,
Tag = 1 << 19
Tag = 1 << 19,
Stash = 1 << 20
}
// function getOperationName(operation: Operation): string {
......@@ -345,6 +346,11 @@ export class Model implements Disposable {
return this._remotes;
}
private _stashes: Stash[] = [];
get stashes(): Stash[] {
return this._stashes;
}
private _operations = new OperationsImpl();
get operations(): Operations { return this._operations; }
......@@ -359,6 +365,7 @@ export class Model implements Disposable {
this._HEAD = undefined;
this._refs = [];
this._remotes = [];
this._stashes = [];
this._mergeGroup = new MergeGroup();
this._indexGroup = new IndexGroup();
this._workingTreeGroup = new WorkingTreeGroup();
......@@ -542,6 +549,11 @@ export class Model implements Disposable {
});
}
@throttle
async stash(pop: boolean = false, index?: string): Promise<void> {
return await this.run(Operation.Stash, () => this.repository.stash(pop, index));
}
async getCommitTemplate(): Promise<string> {
return await this.run(Operation.GetCommitTemplate, async () => this.repository.getCommitTemplate());
}
......@@ -692,11 +704,12 @@ export class Model implements Disposable {
// noop
}
const [refs, remotes] = await Promise.all([this.repository.getRefs(), this.repository.getRemotes()]);
const [refs, remotes, stashes] = await Promise.all([this.repository.getRefs(), this.repository.getRemotes(), this.repository.getStashes()]);
this._HEAD = HEAD;
this._refs = refs;
this._remotes = remotes;
this._stashes = stashes;
const index: Resource[] = [];
const workingTree: Resource[] = [];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册