Restore prev commit msg using IStorageService
* Added line in `UndoLastCommitAction` to get the previous commit msg and store in `IStorageService`. * Added `UpdateCommitInputPrevCommitMsg` that checks for that key in storage, and use it then remove it if it exists. * This does not suffer from the previous bug that blanked out the commit msg if you unstage a file. * Added a clause if the undo last commit fails to remove the key from storage. This way, it doesn't stay in there and get used later (I was scratching my head when it showed up later).
This commit is contained in:
parent
8a92ee5aa3
commit
4753a000ae
2 changed files with 21 additions and 3 deletions
|
@ -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~'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue