All of lore.kernel.org
 help / color / mirror / Atom feed
From: Erik Cervin-Edin <erik@cervined.in>
To: git@vger.kernel.org
Cc: gitster@pobox.com, phillip.wood123@gmail.com,
	Erik Cervin-Edin <erik@cervined.in>
Subject: [PATCH v4 0/3] commit: allow -m/-F/-c/-C for all --fixup variants
Date: Wed, 25 Nov 2026 00:32:08 +0100	[thread overview]
Message-ID: <cover.1795562078.git.erik@cervined.in> (raw)
In-Reply-To: <cover.1790082176.git.erik@cervined.in>

Changes since v3:

  * New 1/3 refactors prepare_to_commit() to write the --fixup subject
    in a block before the message-source chain, as --squash already
    does.  On v3 1/2 Phillip found it unfortunate that the -m and -F
    arms had to be guarded with "!fixup_message" while the fixup arm
    duplicated their work [1] and I agree.

    Originally, I wanted to avoid a refactor -- but the guards were
    getting nasty, and a refactor is the proper fix.  It turned out not
    to be that difficult and I think it makes the series land cleaner.

    With the subject written up front, the -m and -F arms serve every
    --fixup variant unchanged, and the fixup arm is left with only the
    amend case.

  * 2/3 and 3/3 are rebuilt on top of 1/3, which now carries most of
    the change to builtin/commit.c.

  * 3/3 tests: took Phillip's suggestions [2].

  * Log messages: reworded 2/3's history of why these options were
    rejected; 3/3 now gives its motivation, with a use case, and
    explains the "amend!" handling that the v3 cover letter described.

Background
----------

Today only -m works with plain --fixup, and neither -m nor -F works
with --fixup=amend: or --fixup=reword:, which makes those modes
awkward to drive non-interactively.  2/3 lets -m and -F supply the
message for all --fixup variants.  3/3 does the same for -c/-C, so
that all four message sources behave consistently across the plain,
amend, and reword forms.

As in v3, -c/-C go through prepare_amend_commit(), so if the source
commit is itself an "amend!" commit, its subject line is dropped and
only the body is copied.  This is what a no-source
--fixup=amend:<commit> already does.  The helper only knows about
"amend!" and not "fixup!" or "squash!"; that is pre-existing and I
have left it alone here.

The earlier rounds are described in the v2 [3] and v3 [4] cover
letters.

[1] https://lore.kernel.org/git/3354eeb4-3b9d-474e-bf9f-8efd2ca3a512@gmail.com/
[2] https://lore.kernel.org/git/de12af28-a64e-4472-8bd4-b65200772dbe@gmail.com/
[3] https://lore.kernel.org/git/cover.1779792311.git.erik@cervined.in/
[4] https://lore.kernel.org/git/cover.1790082176.git.erik@cervined.in/

Erik Cervin-Edin (3):
  commit: write the --fixup subject the way --squash does
  commit: allow -m/-F for all --fixup variants
  commit: allow -c/-C for all --fixup variants

 Documentation/git-commit.adoc             |  22 +++--
 builtin/commit.c                          |  61 ++++++------
 t/t7500-commit-template-squash-signoff.sh | 114 +++++++++++++++++++---
 3 files changed, 138 insertions(+), 59 deletions(-)

