git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Documentation/merge-options: clarify --squash behavior

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 25, 2019, 04:16 UTC
Message-ID
<xmqqr29qyb1i.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20190424212212.10039-1-vishal.l.verma@intel.com>
Vishal Verma <vishal.l.verma@intel.com> writes:
Show 12 quoted lines
> Add a note to the --squash option for git-merge to clarify its behavior
> with respect to --commit. When --squash is supplied, 'option_commit' is
> silently dropped. This can be surprising to a user who tries to override
> the no-commit behavior of squash using --commit explicitly.
>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
>
> There may be an argument to make --commit 'just work' with squash, but
> that might involve changing option_commit from OPT_BOOL to something
> that can distinguish between the default, what's requested on the
> command line, or the --no- version.

I think it is bad to silently ignore the option. With or without this documentation update, I think it is sensible to update the code so that it errors out when "--squash --commit" are both given at the same time, just like when "--squash --no-ff" is given.

Or make it "just work" as you said. Using a boolean variable as tristate is something we do in many places and it by itself is not a rocket science. You initialize the variable to -1 (unset), let parse_options() to set it to 0/1 when "--[no-]commit" is seen, and inspect after parse_options() finishes. If the variable is still -1, you know the user wants "the default" behaviour.

The "default" behaviour you are proposing would probably be something like

        if (option_commit < 0) {
                /* 
                 * default to record the result in a commit.
                 * but --squash traditionally does not.
                 */
                if (!squash)
                        option_commit = 1;
                else
                        option_commit = 0;
        }

But I suspect that the option parsing part is the least difficult in the "make it just work" change. That is because I think that the machinery to record the result in a commit is not expecting to be asked to create a single-parent commit to record the result of the squashing, so there may be need for adjusting to how the result wants to be recorded before the code makes a commit.

Previous: Vishal VermaNext: Vishal Verma
Message 2 of 4 in “Documentation/merge-options: clarify --squash behavior”
  1. Documentation/merge-options: clarify --squash behaviorVishal Verma, Apr 24, 2019
  2. Junio C HamanoApr 25, 2019
  3. Vishal VermaApr 25, 2019
  4. builtin/merges: clarify --squash behavior with --commitvishal@kernel.org, Apr 26, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.