Merge branch 'bill_prev_comm_msg' of https://github.com/bill-mybiz/vscode into bill-mybiz-bill_prev_comm_msg

This commit is contained in:
Joao Moreno 2016-08-12 12:16:23 +02:00
commit 7ddbab5494
8 changed files with 73 additions and 4 deletions

View file

@ -29,6 +29,7 @@ import { IGitService, IFileStatus, Status, StatusType, ServiceState, IModel, IBr
import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickOpenService';
import paths = require('vs/base/common/paths');
import URI from 'vs/base/common/uri';
import { IStorageService } from 'vs/platform/storage/common/storage';
function flatten(context?: any, preferFocus = false): IFileStatus[] {
if (!context) {
@ -1117,13 +1118,14 @@ export class UndoLastCommitAction extends GitAction {
constructor(
id = UndoLastCommitAction.ID,
label = UndoLastCommitAction.LABEL,
@IGitService gitService: IGitService
@IGitService gitService: IGitService,
@IStorageService private storageService: IStorageService
) {
super(UndoLastCommitAction.ID, UndoLastCommitAction.LABEL, 'git-action undo-last-commit', gitService);
}
public run():Promise {
return this.gitService.reset('HEAD~');
return this.gitService.getLog({ prevCount: 1, format: '%B' }).then(prevCommitMsg => this.storageService.store('prevCommitMsg', prevCommitMsg)).then(_ => this.gitService.reset('HEAD~'));
}
}

View file

@ -38,6 +38,7 @@ import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage'
import Event from 'vs/base/common/event';
import { domEvent } from 'vs/base/browser/event';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import { ILogOptions } from 'vs/workbench/parts/git/node/git.lib';
function toReadablePath(path: string): string {
if (!platform.isWindows) {
@ -695,6 +696,10 @@ export class GitService extends ee.EventEmitter
return this.raw.getCommitTemplate();
}
public getLog(options?: ILogOptions): winjs.Promise {
return this.raw.getLog(options);
}
public detectMimetypes(path: string, treeish: string = '~'): winjs.Promise {
return this.raw.detectMimetypes(path, treeish);
}

View file

@ -41,6 +41,7 @@ import {IEventService} from 'vs/platform/event/common/event';
import {CommonKeybindings} from 'vs/base/common/keyCodes';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IStorageService} from 'vs/platform/storage/common/storage';
import IGitService = git.IGitService;
@ -89,7 +90,8 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV
@IGitService gitService: IGitService,
@IOutputService outputService: IOutputService,
@IEventService eventService: IEventService,
@IConfigurationService private configurationService: IConfigurationService
@IConfigurationService private configurationService: IConfigurationService,
@IStorageService private storageService: IStorageService
) {
super();
@ -244,6 +246,14 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV
}
}
private updateCommitInputPrevCommitMsg(): void {
let prevCommitMsg = this.storageService.get('prevCommitMsg');
if (prevCommitMsg) {
this.commitInputBox.value = prevCommitMsg;
this.storageService.remove('prevCommitMsg');
}
}
private updateCommitInputTemplate(): void {
if (this.commitInputBox.value) {
return;
@ -414,6 +424,12 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV
this.updateCommitInputTemplate();
}
}
} else if (e.operation.id === git.ServiceOperations.RESET) {
if (!e.error) {
this.updateCommitInputPrevCommitMsg();
} else {
this.storageService.remove('prevCommitMsg');
}
}
}

View file

