All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ruslan Yakauleu via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Ruslan Yakauleu <ruslan.yakauleu@gmail.com>,
	Ruslan Yakauleu <ruslan.yakauleu@gmail.com>
Subject: [PATCH] merge: --ff-one-only to apply FF if commit is one
Date: Wed, 25 Oct 2023 08:58:00 +0000	[thread overview]
Message-ID: <pull.1599.git.git.1698224280816.gitgitgadget@gmail.com> (raw)

From: Ruslan Yakauleu <ruslan.yakauleu@gmail.com>

A new option --ff-one-only to control the merging strategy.
For one commit option works like -ff to avoid extra merge commit.
In other cases the option works like --no-ff to create merge commit for
complex features.

Signed-off-by: Ruslan Yakauleu <ruslan.yakauleu@gmail.com>
---
    merge: --ff-one-only to apply FF if commit is one
    
    A new option --ff-one-only to control the merging strategy. For one
    commit option works like -ff to avoid extra merge commit. In other cases
    the option works like --no-ff to create merge commit for complex
    features.
    
    Plenty of developers want to simplify merge history. We have two main
    merging strategies:
    
     * Fast-forward (--ff) - There we can lose merge commits for complex
       features and if we need to roll back some feature we can't revert
       just one commit.
     * Merge (--no-ff) - There we have extra merges for extra simple
       changes.
    
    Before, the user had to choose between --ff/--no-ff every time to have
    history without extra merges for simple changes and to use merges for
    complex features.
    
    Ways to use the new option: git merge --ff-one-only git config merge.ff
    one-only git config branch.master.mergeoptions --ff-one-only

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1599%2FQuAzI%2Fmerge%2Fff-one-only-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1599/QuAzI/merge/ff-one-only-v1
Pull-Request: https://github.com/git/git/pull/1599

 Documentation/config/merge.txt |  3 +++
 builtin/merge.c                | 18 +++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/Documentation/config/merge.txt b/Documentation/config/merge.txt
index 8851b6cedef..6cd5daa4d64 100644
--- a/Documentation/config/merge.txt
+++ b/Documentation/config/merge.txt
@@ -31,6 +31,9 @@ merge.ff::
 	a case (equivalent to giving the `--no-ff` option from the command
 	line). When set to `only`, only such fast-forward merges are
 	allowed (equivalent to giving the `--ff-only` option from the
+	command line). When set to `one-only`, fast-forward merge allowed
+	only for one commit, in other way extra merge commit should be
+	created (equivalent to giving the `--ff-one-only` option from the
 	command line).
 
 merge.verifySignatures::
diff --git a/builtin/merge.c b/builtin/merge.c
index d748d46e135..100f0021e56 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -110,7 +110,8 @@ static const char *pull_twohead, *pull_octopus;
 enum ff_type {
 	FF_NO,
 	FF_ALLOW,
-	FF_ONLY
+	FF_ONLY,
+	FF_ONE_ONLY
 };
 
 static enum ff_type fast_forward = FF_ALLOW;
@@ -258,6 +259,7 @@ static struct option builtin_merge_options[] = {
 		N_("edit message before committing")),
 	OPT_CLEANUP(&cleanup_arg),
 	OPT_SET_INT(0, "ff", &fast_forward, N_("allow fast-forward (default)"), FF_ALLOW),
+	OPT_SET_INT(0, "ff-one-only", &fast_forward, N_("allow fast-forward if only one commit"), FF_ONE_ONLY),
 	OPT_SET_INT_F(0, "ff-only", &fast_forward,
 		      N_("abort if fast-forward is not possible"),
 		      FF_ONLY, PARSE_OPT_NONEG),
@@ -631,6 +633,8 @@ static int git_merge_config(const char *k, const char *v,
 			fast_forward = boolval ? FF_ALLOW : FF_NO;
 		} else if (v && !strcmp(v, "only")) {
 			fast_forward = FF_ONLY;
+		} else if (v && !strcmp(v, "one-only")) {
+			fast_forward = FF_ONE_ONLY;
 		} /* do not barf on values from future versions of git */
 		return 0;
 	} else if (!strcmp(k, "merge.defaulttoupstream")) {
@@ -1527,6 +1531,18 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		free(list);
 	}
 
+	if (fast_forward == FF_ONE_ONLY) {
+		fast_forward = FF_NO;
+
+		/* check that we have one and only one commit to merge */
+		if (squash || ((!remoteheads->next &&
+				!common->next &&
+				oideq(&common->item->object.oid, &head_commit->object.oid)) &&
+				oideq(&remoteheads->item->parents->item->object.oid, &head_commit->object.oid))) {
+			fast_forward = FF_ALLOW;
+		}
+	}
+
 	update_ref("updating ORIG_HEAD", "ORIG_HEAD",
 		   &head_commit->object.oid, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 

base-commit: 2e8e77cbac8ac17f94eee2087187fa1718e38b14
-- 
gitgitgadget

             reply	other threads:[~2023-10-25  8:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-25  8:58 Ruslan Yakauleu via GitGitGadget [this message]
2023-10-25 16:27 ` [PATCH] merge: --ff-one-only to apply FF if commit is one Kristoffer Haugsbakk
2023-10-25 18:31   ` Ruslan Yakauleu
2023-10-25 19:04     ` Kristoffer Haugsbakk
     [not found]       ` <c37ba153-7239-49ff-b40f-370bc695986e@gmail.com>
2023-10-26 13:40         ` Ruslan Yakauleu
2023-10-30 20:01 ` Taylor Blau
2023-10-31  0:19   ` Junio C Hamano
2023-10-31  5:48     ` Ruslan Yakauleu
2023-10-31  6:07       ` Junio C Hamano
2023-10-31  8:32     ` Kristoffer Haugsbakk
2023-11-01  1:42       ` Junio C Hamano
2023-11-01  6:34         ` Ruslan Yakauleu
2023-11-01 10:09         ` Kristoffer Haugsbakk
2023-11-01 23:05           ` Junio C Hamano
2023-10-31  6:01   ` Ruslan Yakauleu

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=pull.1599.git.git.1698224280816.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=ruslan.yakauleu@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.