Skip to content

Commit c1ab3b8

Browse files
committed
Merge branch 'ab/commit-m-with-fixup' into maint
"git commit --fixup" did not allow "-m<message>" option to be used at the same time; allow it to annotate resulting commit with more text. * ab/commit-m-with-fixup: commit: add support for --fixup <commit> -m"<extra message>" commit doc: document that -c, -C, -F and --fixup with -m error
2 parents 12accdc + 30884c9 commit c1ab3b8

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Documentation/git-commit.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ OPTIONS
144144
Use the given <msg> as the commit message.
145145
If multiple `-m` options are given, their values are
146146
concatenated as separate paragraphs.
147+
+
148+
The `-m` option is mutually exclusive with `-c`, `-C`, and `-F`.
147149

148150
-t <file>::
149151
--template=<file>::

builtin/commit.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
701701
}
702702
}
703703

704-
if (have_option_m) {
704+
if (have_option_m && !fixup_message) {
705705
strbuf_addbuf(&sb, &message);
706706
hook_arg1 = "message";
707707
} else if (logfile && !strcmp(logfile, "-")) {
@@ -731,6 +731,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
731731
ctx.output_encoding = get_commit_output_encoding();
732732
format_commit_message(commit, "fixup! %s\n\n",
733733
&sb, &ctx);
734+
if (have_option_m)
735+
strbuf_addbuf(&sb, &message);
734736
hook_arg1 = "message";
735737
} else if (!stat(git_path_merge_msg(), &statbuf)) {
736738
/*
@@ -1197,8 +1199,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
11971199
f++;
11981200
if (f > 1)
11991201
die(_("Only one of -c/-C/-F/--fixup can be used."));
1200-
if (have_option_m && f > 0)
1201-
die((_("Option -m cannot be combined with -c/-C/-F/--fixup.")));
1202+
if (have_option_m && (edit_message || use_message || logfile))
1203+
die((_("Option -m cannot be combined with -c/-C/-F.")));
12021204
if (f || have_option_m)
12031205
template_file = NULL;
12041206
if (edit_message)

t/t7500-commit.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ test_expect_success 'commit --fixup provides correct one-line commit message' '
272272
commit_msg_is "fixup! target message subject line"
273273
'
274274

275+
test_expect_success 'commit --fixup -m"something" -m"extra"' '
276+
commit_for_rebase_autosquash_setup &&
277+
git commit --fixup HEAD~1 -m"something" -m"extra" &&
278+
commit_msg_is "fixup! target message subject linesomething
279+
280+
extra"
281+
'
282+
275283
test_expect_success 'commit --squash works with -F' '
276284
commit_for_rebase_autosquash_setup &&
277285
echo "log message from file" >msgfile &&
@@ -325,7 +333,6 @@ test_expect_success 'invalid message options when using --fixup' '
325333
test_must_fail git commit --fixup HEAD~1 --squash HEAD~2 &&
326334
test_must_fail git commit --fixup HEAD~1 -C HEAD~2 &&
327335
test_must_fail git commit --fixup HEAD~1 -c HEAD~2 &&
328-
test_must_fail git commit --fixup HEAD~1 -m "cmdline message" &&
329336
test_must_fail git commit --fixup HEAD~1 -F log
330337
'
331338

0 commit comments

Comments
 (0)