diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-06-27 14:38:07 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-06-27 14:38:07 -0700 |
commit | ee1a1ddf38a791e6464a71814de0b74c57098eb2 (patch) | |
tree | daf5cfe2bc5c1ab9b5fccd6102913bf4be0bafda | |
parent | Merge branch 'jc/strbuf-branchname-fix' into maint (diff) | |
parent | commit: don't start editor if empty message is given with -m (diff) | |
download | tgif-ee1a1ddf38a791e6464a71814de0b74c57098eb2.tar.xz |
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
-rw-r--r-- | builtin/commit.c | 10 | ||||
-rwxr-xr-x | t/t7502-commit.sh | 17 |
2 files changed, 23 insertions, 4 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index d2f30d960a..1621dfcd40 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -107,7 +107,7 @@ static const char *cleanup_arg; static enum commit_whence whence; static int use_editor = 1, include_status = 1; -static int show_ignored_in_status; +static int show_ignored_in_status, have_option_m; static const char *only_include_assumed; static struct strbuf message = STRBUF_INIT; @@ -121,9 +121,11 @@ static enum { static int opt_parse_m(const struct option *opt, const char *arg, int unset) { struct strbuf *buf = opt->value; - if (unset) + if (unset) { + have_option_m = 0; strbuf_setlen(buf, 0); - else { + } else { + have_option_m = 1; if (buf->len) strbuf_addch(buf, '\n'); strbuf_addstr(buf, arg); @@ -975,7 +977,7 @@ static int parse_and_validate_options(int argc, const char *argv[], if (force_author && renew_authorship) die(_("Using both --reset-author and --author does not make sense")); - if (logfile || message.len || use_message || fixup_message) + if (logfile || have_option_m || use_message || fixup_message) use_editor = 0; if (0 <= edit_flag) use_editor = edit_flag; diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index a4938b1e45..6313da2cdd 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -361,6 +361,23 @@ test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' ' test_cmp expect .git/result ' +test_expect_success 'do not fire editor if -m <msg> was given' ' + echo tick >file && + git add file && + echo "editor not started" >.git/result && + (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" git commit -m tick) && + test "$(cat .git/result)" = "editor not started" +' + +test_expect_success 'do not fire editor if -m "" was given' ' + echo tock >file && + git add file && + echo "editor not started" >.git/result && + (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" \ + git commit -m "" --allow-empty-message) && + test "$(cat .git/result)" = "editor not started" +' + test_expect_success 'do not fire editor in the presence of conflicts' ' git clean -f && |