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

Re: [PATCH] Teach 'git merge' and 'git pull' the option --ff-only

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 28, 2009, 22:45 UTC
Message-ID
<7vk4yfi1dd.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4AE8C281.50104@gmail.com>
Björn Gustavsson <bgustavsson@gmail.com> writes:
Show 8 quoted lines
> For convenience in scripts and aliases, add the option
> --ff-only to only allow fast-forwards.
>
> Acknowledgements: I did look at Yuval Kogman's earlier
> patch (107768 in gmane), mainly as shortcut to find my
> way in the code, but I did not copy anything directly.
>
> Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>
Thanks.  I think you covered the points in the old discussion thread.
Show 11 quoted lines
> diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt
> index adadf8e..fbf8976 100644
> --- a/Documentation/merge-options.txt
> +++ b/Documentation/merge-options.txt
> @@ -60,6 +60,10 @@
>  	a fast-forward, only update the branch pointer. This is
>  	the default behavior of git-merge.
>  
> +--ff-only::
> +	Refuse to merge unless the merge can be resolved as a
> +	fast-forward.

Do you or do you not allow "already up to date"? I think it makes sense to allow it, but it is unclear from these two lines.

Show 6 quoted lines
> @@ -874,6 +877,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
>  		option_commit = 0;
>  	}
>  
> +	if (!allow_fast_forward && fast_forward_only)
> +		die("You cannot combine --no-ff with --ff-only.");

Are these the only nonsensical combinations? How should this interact with other options, e.g. --squash or --message?

Show 10 quoted lines
> @@ -969,8 +975,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
>  	}
>  
>  	for (i = 0; i < use_strategies_nr; i++) {
> -		if (use_strategies[i]->attr & NO_FAST_FORWARD)
> +		if (use_strategies[i]->attr & NO_FAST_FORWARD) {
>  			allow_fast_forward = 0;
> +			if (fast_forward_only)
> +				die("You cannot combine --ff-only with the merge strategy '%s'.", use_strategies[i]->name);
> +		}

I am not convinced this tests the right condition nor it is placed at the right place in the codepath---even if a specified strategy happens to allow fast-forward, wouldn't it be nonsense to say

    $ git merge --ff-only -s resolve that-one

in the first place? Note that I am not saying "I am convinced this is wrong."

Show 6 quoted lines
> @@ -1040,7 +1049,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
>  		 * only one common.
>  		 */
>  		refresh_cache(REFRESH_QUIET);
> -		if (allow_trivial) {
> +		if (allow_trivial && !fast_forward_only) {
Good.
Show 6 quoted lines
> @@ -1079,6 +1088,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
>  		}
>  	}
>  
> +	if (fast_forward_only)
> +		die("Not possible to fast forward, aborting.");
Good.
Previous: Björn GustavssonNext: Björn Gustavsson
Message 2 of 3 in “Teach 'git merge' and 'git pull' the option --ff-only”
  1. Teach 'git merge' and 'git pull' the option --ff-onlyBjörn Gustavsson, Oct 28, 2009
  2. Junio C HamanoOct 28, 2009
  3. Björn GustavssonOct 29, 2009

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.