Skip to content

Commit

Permalink
Merge branch 'rs/commit-m-no-edit' into maint
Browse files Browse the repository at this point in the history
* rs/commit-m-no-edit:
  commit: don't start editor if empty message is given with -m
  • Loading branch information
Junio C Hamano committed Jun 27, 2013
2 parents 872f5bf + 2520677 commit ee1a1dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
10 changes: 6 additions & 4 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions t/t7502-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit ee1a1dd

Please sign in to comment.