Skip to content

Commit

Permalink
Revert "A full editor can be used as git commit message editor (#95266)"
Browse files Browse the repository at this point in the history
This reverts commit 97f8e66.
  • Loading branch information
lszomoru committed May 26, 2022
1 parent 33a8212 commit ca90050
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 235 deletions.
3 changes: 1 addition & 2 deletions extensions/git/extension.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = withDefaults({
context: __dirname,
entry: {
main: './src/main.ts',
['askpass-main']: './src/askpass-main.ts',
['git-editor-main']: './src/gitEditor/main.ts'
['askpass-main']: './src/askpass-main.ts'
}
});
62 changes: 16 additions & 46 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"diffCommand",
"contribMergeEditorToolbar",
"contribViewsWelcome",
"resolvers",
"scmActionButton",
"scmInput",
"scmSelectedProvider",
"scmValidation",
"timeline"
Expand Down Expand Up @@ -215,99 +213,83 @@
"command": "git.commit",
"title": "%command.commit%",
"category": "Git",
"icon": "$(check)",
"enablement": "!commitInProgress"
"icon": "$(check)"
},
{
"command": "git.commitStaged",
"title": "%command.commitStaged%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitEmpty",
"title": "%command.commitEmpty%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitStagedSigned",
"title": "%command.commitStagedSigned%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitStagedAmend",
"title": "%command.commitStagedAmend%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitAll",
"title": "%command.commitAll%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitAllSigned",
"title": "%command.commitAllSigned%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitAllAmend",
"title": "%command.commitAllAmend%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitNoVerify",
"title": "%command.commitNoVerify%",
"category": "Git",
"icon": "$(check)",
"enablement": "!commitInProgress"
"icon": "$(check)"
},
{
"command": "git.commitStagedNoVerify",
"title": "%command.commitStagedNoVerify%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitEmptyNoVerify",
"title": "%command.commitEmptyNoVerify%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitStagedSignedNoVerify",
"title": "%command.commitStagedSignedNoVerify%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitStagedAmendNoVerify",
"title": "%command.commitStagedAmendNoVerify%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitAllNoVerify",
"title": "%command.commitAllNoVerify%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitAllSignedNoVerify",
"title": "%command.commitAllSignedNoVerify%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.commitAllAmendNoVerify",
"title": "%command.commitAllAmendNoVerify%",
"category": "Git",
"enablement": "!commitInProgress"
"category": "Git"
},
{
"command": "git.restoreCommitTemplate",
Expand Down Expand Up @@ -2017,18 +1999,6 @@
"scope": "machine",
"description": "%config.defaultCloneDirectory%"
},
"git.useEditorAsCommitInput": {
"type": "boolean",
"scope": "resource",
"description": "%config.useEditorAsCommitInput%",
"default": false
},
"git.verboseCommit": {
"type": "boolean",
"scope": "resource",
"markdownDescription": "%config.verboseCommit%",
"default": false
},
"git.enableSmartCommit": {
"type": "boolean",
"scope": "resource",
Expand Down
2 changes: 0 additions & 2 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@
"config.ignoreLimitWarning": "Ignores the warning when there are too many changes in a repository.",
"config.ignoreRebaseWarning": "Ignores the warning when it looks like the branch might have been rebased when pulling.",
"config.defaultCloneDirectory": "The default location to clone a git repository.",
"config.useEditorAsCommitInput": "Use an editor to author the commit message.",
"config.verboseCommit": "Enable verbose output when `#git.useEditorAsCommitInput#` is enabled.",
"config.enableSmartCommit": "Commit all changes when there are no staged changes.",
"config.smartCommitChanges": "Control which changes are automatically staged by Smart Commit.",
"config.smartCommitChanges.all": "Automatically stage all changes.",
Expand Down
3 changes: 0 additions & 3 deletions extensions/git/src/api/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ export interface CommitOptions {
empty?: boolean;
noVerify?: boolean;
requireUserConfig?: boolean;
useEditor?: boolean;
verbose?: boolean;
}

export interface FetchOptions {
Expand Down Expand Up @@ -338,5 +336,4 @@ export const enum GitErrorCodes {
PatchDoesNotApply = 'PatchDoesNotApply',
NoPathFound = 'NoPathFound',
UnknownPath = 'UnknownPath',
EmptyCommitMessage = 'EmptyCommitMessage'
}
14 changes: 12 additions & 2 deletions extensions/git/src/askpass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@
import { window, InputBoxOptions, Uri, Disposable, workspace } from 'vscode';
import { IDisposable, EmptyDisposable, toDisposable } from './util';
import * as path from 'path';
import { IIPCHandler, IIPCServer } from './ipc/ipcServer';
import { IIPCHandler, IIPCServer, createIPCServer } from './ipc/ipcServer';
import { CredentialsProvider, Credentials } from './api/git';
import { OutputChannelLogger } from './log';

export class Askpass implements IIPCHandler {

private disposable: IDisposable = EmptyDisposable;
private cache = new Map<string, Credentials>();
private credentialsProviders = new Set<CredentialsProvider>();

constructor(private ipc?: IIPCServer) {
static async create(outputChannelLogger: OutputChannelLogger, context?: string): Promise<Askpass> {
try {
return new Askpass(await createIPCServer(context));
} catch (err) {
outputChannelLogger.logError(`Failed to create git askpass IPC: ${err}`);
return new Askpass();
}
}

private constructor(private ipc?: IIPCServer) {
if (ipc) {
this.disposable = ipc.registerHandler('askpass', this);
}
Expand Down
39 changes: 6 additions & 33 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,14 +1516,6 @@ export class CommandCenter {
opts.signoff = true;
}

if (config.get<boolean>('useEditorAsCommitInput')) {
opts.useEditor = true;

if (config.get<boolean>('verboseCommit')) {
opts.verbose = true;
}
}

const smartCommitChanges = config.get<'all' | 'tracked'>('smartCommitChanges');

if (
Expand Down Expand Up @@ -1571,7 +1563,7 @@ export class CommandCenter {

let message = await getCommitMessage();

if (!message && !opts.amend && !opts.useEditor) {
if (!message && !opts.amend) {
return false;
}

Expand Down Expand Up @@ -1631,13 +1623,10 @@ export class CommandCenter {

private async commitWithAnyInput(repository: Repository, opts?: CommitOptions): Promise<void> {
const message = repository.inputBox.value;
const root = Uri.file(repository.root);
const config = workspace.getConfiguration('git', root);

const getCommitMessage = async () => {
let _message: string | undefined = message;

if (!_message && !config.get<boolean>('useEditorAsCommitInput')) {
if (!_message) {
let value: string | undefined = undefined;

if (opts && opts.amend && repository.HEAD && repository.HEAD.commit) {
Expand Down Expand Up @@ -3021,7 +3010,7 @@ export class CommandCenter {
};

let message: string;
let type: 'error' | 'warning' | 'information' = 'error';
let type: 'error' | 'warning' = 'error';

const choices = new Map<string, () => void>();
const openOutputChannelChoice = localize('open git log', "Open Git Log");
Expand Down Expand Up @@ -3084,12 +3073,6 @@ export class CommandCenter {
message = localize('missing user info', "Make sure you configure your 'user.name' and 'user.email' in git.");
choices.set(localize('learn more', "Learn More"), () => commands.executeCommand('vscode.open', Uri.parse('https://aka.ms/vscode-setup-git')));
break;
case GitErrorCodes.EmptyCommitMessage:
message = localize('empty commit', "Commit operation was cancelled due to empty commit message.");
choices.clear();
type = 'information';
options.modal = false;
break;
default: {
const hint = (err.stderr || err.message || String(err))
.replace(/^error: /mi, '')
Expand All @@ -3111,20 +3094,10 @@ export class CommandCenter {
return;
}

let result: string | undefined;
const allChoices = Array.from(choices.keys());

switch (type) {
case 'error':
result = await window.showErrorMessage(message, options, ...allChoices);
break;
case 'warning':
result = await window.showWarningMessage(message, options, ...allChoices);
break;
case 'information':
result = await window.showInformationMessage(message, options, ...allChoices);
break;
}
const result = type === 'error'
? await window.showErrorMessage(message, options, ...allChoices)
: await window.showWarningMessage(message, options, ...allChoices);

if (result) {
const resultFn = choices.get(result);
Expand Down
34 changes: 7 additions & 27 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1400,37 +1400,20 @@ export class Repository {
}

async commit(message: string | undefined, opts: CommitOptions = Object.create(null)): Promise<void> {
const args = ['commit', '--quiet'];
const options: SpawnOptions = {};

if (message) {
options.input = message;
args.push('--file', '-');
}

if (opts.verbose) {
args.push('--verbose');
}
const args = ['commit', '--quiet', '--allow-empty-message'];

if (opts.all) {
args.push('--all');
}

if (opts.amend) {
if (opts.amend && message) {
args.push('--amend');
}

if (!opts.useEditor) {
if (!message) {
if (opts.amend) {
args.push('--no-edit');
} else {
options.input = '';
args.push('--file', '-');
}
}

args.push('--allow-empty-message');
if (opts.amend && !message) {
args.push('--amend', '--no-edit');
} else {
args.push('--file', '-');
}

if (opts.signoff) {
Expand All @@ -1455,7 +1438,7 @@ export class Repository {
}

try {
await this.exec(args, options);
await this.exec(args, !opts.amend || message ? { input: message || '' } : {});
} catch (commitErr) {
await this.handleCommitError(commitErr);
}
Expand All @@ -1479,9 +1462,6 @@ export class Repository {
if (/not possible because you have unmerged files/.test(commitErr.stderr || '')) {
commitErr.gitErrorCode = GitErrorCodes.UnmergedChanges;
throw commitErr;
} else if (/Aborting commit due to empty commit message/.test(commitErr.stderr || '')) {
commitErr.gitErrorCode = GitErrorCodes.EmptyCommitMessage;
throw commitErr;
}

try {
Expand Down
Loading

0 comments on commit ca90050

Please sign in to comment.