@ -10,6 +10,7 @@ import { IEventEmitter } from 'vs/base/common/eventEmitter';
import { IDisposable } from 'vs/base/common/lifecycle';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import Event from 'vs/base/common/event';
import { ILogOptions } from 'vs/workbench/parts/git/node/git.lib';
// Model raw interfaces
@ -287,6 +288,7 @@ export interface IRawGitService {
detectMimetypes(path: string, treeish?: string): TPromise<string[]>;
show(path: string, treeish?: string): TPromise<string>;
getCommitTemplate(): TPromise<string>;
getLog(options?: ILogOptions): TPromise<string>;
}
export const GIT_SERVICE_ID = 'gitService';
@ -324,6 +326,7 @@ export interface IGitService extends IEventEmitter {
getRunningOperations(): IGitOperation[];
getAutoFetcher(): IAutoFetcher;
getCommitTemplate(): TPromise<string>;
getLog(options?: ILogOptions): TPromise<string>;
}
export interface IAskpassService {

View file

@ -10,6 +10,7 @@ import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/i
import Event from 'vs/base/common/event';
import { IRawGitService, RawServiceState, IRawStatus, IPushOptions, IAskpassService, ICredentials,
ServiceState, IRawFileStatus, IBranch, RefType, IRef, IRemote } from './git';
import { ILogOptions } from 'vs/workbench/parts/git/node/git.lib';
type ISerializer<A,B> = { to(a: A): B; from(b: B): A; };
@ -88,6 +89,7 @@ export interface IGitChannel extends IChannel {
call(command: 'show', args: [string, string]): TPromise<string>;
call(command: 'onOutput'): TPromise<void>;
call(command: 'getCommitTemplate'): TPromise<string>;
call(command: 'getLog', options?: ILogOptions): TPromise<string>;
call(command: string, args: any): TPromise<any>;
}
@ -119,6 +121,7 @@ export class GitChannel implements IGitChannel {
case 'show': return this.service.then(s => s.show(args[0], args[1]));
case 'onOutput': return this.service.then(s => eventToCall(s.onOutput));
case 'getCommitTemplate': return this.service.then(s => s.getCommitTemplate());
case 'getLog': return this.service.then(s => s.getLog(args));
}
}
}
@ -223,6 +226,10 @@ export class GitChannelClient implements IRawGitService {
getCommitTemplate(): TPromise<string> {
return this.channel.call('getCommitTemplate');
}
getLog(options?: ILogOptions): TPromise<string> {
return this.channel.call('getLog', options);
}
}
export interface IAskpassChannel extends IChannel {

View file

@ -7,6 +7,7 @@
import { IRawGitService, IRawStatus, ServiceState, RawServiceState } from 'vs/workbench/parts/git/common/git';
import { TPromise } from 'vs/base/common/winjs.base';
import Event, { Emitter } from 'vs/base/common/event';
import { ILogOptions } from 'vs/workbench/parts/git/node/git.lib';
export class NoOpGitService implements IRawGitService {
@ -105,4 +106,8 @@ export class NoOpGitService implements IRawGitService {
getCommitTemplate(): TPromise<string> {
return TPromise.as(null);
}
getLog(options?: ILogOptions): TPromise<string> {
return TPromise.as(null);
}
}

View file

@ -119,6 +119,18 @@ export class GitError {
}
}
export interface ILogOptions {
/**
* @example `git log -1 --format=%B` to get the last commit log, message only
*/
prevCount?: number;
/**
* @example format: "%B" translates to `git log --format=%B` to extract only the message
*/
format?: string;
}
export interface IGitOptions {
gitPath:string;
version: string;
@ -723,6 +735,20 @@ export class Repository {
}, () => '');
}
/** Implemented for use case `git log` and `git log -N`. */
getLog(options?: ILogOptions): TPromise<string> {
const args = ['log'];
if (options) {
if (options.prevCount) { args.push(`-${options.prevCount}`); }
if (options.format) { args.push(`--format=${options.format}`); }
}
return this.run(args, { log: false }).then(result => {
return result.stdout.trim();
});
}
onOutput(listener: (output: string) => void): () => void {
return this.git.onOutput(listener);
}

View file

@ -8,7 +8,7 @@ import { join } from 'path';
import { TPromise, Promise } from 'vs/base/common/winjs.base';
import { detectMimesFromFile, detectMimesFromStream } from 'vs/base/node/mime';
import { realpath, exists} from 'vs/base/node/pfs';
import { Repository, GitError } from 'vs/workbench/parts/git/node/git.lib';
import { Repository, GitError, ILogOptions } from 'vs/workbench/parts/git/node/git.lib';
import { IRawGitService, RawServiceState, IRawStatus, IRef, GitErrorCodes, IPushOptions } from 'vs/workbench/parts/git/common/git';
import Event, { Emitter, fromPromise } from 'vs/base/common/event';
@ -199,6 +199,10 @@ export class RawGitService implements IRawGitService {
getCommitTemplate(): TPromise<string> {
return this.repo.getCommitTemplate();
}
getLog(options?: ILogOptions): TPromise<string> {
return this.repo.getLog(options);
}
}
export class DelayedRawGitService implements IRawGitService {
@ -225,4 +229,5 @@ export class DelayedRawGitService implements IRawGitService {
detectMimetypes(path: string, treeish?: string): TPromise<string[]> { return this.raw.then(r => r.detectMimetypes(path, treeish)); }
show(path: string, treeish?: string): TPromise<string> { return this.raw.then(r => r.show(path, treeish)); }
getCommitTemplate(): TPromise<string> { return this.raw.then(r => r.getCommitTemplate()); }
getLog(options?: ILogOptions): TPromise<string> { return this.raw.then(r => r.getLog(options)); }
}