Git - use editor as commit message input (#151491)

This commit is contained in:
Ladislau Szomoru
2022-06-08 15:45:27 +02:00
committed by GitHub
parent 793b0fd550
commit 6f5fc17622
15 changed files with 229 additions and 45 deletions

View File

@@ -1400,20 +1400,37 @@ export class Repository {
}
async commit(message: string | undefined, opts: CommitOptions = Object.create(null)): Promise<void> {
const args = ['commit', '--quiet', '--allow-empty-message'];
const args = ['commit', '--quiet'];
const options: SpawnOptions = {};
if (message) {
options.input = message;
args.push('--file', '-');
}
if (opts.verbose) {
args.push('--verbose');
}
if (opts.all) {
args.push('--all');
}
if (opts.amend && message) {
if (opts.amend) {
args.push('--amend');
}
if (opts.amend && !message) {
args.push('--amend', '--no-edit');
} else {
args.push('--file', '-');
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.signoff) {
@@ -1438,7 +1455,7 @@ export class Repository {
}
try {
await this.exec(args, !opts.amend || message ? { input: message || '' } : {});
await this.exec(args, options);
} catch (commitErr) {
await this.handleCommitError(commitErr);
}
@@ -1462,6 +1479,9 @@ 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 {