Skip to content

Commit ee1a1dd

Browse files
committed
Merge branch 'rs/commit-m-no-edit' into maint
* rs/commit-m-no-edit: commit: don't start editor if empty message is given with -m
2 parents 872f5bf + 2520677 commit ee1a1dd

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

builtin/commit.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static const char *cleanup_arg;
107107

108108
static enum commit_whence whence;
109109
static int use_editor = 1, include_status = 1;
110-
static int show_ignored_in_status;
110+
static int show_ignored_in_status, have_option_m;
111111
static const char *only_include_assumed;
112112
static struct strbuf message = STRBUF_INIT;
113113

@@ -121,9 +121,11 @@ static enum {
121121
static int opt_parse_m(const struct option *opt, const char *arg, int unset)
122122
{
123123
struct strbuf *buf = opt->value;
124-
if (unset)
124+
if (unset) {
125+
have_option_m = 0;
125126
strbuf_setlen(buf, 0);
126-
else {
127+
} else {
128+
have_option_m = 1;
127129
if (buf->len)
128130
strbuf_addch(buf, '\n');
129131
strbuf_addstr(buf, arg);
@@ -975,7 +977,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
975977
if (force_author && renew_authorship)
976978
die(_("Using both --reset-author and --author does not make sense"));
977979

978-
if (logfile || message.len || use_message || fixup_message)
980+
if (logfile || have_option_m || use_message || fixup_message)
979981
use_editor = 0;
980982
if (0 <= edit_flag)
981983
use_editor = edit_flag;

t/t7502-commit.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,23 @@ test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
361361
test_cmp expect .git/result
362362
'
363363

364+
test_expect_success 'do not fire editor if -m <msg> was given' '
365+
echo tick >file &&
366+
git add file &&
367+
echo "editor not started" >.git/result &&
368+
(GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" git commit -m tick) &&
369+
test "$(cat .git/result)" = "editor not started"
370+
'
371+
372+
test_expect_success 'do not fire editor if -m "" was given' '
373+
echo tock >file &&
374+
git add file &&
375+
echo "editor not started" >.git/result &&
376+
(GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" \
377+
git commit -m "" --allow-empty-message) &&
378+
test "$(cat .git/result)" = "editor not started"
379+
'
380+
364381
test_expect_success 'do not fire editor in the presence of conflicts' '
365382
366383
git clean -f &&

0 commit comments

Comments
 (0)