Skip to content

Commit ca1ba20

Browse files
committed
commit: honour --no-edit
After making fixes to the contents to be committed, it is not unusual to update the current commit without rewording the message. Idioms to tell "commit --amend" that we do not need an editor have been: $ EDITOR=: git commit --amend $ git commit --amend -C HEAD but that was only because a more natural "--no-edit" option in $ git commit --amend --no-edit was not honoured. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1af524e commit ca1ba20

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

builtin/commit.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ static const char *template_file;
8181
static const char *author_message, *author_message_buffer;
8282
static char *edit_message, *use_message;
8383
static char *fixup_message, *squash_message;
84-
static int all, edit_flag, also, interactive, patch_interactive, only, amend, signoff;
84+
static int all, also, interactive, patch_interactive, only, amend, signoff;
85+
static int edit_flag = -1; /* unspecified */
8586
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
8687
static int no_post_rewrite, allow_empty_message;
8788
static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
@@ -141,7 +142,7 @@ static struct option builtin_commit_options[] = {
141142
OPT_BOOLEAN(0, "reset-author", &renew_authorship, "the commit is authored by me now (used with -C-c/--amend)"),
142143
OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
143144
OPT_FILENAME('t', "template", &template_file, "use specified template file"),
144-
OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"),
145+
OPT_BOOL('e', "edit", &edit_flag, "force edit of commit"),
145146
OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
146147
OPT_BOOLEAN(0, "status", &include_status, "include status in commit message template"),
147148
/* end commit message options */
@@ -1020,8 +1021,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
10201021

10211022
if (logfile || message.len || use_message || fixup_message)
10221023
use_editor = 0;
1023-
if (edit_flag)
1024-
use_editor = 1;
1024+
if (0 <= edit_flag)
1025+
use_editor = edit_flag;
10251026
if (!use_editor)
10261027
setenv("GIT_EDITOR", ":", 1);
10271028

0 commit comments

Comments
 (0)