Range-diff against v3:
-:  ---------- > 1:  ebae1fbe05 commit: write the --fixup subject the way --squash does
1:  4a493867bb ! 2:  051b659965 commit: allow -m/-F for all kinds of --fixup
    @@ Metadata
     Author: Erik Cervin-Edin <erik@cervined.in>
     
      ## Commit message ##
    -    commit: allow -m/-F for all kinds of --fixup
    +    commit: allow -m/-F for all --fixup variants
     
         The ability to provide a commit message for git commit --fixup and its
    -    variations is limited:
    +    variants is limited:
     
    -      * Plain --fixup only allows using the -m flag
    +      * Plain --fixup accepts -m but not -F
     
    -      * The amend/reword --fixup variants only allow supplying the message
    -        using an editor
    +      * The amend/reword variants accept a message only through an editor
    +        (or a GIT_EDITOR script standing in for one)
     
    -    For amend/reword, the -m and -F flags are rejected: -m is caught by a
    -    die() in prepare_to_commit(), and -F is caught by
    -    die_for_incompatible_opt4() which groups -F with --fixup as mutually
    -    exclusive.  This makes these modes poorly suited for non-interactive
    +    This makes the amend/reword variants poorly suited for non-interactive
         workflows -- notably when using AI coding agents.
     
    -    When support to use the -m option was introduced in [1] it was noted
    -    that there could be support for other options but at the time the use
    -    case was deemed too niche.  Later, when the amend suboption was
    -    introduced in [2] -m support for amend fixups was discussed but not
    -    pursued, and -F was already caught by the higher-layer incompatibility
    -    check grouping it with --fixup.
    +    When --fixup learned to take -m [1], it was noted that other options
    +    (-c/-C/-F) could also be supported, but were left out for lack of a
    +    clear use case.  Later, when the amend suboption was introduced in [2],
    +    -m was initially supported for amend fixups too, but was dropped for the
    +    same reason [3].
     
    -    The rejections of these options hark back to when --fixup was
    -    introduced in [3] and as noted in [1] -- there's nothing inherently
    -    preventing support for them.  The current patchwork of which flags
    -    work with which --fixup variants has no strong logic to it, and
    -    allowing all of them simplifies both the code and the interface.
    +    The rejections of these options hark back to when --fixup was introduced
    +    in [4], but as [1] noted, nothing inherently prevents supporting them.
     
    -    Allow -m and -F to supply the message body for all --fixup variations,
    -    mirroring the flow of a regular commit.  -c and -C, which are blocked
    -    by the same incompatibility check, are handled in the next commit.
    +    The current patchwork of which options work with which --fixup variants
    +    has no strong logic to it, and allowing all of them simplifies the
    +    interface.
    +
    +    Allow -m and -F to supply the message body for all --fixup variants,
    +    mirroring the flow of a regular commit.  With --fixup=amend/reword the
    +    given message replaces the one that would otherwise be copied from the
    +    target commit.  Options -c and -C are handled in the next commit.
     
         1. 30884c9afc (commit: add support for --fixup <commit> -m"<extra
            message>", 2017-12-22)
    @@ Commit message
         2. 494d314a05 (commit: add amend suboption to --fixup to create amend!
            commit, 2021-03-15)
     
    -    3. d71b8ba7c9 (commit: --fixup option for use with rebase --autosquash,
    +    3. https://lore.kernel.org/git/xmqqft1o80pe.fsf@gitster.g/
    +
    +    4. d71b8ba7c9 (commit: --fixup option for use with rebase --autosquash,
            2010-11-02)
     
         Helped-by: Junio C Hamano <gitster@pobox.com>
    -    Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
    +    Helped-by: Phillip Wood <phillip.wood123@gmail.com>
         Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
     
      ## Documentation/git-commit.adoc ##
    @@ Documentation/git-commit.adoc: include::diff-context-options.adoc[]
     
      ## builtin/commit.c ##
     @@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
    - 	if (have_option_m && !fixup_message) {
    - 		strbuf_addbuf(&sb, &message);
    - 		hook_arg1 = "message";
    --	} else if (logfile && !strcmp(logfile, "-")) {
    -+	} else if (logfile && !fixup_message && !strcmp(logfile, "-")) {
    - 		if (isatty(0))
    - 			fprintf(stderr, _("(reading log message from standard input)\n"));
    - 		if (strbuf_read(&sb, 0, 0) < 0)
    - 			die_errno(_("could not read log from standard input"));
    - 		hook_arg1 = "message";
    --	} else if (logfile) {
    -+	} else if (logfile && !fixup_message) {
    - 		if (strbuf_read_file(&sb, logfile, 0) < 0)
    - 			die_errno(_("could not read log file '%s'"),
    - 				  logfile);
    - 		hook_arg1 = "message";
    --	} else if (use_message) {
    -+	} else if (use_message && !fixup_message) {
    - 		const char *buffer;
    - 		buffer = strstr(use_message_buffer, "\n\n");
    - 		if (buffer)
    -@@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
    - 		hook_arg1 = "message";
    - 
    + 		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) {
      		/*
    --		 * Only `-m` commit message option is checked here, as
    --		 * it supports `--fixup` to append the commit message.
    --		 *
    --		 * The other commit message options `-c`/`-C`/`-F` are
    --		 * incompatible with all the forms of `--fixup` and
    --		 * have already errored out while parsing the `git commit`
    --		 * options.
    -+		 * Only `-m` and `-F` are handled here. `-c`/`-C` are
    -+		 * incompatible with --fixup and have already errored out
    -+		 * during option parsing.
    - 		 */
    --		if (have_option_m && !strcmp(fixup_prefix, "fixup"))
    -+		if (have_option_m) {
    - 			strbuf_addbuf(&sb, &message);
    --
    --		if (!strcmp(fixup_prefix, "amend")) {
    --			if (have_option_m)
    --				die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
    -+		} else if (logfile && !strcmp(logfile, "-")) {
    -+			if (isatty(0))
    -+				fprintf(stderr, _("(reading log message from standard input)\n"));
    -+			if (strbuf_read(&sb, 0, 0) < 0)
    -+				die_errno(_("could not read log from standard input"));
    -+		} else if (logfile) {
    -+			if (strbuf_read_file(&sb, logfile, 0) < 0)
    -+				die_errno(_("could not read log file '%s'"), logfile);
    -+		} else if (!strcmp(fixup_prefix, "amend")) {
    - 			prepare_amend_commit(commit, &sb, &ctx);
    - 		}
    - 	} else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
    + 		 * Insert the proper subject line before other commit
     @@ builtin/commit.c: static int parse_and_validate_options(int argc, const char *argv[],
      	}
      	if (fixup_message && squash_message)
2:  13608615d6 ! 3:  159a56c510 commit: allow -c/-C for all kinds of --fixup
    @@ Metadata
     Author: Erik Cervin-Edin <erik@cervined.in>
     
      ## Commit message ##
    -    commit: allow -c/-C for all kinds of --fixup
    +    commit: allow -c/-C for all --fixup variants
     
         The fixup code path in prepare_to_commit() only knows how to take a
         message body from -m or -F.  Now that the previous commit allows -m and
    -    -F for all --fixup variations, -c/-C are the odd ones out.
    +    -F for all --fixup variants, -c/-C are the odd ones out.
     
    -    Teach the fixup path to look up the ref given to -c/-C and seed its
    -    message when preparing to amend the commit, mirroring what --fixup=amend
    -    does when no message source is given.  With this in place, -m/-F/-c/-C
    -    all behave consistently across the plain, amend, and reword --fixup
    -    forms.
    +    Teach the fixup path to take the message body from the commit given to
    +    -c/-C, using prepare_amend_commit() as --fixup=amend does when no
    +    message source is given.
    +
    +    The main motivation is consistency: with -c/-C allowed, every message
    +    option works with every --fixup variant, and there's no exception to
    +    document or remember.  Using -c/-C under --fixup is admittedly niche,
    +    but not useless; for example, rewording commit Y based on X's message
    +    after an earlier rebase split X into X' and Y, when Y wasn't reworded at
    +    the time:
    +
    +        git commit --fixup=reword:Y -c X
    +
    +    Like --fixup=amend, this copies only the body when the source itself is
    +    an "amend!" commit.  Under --fixup the subject is always generated, and
    +    the body of an "amend!" commit is the message intended for its target,
    +    so copying its "amend!" line would leave it in the final message after
    +    autosquash.  This also means that "git commit --fixup=amend:X -C X"
    +    produces the same message as "GIT_EDITOR=: git commit --fixup=amend:X".
    +
    +    Plain --fixup never opens an editor, so -c there behaves like -C.
     
         The incompatibility check grouping -C, -c, and --fixup can go away
         entirely, as -C and -c are already rejected together by the check that
    @@ Documentation/git-commit.adoc: The commit created by `--fixup=amend:<commit>` is
     
      ## builtin/commit.c ##
     @@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
    + 			die_errno(_("could not read log file '%s'"),
    + 				  logfile);
      		hook_arg1 = "message";
    - 
    - 		/*
    --		 * Only `-m` and `-F` are handled here. `-c`/`-C` are
    --		 * incompatible with --fixup and have already errored out
    --		 * during option parsing.
    -+		 * `-m`, `-F`, `-C`, and `-c` provide the message body.
    -+		 * If none was given and this is an amend, use the target
    -+		 * commit's body instead.
    - 		 */
    - 		if (have_option_m) {
    - 			strbuf_addbuf(&sb, &message);
    +-	} else if (use_message) {
    ++	} else if (use_message && !fixup_message) {
    + 		const char *buffer;
    + 		buffer = strstr(use_message_buffer, "\n\n");
    + 		if (buffer)
     @@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
    - 		} else if (logfile) {
    - 			if (strbuf_read_file(&sb, logfile, 0) < 0)
    - 				die_errno(_("could not read log file '%s'"), logfile);
    -+		} else if (use_message) {
    -+			struct commit *c = lookup_commit_reference_by_name(use_message);
    -+			if (!c)
    -+				die(_("could not lookup commit '%s'"), use_message);
    -+			prepare_amend_commit(c, &sb, &ctx);
    - 		} else if (!strcmp(fixup_prefix, "amend")) {
    - 			prepare_amend_commit(commit, &sb, &ctx);
    + 		hook_arg1 = "commit";
    + 		hook_arg2 = use_message;
    + 	} else if (fixup_message) {
    ++		const char *refname = NULL;
    ++
    + 		hook_arg1 = "message";
    +-		if (!strcmp(fixup_prefix, "amend")) {
    ++		if (use_message)
    ++			refname = use_message;
    ++		else if (!strcmp(fixup_prefix, "amend"))
    ++			refname = fixup_commit;
    ++
    ++		if (refname) {
    + 			struct pretty_print_context ctx = {0};
    +-			struct commit *c = lookup_commit_reference_by_name(fixup_commit);
    ++			struct commit *c = lookup_commit_reference_by_name(refname);
    ++
    + 			if (!c)
    +-				die(_("could not lookup commit '%s'"), fixup_commit);
    ++				die(_("could not lookup commit '%s'"), refname);
    + 			ctx.output_encoding = get_commit_output_encoding();
    + 			prepare_amend_commit(c, &sb, &ctx);
      		}
     @@ builtin/commit.c: static int parse_and_validate_options(int argc, const char *argv[],
      	}
    @@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
      
     +test_expect_success 'commit --fixup works with -C' '
     +	commit_for_rebase_autosquash_setup &&
    -+	git commit --fixup HEAD~ -C HEAD &&
    ++	GIT_EDITOR=false git commit --fixup HEAD~ -C HEAD &&
     +	test_commit_message HEAD <<-EOF
     +	fixup! $(git log -1 --format=%s HEAD~2)
     +
    @@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
     +
     +test_expect_success 'commit --fixup=amend: works with -c' '
     +	commit_for_rebase_autosquash_setup &&
    -+	test_set_editor : &&
    -+	git commit --fixup=amend:HEAD -c HEAD~ &&
    ++	GIT_EDITOR="echo edited >>" git commit --fixup=amend:HEAD -c HEAD~ &&
     +	test_commit_message HEAD <<-EOF
     +	amend! intermediate commit
     +
    @@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
     +
     +	target message body line 1
     +	target message body line 2
    ++
    ++	edited
     +	EOF
     +'
     +
    @@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
     +	git log -1 --pretty=%B >with-c &&
     +
     +	git reset --hard "$start" &&
    -+	test_set_editor : &&
     +	git commit --fixup=amend:HEAD &&
     +	git commit --fixup=amend:HEAD &&
     +	git log -1 --pretty=%B >without-c &&

base-commit: f7de81456940dd6f3274e461149bba12965de609
-- 
2.56.1.978.gcc9bcf3eaa


  parent reply	other threads:[~2026-11-24 23:32 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     ` Erik Cervin-Edin [this message]
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
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=cover.1795562078.git.erik@cervined.in \
    --to=erik@cervined.in \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.