diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index bf5c83e2b8597ec557b3d642f916a94b6b69db10..12c43c3540d715934b536ce8c9ee00df7553993b 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1583,9 +1583,9 @@ export class CommandCenter { } } - const message = await getCommitMessage(); + let message = await getCommitMessage(); - if (!message) { + if (!message && !opts.amend) { return false; } @@ -1622,7 +1622,7 @@ export class CommandCenter { let value: string | undefined = undefined; if (opts && opts.amend && repository.HEAD && repository.HEAD.commit) { - value = (await repository.getCommit(repository.HEAD.commit)).message; + return undefined; } const branchName = repository.headShortName; diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 0846ca91f42ebf8af673d4a14a2e94c4128eca6b..78ddf4d0ae7ab6fa479403a1c3e679930534e879 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -1332,17 +1332,23 @@ export class Repository { } } - async commit(message: string, opts: CommitOptions = Object.create(null)): Promise { - const args = ['commit', '--quiet', '--allow-empty-message', '--file', '-']; + async commit(message: string | undefined, opts: CommitOptions = Object.create(null)): Promise { + 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.amend && !message) { + args.push('--amend', '--no-edit'); + } else { + args.push('--file', '-'); + } + if (opts.signoff) { args.push('--signoff'); } @@ -1360,7 +1366,7 @@ export class Repository { } try { - await this.run(args, { input: message || '' }); + await this.run(args, !opts.amend || message ? { input: message || '' } : {}); } catch (commitErr) { await this.handleCommitError(commitErr); } diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 7ff4418e6a32350fef89ae758ffb1411ebf6fc60..d09f118295c2622165c79f90ec8c413b59733737 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -985,7 +985,7 @@ export class Repository implements Disposable { await this.run(Operation.RevertFiles, () => this.repository.revert('HEAD', resources.map(r => r.fsPath))); } - async commit(message: string, opts: CommitOptions = Object.create(null)): Promise { + async commit(message: string | undefined, opts: CommitOptions = Object.create(null)): Promise { if (this.rebaseCommit) { await this.run(Operation.RebaseContinue, async () => { if (opts.all) {