From: Junio C Hamano <gitster@pobox.com>
To: Erik Cervin-Edin <erik@cervined.in>
Cc: git@vger.kernel.org, phillip.wood123@gmail.com
Subject: Re: [PATCH v5 1/3] commit: write the --fixup subject the way --squash does
Date: Sat, 28 Nov 2026 17:31:01 -0800 [thread overview]
Message-ID: <xmqqmrqss9t6.fsf@gitster.g> (raw)
In-Reply-To: <ebae1fbe0586bc3c396c26aaf044149a0b9a16bb.1795867565.git.erik@cervined.in> (Erik Cervin-Edin's message of "Sat, 28 Nov 2026 13:13:58 +0100")
Erik Cervin-Edin <erik@cervined.in> writes:
> Two commits that follow teach commit --fixup how to take messages like
> --squash. In preparation for that, refactor prepare_to_commit() to
> write the --fixup subject in a block before the chain, as --squash does.
> Since the two options are mutually exclusive, put each subject block in
> its own branch of an if/else-if.
Because parse_and_validate_options() already rejects combining --fixup
and --squash with a die(), placing the fixup_message and squash_message
subject blocks in an if/else-if ahead of the message-source chain is
safe and mirrors how --squash already works.
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 36e47e18ed..698823d4fa 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -781,7 +781,21 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
> "pre-commit", NULL))
> return 0;
>
> - if (squash_message) {
> + if (fixup_message) {
> + struct pretty_print_context ctx = {0};
> + struct commit *c;
> + char *fmt;
> + c = lookup_commit_reference_by_name(fixup_commit);
> + if (!c)
> + die(_("could not lookup commit '%s'"), fixup_commit);
> + ctx.output_encoding = get_commit_output_encoding();
> + fmt = xstrfmt("%s! %%s\n\n", fixup_prefix);
> + repo_format_commit_message(the_repository, c, fmt, &sb,
> + &ctx);
> + free(fmt);
> + if (have_option_m && !strcmp(fixup_prefix, "amend"))
> + die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
> + } else if (squash_message) {
Checking the remaining arms in prepare_to_commit() confirms that
observable behavior is unchanged.
At this point in the series, -C, -c, and -F are still rejected alongside
--fixup in parse_and_validate_options(), and combining --amend with
--fixup explicitly leaves use_message NULL there.
As a result, --fixup either enters the have_option_m arm (which now sets
hook_arg1 to "message" and appends &message for plain --fixup, while
amend/reword with -m already died above) or falls through to the
fixup_message arm, which sets hook_arg1 to "message" and calls
prepare_amend_commit() for amend/reword.
> if (!strcmp(fixup_prefix, "amend")) {
> - if (have_option_m)
> - die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
> - prepare_amend_commit(commit, &sb, &ctx);
> + struct pretty_print_context ctx = {0};
> + struct commit *c = lookup_commit_reference_by_name(fixup_commit);
> + if (!c)
> + die(_("could not lookup commit '%s'"), fixup_commit);
> + ctx.output_encoding = get_commit_output_encoding();
> + prepare_amend_commit(c, &sb, &ctx);
> }
> } else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
> size_t merge_msg_start;
Doing a second lookup_commit_reference_by_name(fixup_commit) inside the
fixup_message arm for the amend case feels a little bit wasteful, but
keeps the subject block cleanly separated from the body block ahead of
the final patch.
Looking good.
next prev parent reply other threads:[~2026-11-29 1:31 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-18 11:22 [PATCH 0/1] commit: allow -m/-F with --fixup=amend: or reword: erik
2026-05-18 11:22 ` [PATCH 1/1] " erik
2026-05-18 12:39 ` Junio C Hamano
2026-05-18 15:27 ` Phillip Wood
2026-05-24 15:00 ` Erik Cervin Edin
2026-05-26 10:47 ` [PATCH v2 0/2] commit: allow -m/-F/-c/-C for all --fixup variations erik
2026-05-26 10:47 ` [PATCH v2 1/2] commit: allow -m/-F for all kinds of --fixup erik
2026-05-26 10:47 ` [PATCH v2 2/2] commit: allow -c/-C " erik
2026-08-26 21:31 ` Junio C Hamano
2026-09-04 18:47 ` Erik Cervin Edin
2026-09-22 13:04 ` [PATCH v3 0/2] commit: allow -m/-F/-c/-C for all --fixup variations erik
2026-09-22 13:04 ` [PATCH v3 1/2] commit: allow -m/-F for all kinds of --fixup erik
2026-10-21 15:11 ` Phillip Wood
2026-09-22 13:04 ` [PATCH v3 2/2] commit: allow -c/-C " erik
2026-10-21 15:10 ` Phillip Wood
2026-10-21 15:13 ` [PATCH v3 0/2] commit: allow -m/-F/-c/-C for all --fixup variations Phillip Wood
2026-11-05 14:51 ` Erik Cervin-Edin
2026-11-09 10:54 ` Phillip Wood
2026-11-24 23:32 ` [PATCH v4 0/3] commit: allow -m/-F/-c/-C for all --fixup variants Erik Cervin-Edin
2026-11-24 23:32 ` [PATCH v4 1/3] commit: write the --fixup subject the way --squash does Erik Cervin-Edin
2026-11-24 23:32 ` [PATCH v4 2/3] commit: allow -m/-F for all --fixup variants Erik Cervin-Edin
2026-11-24 23:32 ` [PATCH v4 3/3] commit: allow -c/-C " Erik Cervin-Edin
2026-11-25 14:37 ` [PATCH v4 0/3] commit: allow -m/-F/-c/-C " Phillip Wood
2026-11-26 9:17 ` erik88
2026-11-26 15:07 ` Phillip Wood
2026-11-28 12:13 ` [PATCH v5 " Erik Cervin-Edin
2026-11-28 12:13 ` [PATCH v5 1/3] commit: write the --fixup subject the way --squash does Erik Cervin-Edin
2026-11-29 1:31 ` Junio C Hamano [this message]
2026-11-28 12:14 ` [PATCH v5 2/3] commit: allow -m/-F for all --fixup variants Erik Cervin-Edin
2026-11-29 1:51 ` Junio C Hamano
2026-11-28 12:14 ` [PATCH v5 3/3] commit: allow -c/-C " Erik Cervin-Edin
2026-11-29 18:34 ` Junio C Hamano
2026-11-30 14:28 ` Phillip Wood
2026-11-30 14:29 ` [PATCH v5 0/3] commit: allow -m/-F/-c/-C " Phillip Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqmrqss9t6.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=erik@cervined.in \
--cc=git@vger.kernel.org \
--cc=phillip.wood123@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox