mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
git: commit
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
import { Uri, commands, scm, Disposable, SCMResourceGroup, SCMResource, window, workspace, QuickPickItem, OutputChannel } from 'vscode';
|
||||
import { IRef, RefType } from './git';
|
||||
import { Model, Resource, Status } from './model';
|
||||
import { CommitController } from './commit';
|
||||
import * as path from 'path';
|
||||
import * as nls from 'vscode-nls';
|
||||
|
||||
@@ -125,7 +126,11 @@ export class CommandCenter {
|
||||
|
||||
private disposables: Disposable[];
|
||||
|
||||
constructor(private model: Model, private outputChannel: OutputChannel) {
|
||||
constructor(
|
||||
private model: Model,
|
||||
private commitController: CommitController,
|
||||
private outputChannel: OutputChannel
|
||||
) {
|
||||
this.disposables = CommandCenter.Commands
|
||||
.map(({ commandId, method }) => commands.registerCommand(commandId, method, this));
|
||||
}
|
||||
@@ -286,7 +291,7 @@ export class CommandCenter {
|
||||
return;
|
||||
}
|
||||
|
||||
return await this.model.clean(resource);
|
||||
await this.model.clean(resource);
|
||||
}
|
||||
|
||||
@CommandCenter.Command('git.cleanAll')
|
||||
@@ -301,13 +306,45 @@ export class CommandCenter {
|
||||
return;
|
||||
}
|
||||
|
||||
return await this.model.clean(...this.model.workingTreeGroup.resources);
|
||||
await this.model.clean(...this.model.workingTreeGroup.resources);
|
||||
}
|
||||
|
||||
@CommandCenter.CatchErrors
|
||||
async commit(message: string): Promise<void> {
|
||||
private async _commit(fn: () => Promise<string>): Promise<boolean> {
|
||||
if (this.model.indexGroup.resources.length === 0 && this.model.workingTreeGroup.resources.length === 0) {
|
||||
window.showInformationMessage(localize('no changes', "There are no changes to commit."));
|
||||
return false;
|
||||
}
|
||||
|
||||
const message = await fn();
|
||||
|
||||
if (!message) {
|
||||
// TODO@joao: show modal dialog to confirm empty message commit
|
||||
return false;
|
||||
}
|
||||
|
||||
const all = this.model.indexGroup.resources.length === 0;
|
||||
return this.model.commit(message, { all });
|
||||
await this.model.commit(message, { all });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@CommandCenter.Command('git.commit')
|
||||
@CommandCenter.CatchErrors
|
||||
async commit(): Promise<void> {
|
||||
await this._commit(async () => await window.showInputBox({
|
||||
placeHolder: localize('commit message', "Commit message"),
|
||||
prompt: localize('provide commit message', "Please provide a commit message")
|
||||
}));
|
||||
}
|
||||
|
||||
@CommandCenter.Command('git.commitWithInput')
|
||||
@CommandCenter.CatchErrors
|
||||
async commitWithInput(): Promise<void> {
|
||||
const didCommit = await this._commit(async () => this.commitController.message);
|
||||
|
||||
if (didCommit) {
|
||||
this.commitController.message = '';
|
||||
}
|
||||
}
|
||||
|
||||
@CommandCenter.Command('git.commitStaged')
|
||||
|
||||
@@ -5,15 +5,16 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { workspace, window, languages, Disposable, Uri, TextDocumentChangeEvent, HoverProvider, Hover, TextEditor, Position, TextDocument, Range, TextEditorDecorationType } from 'vscode';
|
||||
import { workspace, window, languages, Disposable, Uri, TextDocumentChangeEvent, HoverProvider, Hover, TextEditor, Position, TextDocument, Range, TextEditorDecorationType, WorkspaceEdit } from 'vscode';
|
||||
import { Model } from './model';
|
||||
import { filterEvent } from './util';
|
||||
import * as nls from 'vscode-nls';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
const scmInputUri = Uri.parse('scm:input');
|
||||
|
||||
function isSCMInput(uri: Uri) {
|
||||
return uri.toString() === 'scm:input';
|
||||
return uri.toString() === scmInputUri.toString();
|
||||
}
|
||||
|
||||
interface Diagnostic {
|
||||
@@ -22,7 +23,7 @@ interface Diagnostic {
|
||||
}
|
||||
|
||||
// TODO@Joao: hover dissapears if editor is scrolled
|
||||
export class CommitHandler implements HoverProvider {
|
||||
export class CommitController implements HoverProvider {
|
||||
|
||||
private visibleTextEditorsDisposable: Disposable;
|
||||
private editor: TextEditor;
|
||||
@@ -30,6 +31,28 @@ export class CommitHandler implements HoverProvider {
|
||||
private decorationType: TextEditorDecorationType;
|
||||
private disposables: Disposable[] = [];
|
||||
|
||||
get message(): string | undefined {
|
||||
if (!this.editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.editor.document.getText();
|
||||
}
|
||||
|
||||
set message(message: string | undefined) {
|
||||
if (!this.editor || message === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const document = this.editor.document;
|
||||
const start = document.lineAt(0).range.start;
|
||||
const end = document.lineAt(document.lineCount - 1).range.end;
|
||||
const range = new Range(start, end);
|
||||
const edit = new WorkspaceEdit();
|
||||
edit.replace(scmInputUri, range, message);
|
||||
workspace.applyEdit(edit);
|
||||
}
|
||||
|
||||
constructor(private model: Model) {
|
||||
this.visibleTextEditorsDisposable = window.onDidChangeVisibleTextEditors(this.onVisibleTextEditors, this);
|
||||
this.onVisibleTextEditors(window.visibleTextEditors);
|
||||
|
||||
@@ -15,7 +15,7 @@ import { filterEvent, anyEvent } from './util';
|
||||
import { GitContentProvider } from './contentProvider';
|
||||
import { AutoFetcher } from './autofetch';
|
||||
import { MergeDecorator } from './merge';
|
||||
import { CommitHandler } from './commit';
|
||||
import { CommitController } from './commit';
|
||||
import * as nls from 'vscode-nls';
|
||||
|
||||
const localize = nls.config()();
|
||||
@@ -42,16 +42,17 @@ async function init(disposables: Disposable[]): Promise<void> {
|
||||
outputChannel.appendLine(localize('using git', "Using git {0} from {1}", info.version, info.path));
|
||||
git.onOutput(str => outputChannel.append(str), null, disposables);
|
||||
|
||||
const commandCenter = new CommandCenter(model, outputChannel);
|
||||
const commitHandler = new CommitController(model);
|
||||
const commandCenter = new CommandCenter(model, commitHandler, outputChannel);
|
||||
const provider = new GitSCMProvider(model, commandCenter);
|
||||
const contentProvider = new GitContentProvider(git, rootPath, onGitChange);
|
||||
const checkoutStatusBar = new CheckoutStatusBar(model);
|
||||
const syncStatusBar = new SyncStatusBar(model);
|
||||
const autoFetcher = new AutoFetcher(model);
|
||||
const mergeDecorator = new MergeDecorator(model);
|
||||
const commitHandler = new CommitHandler(model);
|
||||
|
||||
disposables.push(
|
||||
commitHandler,
|
||||
commandCenter,
|
||||
provider,
|
||||
contentProvider,
|
||||
@@ -60,8 +61,7 @@ async function init(disposables: Disposable[]): Promise<void> {
|
||||
checkoutStatusBar,
|
||||
syncStatusBar,
|
||||
autoFetcher,
|
||||
mergeDecorator,
|
||||
commitHandler
|
||||
mergeDecorator
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,6 @@ export class GitSCMProvider implements SCMProvider {
|
||||
scm.registerSCMProvider('git', this);
|
||||
}
|
||||
|
||||
commit(message: string): Thenable<void> {
|
||||
return this.commandCenter.commit(message);
|
||||
}
|
||||
|
||||
open(resource: Resource): ProviderResult<void> {
|
||||
return this.commandCenter.open(resource);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user