提交 7a298ad0 编写于 作者: W William Raiford

Changed `getCommitInfo` to `getCommitTemplate`

* Removed all previous commit message code.
* Changed `getCommitInfo` call to return a string that is the template contents.
  * Removed from `IModel`, `IRawStatus`
* Still has issue of locating `~/some/path/with/tilde` in it.
  * path.resolve resolves to the repo's `.build` path and not the user folder.
  * I'm testing this on Windows, and I don't know the behavior on Linux.
上级 cc3d257d
......@@ -1190,11 +1190,7 @@ export class UndoLastCommitAction extends GitAction {
}
public run():Promise {
// Need to get the previous commit msg **before** executing the reset.
return this.gitService.getCommitInfo().then(model => {
this.storageService.store('prevCommitMsg', model.getCommitInfo().prevCommitMsg);
return this.gitService.reset('HEAD~');
});
return this.gitService.reset('HEAD~');
}
}
......
......@@ -663,8 +663,8 @@ export class GitService extends ee.EventEmitter
return this.run(git.ServiceOperations.COMMIT, () => this.raw.commit(message, amend, stage));
}
public getCommitInfo(): winjs.Promise {
return this.run(git.ServiceOperations.GET_COMMIT_INFO, () => this.raw.getCommitInfo());
public getCommitTemplate(): winjs.Promise {
return this.raw.getCommitTemplate();
}
public detectMimetypes(path: string, treeish: string = '~'): winjs.Promise {
......
......@@ -240,8 +240,6 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV
this.tree.onVisible();
return this.onCommitInputShown().then((_) =>
this.onEditorsChanged(this.editorService.getActiveEditorInput()));
// return this.onEditorsChanged(this.editorService.getActiveEditorInput());
} else {
this.tree.onHidden();
return WinJS.TPromise.as(null);
......@@ -249,17 +247,9 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV
}
public onCommitInputShown(): WinJS.TPromise<void> {
if (this.storageService.get('prevCommitMsg')) {
this.commitInputBox.value = this.storageService.get('prevCommitMsg');
this.storageService.remove('prevCommitMsg');
} else if (!this.commitInputBox.value) {
return this.gitService.getCommitInfo().then((model) => {
if (!model || !model.getCommitInfo()) {
this.messageService.show(Severity.Warning, 'status contains no commit info');
} else {
let { template } = model.getCommitInfo();
this.commitInputBox.value = template ? template : "";
}
if (!this.commitInputBox.value) {
return this.gitService.getCommitTemplate().then((template) => {
if (template) { this.commitInputBox.value = template; }
});
} else {
return WinJS.TPromise.as(null);
......
......@@ -52,12 +52,6 @@ export interface IRawStatus {
HEAD: IBranch;
refs: IRef[];
remotes: IRemote[];
commitInfo?: ICommitInfo
}
export interface ICommitInfo {
template?: string;
prevCommitMsg?: string;
}
// Model enums
......@@ -144,7 +138,6 @@ export interface IModel extends IEventEmitter {
getRemotes(): IRemote[];
update(status: IRawStatus): void;
getPS1(): string;
getCommitInfo(): ICommitInfo;
}
// Service operations
......@@ -230,7 +223,6 @@ export var ServiceOperations = {
PULL: 'pull',
PUSH: 'push',
SYNC: 'sync',
GET_COMMIT_INFO: 'getCommitInfo'
};
// Service config
......@@ -309,7 +301,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>;
getCommitInfo(): TPromise<IRawStatus>;
getCommitTemplate(): TPromise<string>;
}
export var GIT_SERVICE_ID = 'gitService';
......@@ -346,7 +338,7 @@ export interface IGitService extends IEventEmitter {
isIdle(): boolean;
getRunningOperations(): IGitOperation[];
getAutoFetcher(): IAutoFetcher;
getCommitInfo(): TPromise<IModel>;
getCommitTemplate(): TPromise<string>;
}
export interface IAskpassService {
......
......@@ -9,7 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
import Event from 'vs/base/common/event';
import { IRawGitService, RawServiceState, IRawStatus, IPushOptions, IAskpassService, ICredentials,
ServiceState, IRawFileStatus, IBranch, RefType, IRef, IRemote, ICommitInfo } from './git';
ServiceState, IRawFileStatus, IBranch, RefType, IRef, IRemote } from './git';
type ISerializer<A,B> = { to(a: A): B; from(b: B): A; };
......@@ -87,7 +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: 'getCommitInfo'): TPromise<ICommitInfo>;
call(command: 'getCommitTemplate'): TPromise<string>;
call(command: string, args: any): TPromise<any>;
}
......@@ -118,7 +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 'getCommitInfo': return this.service.then(s => s.getCommitInfo());
case 'getCommitTemplate': return this.service.then(s => s.getCommitTemplate());
}
}
}
......@@ -220,8 +220,8 @@ export class GitChannelClient implements IRawGitService {
return this.channel.call('show', [path, treeish]);
}
getCommitInfo(): TPromise<ICommitInfo> {
return this.channel.call('getCommitInfo');
getCommitTemplate(): TPromise<string> {
return this.channel.call('getCommitTemplate');
}
}
......
......@@ -9,7 +9,7 @@ import { format } from 'vs/base/common/strings';
import { EventEmitter } from 'vs/base/common/eventEmitter';
import { IStatusModel, IStatusSummary, IRawFileStatus, ModelEvents,
IFileStatus, IStatusGroup, Status, StatusType,
IBranch, IRef, IRemote, IModel, IRawStatus, ICommitInfo
IBranch, IRef, IRemote, IModel, IRawStatus
} from 'vs/workbench/parts/git/common/git';
export class FileStatus implements IFileStatus {
......@@ -316,7 +316,6 @@ export class Model extends EventEmitter implements IModel {
private refs: IRef[];
private remotes: IRemote[];
private toDispose: IDisposable[];
private commitInfo: ICommitInfo;
constructor() {
super();
......@@ -330,7 +329,6 @@ export class Model extends EventEmitter implements IModel {
this.HEAD = null;
this.refs = [];
this.remotes = [];
this.commitInfo = null
}
getRepositoryRoot(): string {
......@@ -367,8 +365,6 @@ export class Model extends EventEmitter implements IModel {
this.repositoryRoot = status.repositoryRoot;
this.status.update(status.status);
this.commitInfo = status.commitInfo;
this.HEAD = status.HEAD;
this.emit(ModelEvents.HEAD_UPDATED);
......@@ -407,10 +403,6 @@ export class Model extends EventEmitter implements IModel {
);
}
getCommitInfo(): ICommitInfo {
return this.commitInfo;
}
dispose(): void {
this.toDispose = dispose(this.toDispose);
super.dispose();
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IRawGitService, IRawStatus, ServiceState, RawServiceState, ICommitInfo } from 'vs/workbench/parts/git/common/git';
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';
......@@ -106,7 +106,7 @@ export class NoOpGitService implements IRawGitService {
return TPromise.as(null);
}
getCommitInfo(): TPromise<ICommitInfo> {
getCommitTemplate(): TPromise<string> {
return TPromise.as(null);
}
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ 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 { IRawGitService, RawServiceState, IRawStatus, IRef, GitErrorCodes, IPushOptions, ICommitInfo } from 'vs/workbench/parts/git/common/git';
import { IRawGitService, RawServiceState, IRawStatus, IRef, GitErrorCodes, IPushOptions } from 'vs/workbench/parts/git/common/git';
import Event, { Emitter } from 'vs/base/common/event';
export class RawGitService implements IRawGitService {
......@@ -194,23 +194,12 @@ export class RawGitService implements IRawGitService {
}
/**
* Gets `ICommitInfo`, including the template and previous commit message.
* @returns `IRawStatus` with `commitInfo` set.
* 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.
*/
getCommitInfo(): TPromise<IRawStatus> {
return Promise.join([
// if either of these do not exist or throw an error, then we return ""
this.repo.run(['config', '--get', 'commit.template']).then(filename => filename, err => ""),
this.repo.getLog({ prevCount: 1, format: '%B' }).then(log => log, err => ""),
this.status()
]).then(r => {
let status = <IRawStatus>r[2];
status.commitInfo = {
template: r[0] ? this.readCommitTemplateFile(r[0].stdout.trim()) : "",
prevCommitMsg: r[1]
};
return status;
});;
getCommitTemplate(): TPromise<string> {
return this.repo.run(['config', '--get', 'commit.template']).then(execResult => execResult, err => '').then(execResult => {
return execResult ? this.readCommitTemplateFile(execResult.stdout.trim()) : '';
});
}
/**
......@@ -219,26 +208,31 @@ export class RawGitService implements IRawGitService {
*/
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
// 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 "";
return '';
}
}
} catch (error) {
console.error(`Error reading file. file: ${file}, error: ${error.message})`);
return "";
return '';
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册