提交 a19e1a49 编写于 作者: J Joao Moreno

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

......@@ -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) {
......@@ -1113,13 +1114,16 @@ export class UndoLastCommitAction extends GitAction {
static ID = 'workbench.action.git.undoLastCommit';
static LABEL = nls.localize('undoLastCommit', "Undo Last Commit");
private storageService: IStorageService;
constructor(
id = UndoLastCommitAction.ID,
label = UndoLastCommitAction.LABEL,
@IGitService gitService: IGitService
@IGitService gitService: IGitService,
@IStorageService storageService: IStorageService
) {
super(UndoLastCommitAction.ID, UndoLastCommitAction.LABEL, 'git-action undo-last-commit', gitService);
this.storageService = storageService;
}
public run():Promise {
......
......@@ -691,6 +691,10 @@ export class GitService extends ee.EventEmitter
return this.run(git.ServiceOperations.COMMIT, () => this.raw.commit(message, amend, stage));
}
public getCommitTemplate(): winjs.Promise {
return this.raw.getCommitTemplate();
}
public detectMimetypes(path: string, treeish: string = '~'): winjs.Promise {
return this.raw.detectMimetypes(path, treeish);
}
......
......@@ -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();
......@@ -236,14 +238,24 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV
if (visible) {
this.tree.onVisible();
return this.onEditorsChanged(this.editorService.getActiveEditorInput());
return this.onCommitInputShown().then((_) =>
this.onEditorsChanged(this.editorService.getActiveEditorInput()));
} else {
this.tree.onHidden();
return WinJS.TPromise.as(null);
}
}
public onCommitInputShown(): WinJS.TPromise<void> {
if (!this.commitInputBox.value) {
return this.gitService.getCommitTemplate().then((template) => {
if (template) { this.commitInputBox.value = template; }
});
} else {
return WinJS.TPromise.as(null);
}
}
public getControl(): Tree.ITree {
return this.tree;
}
......@@ -395,12 +407,13 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV
}
private onGitOperationEnd(e: { operation: git.IGitOperation; error: any; }): void {
if (e.operation.id === git.ServiceOperations.COMMIT) {
if (e.operation.id === git.ServiceOperations.COMMIT || e.operation.id === git.ServiceOperations.RESET) {
if (this.commitInputBox) {
this.commitInputBox.enable();
if (!e.error) {
this.commitInputBox.value = '';
this.onCommitInputShown();
}
}
}
......
......@@ -222,7 +222,7 @@ export var ServiceOperations = {
BACKGROUND_FETCH: 'backgroundfetch',
PULL: 'pull',
PUSH: 'push',
SYNC: 'sync'
SYNC: 'sync',
};
// Service config
......@@ -264,6 +264,23 @@ export interface IPushOptions {
setUpstream?: boolean;
}
/**
* These are `git log` options.
* The use case driving this is getting the previous commit message, message only.
* @example prevCount: 1, format: '%B' executes `git log -1 --format=%B`
* */
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 get the message only
*/
format?: string;
}
export interface IRawGitService {
onOutput: Event<string>;
getVersion(): TPromise<string>;
......@@ -286,6 +303,7 @@ export interface IRawGitService {
commit(message:string, amend?: boolean, stage?: boolean): TPromise<IRawStatus>;
detectMimetypes(path: string, treeish?: string): TPromise<string[]>;
show(path: string, treeish?: string): TPromise<string>;
getCommitTemplate(): TPromise<string>;
}
export var GIT_SERVICE_ID = 'gitService';
......@@ -322,6 +340,7 @@ export interface IGitService extends IEventEmitter {
isIdle(): boolean;
getRunningOperations(): IGitOperation[];
getAutoFetcher(): IAutoFetcher;
getCommitTemplate(): TPromise<string>;
}
export interface IAskpassService {
......
......@@ -87,6 +87,7 @@ export interface IGitChannel extends IChannel {
call(command: 'detectMimetypes', args: [string, string]): TPromise<string[]>;
call(command: 'show', args: [string, string]): TPromise<string>;
call(command: 'onOutput'): TPromise<void>;
call(command: 'getCommitTemplate'): TPromise<string>;
call(command: string, args: any): TPromise<any>;
}
......@@ -117,6 +118,7 @@ export class GitChannel implements IGitChannel {
case 'detectMimetypes': return this.service.then(s => s.detectMimetypes(args[0], args[1]));
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());
}
}
}
......@@ -217,6 +219,10 @@ export class GitChannelClient implements IRawGitService {
show(path: string, treeish?: string): TPromise<string> {
return this.channel.call('show', [path, treeish]);
}
getCommitTemplate(): TPromise<string> {
return this.channel.call('getCommitTemplate');
}
}
export interface IAskpassChannel extends IChannel {
......
......@@ -101,4 +101,12 @@ export class NoOpGitService implements IRawGitService {
show(path: string, treeish?: string): TPromise<string> {
return TPromise.as(null);
}
getLog(): TPromise<string> {
return TPromise.as(null);
}
getCommitTemplate(): TPromise<string> {
return TPromise.as(null);
}
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ import { assign } from 'vs/base/common/objects';
import { v4 as UUIDv4 } from 'vs/base/common/uuid';
import { localize } from 'vs/nls';
import { uniqueFilter } from 'vs/base/common/arrays';
import { IRawFileStatus, RefType, IRef, IBranch, IRemote, GitErrorCodes, IPushOptions } from 'vs/workbench/parts/git/common/git';
import { IRawFileStatus, RefType, IRef, IBranch, IRemote, GitErrorCodes, IPushOptions, ILogOptions } from 'vs/workbench/parts/git/common/git';
import { detectMimesFromStream } from 'vs/base/node/mime';
import { IFileOperationResult, FileOperationResult } from 'vs/platform/files/common/files';
import { spawn, ChildProcess } from 'child_process';
......@@ -557,6 +557,18 @@ export class Repository {
return this.run(['rev-parse', '--show-toplevel'], { log: false }).then(result => result.stdout.trim());
}
/** Only 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 => result.stdout.trim());
}
getStatus(): TPromise<IRawFileStatus[]> {
return this.run(['status', '-z', '-u'], { log: false }).then((executionResult) => {
const status = executionResult.stdout;
......
......@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as fs from 'fs';
import { join } from 'path';
import { TPromise, Promise } from 'vs/base/common/winjs.base';
import { detectMimesFromFile, detectMimesFromStream } from 'vs/base/node/mime';
......@@ -195,6 +196,49 @@ export class RawGitService implements IRawGitService {
return TPromise.wrapError<string>(e);
});
}
/**
* Reads the commit.template git config setting. If exists, then tries to load the contents of the file specified by that setting and returns these contents.
*/
getCommitTemplate(): TPromise<string> {
return this.repo.run(['config', '--get', 'commit.template']).then(execResult => execResult, err => '').then(execResult => {
return execResult ? this.readCommitTemplateFile(execResult.stdout.trim()) : '';
});
}
/**
* Reads the given file, if exists and is valid.
* @returns commit template file contents if exists and valid, else ""
*/
private readCommitTemplateFile(file: string): string {
try {
// // This is resolving to [repo]\.build\electron\~\.gitmessage
// let fullPath = resolve(file)
// console.log(`file: ${file}, fullPath: ${fullPath}`)
// return fs.existsSync(fullPath) ? fs.readFileSync(file, 'utf8') : '';
// Check the file itself
if (fs.existsSync(file)) {
return fs.readFileSync(file, 'utf8');
} else {
// File doesn't exist. Try converting ~/path to absolute path
// Try checking in local repo git folder (This is wrong interpretation oy)
let repo_file = file.replace('~', `${this.repo.path}\\.git`).replace('/', '\\');
if (fs.existsSync(repo_file)) {
return fs.readFileSync(repo_file, 'utf8');
} else {
// Check global (e.g. Windows user folder, Linux: home git config)
// not implemented
console.warn(`file doesnt exist in repo local git config. global git config template not implemented. (commit template file: ${file})`);
return '';
}
}
} catch (error) {
console.error(`Error reading file. file: ${file}, error: ${error.message})`);
return '';
}
}
}
export class DelayedRawGitService implements IRawGitService {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册