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

[PATCH] merge: allow using --no-ff and --ff-only at the same time

From
Miklos Vajna <vmiklos@suse.cz>
Date
Jul 1, 2013, 07:01 UTC
Message-ID
<20130701070143.GB17269@suse.cz>

1347483 (Teach 'git merge' and 'git pull' the option --ff-only, 2009-10-29) says this is not allowed, as they contradict each other.

However, --ff-only is about asserting the input of the merge, and --no-ff is about instructing merge to always create a merge commit, i.e. it makes sense to use these options together in some workflow, e.g. when branches are integrated by rebasing then merging, and the maintainer wants to be sure the branch is rebased.

Signed-off-by: Miklos Vajna <vmiklos@suse.cz>
---
 builtin/merge.c  | 12 ++++++++----
 t/t7600-merge.sh | 11 ++++++++---
 2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 2ebe732..7026ce0 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1162,9 +1162,6 @@ 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."));
-
 	if (!abort_current_merge) {
 		if (!argc) {
 			if (default_to_upstream)
@@ -1433,7 +1430,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		}
 	}
 
-	if (fast_forward_only)
+	/*
+	 * If --ff-only was used without --no-ff, or: --ff-only and --no-ff was
+	 * used at the same time, and this is not a fast-forward.
+	 */
+	if (fast_forward_only && (allow_fast_forward || remoteheads->next ||
+				common->next ||
+				hashcmp(common->item->object.sha1,
+					head_commit->object.sha1)))
 		die(_("Not possible to fast-forward, aborting."));
 
 	/* We are going to make a new commit. */
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 460d8eb..bf3d9b2 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -497,9 +497,14 @@ test_expect_success 'combining --squash and --no-ff is refused' '
 	test_must_fail git merge --no-ff --squash c1
 '
 
-test_expect_success 'combining --ff-only and --no-ff is refused' '
-	test_must_fail git merge --ff-only --no-ff c1 &&
-	test_must_fail git merge --no-ff --ff-only c1
+test_expect_success 'combining --ff-only and --no-ff (ff is possible)' '
+	git reset --hard c0 &&
+	git merge --ff-only --no-ff c1
+'
+
+test_expect_success 'combining --ff-only and --no-ff (ff is not possible)' '
+	git reset --hard c1 &&
+	test_must_fail git merge --ff-only --no-ff c2
 '
 
 test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
-- 
1.8.1.4
Next: Michael Haggerty
Message 1 of 12 in “merge: allow using --no-ff and --ff-only at the same time”
  1. merge: allow using --no-ff and --ff-only at the same timeMiklos Vajna, Jul 1, 2013
  2. Michael HaggertyJul 1, 2013
  3. Miklos VajnaJul 1, 2013
  4. Junio C HamanoJul 1, 2013
  5. Miklos VajnaJul 1, 2013
  6. Junio C HamanoJul 1, 2013
  7. merge: handle --ff/--no-ff/--ff-only as a tri-state optionMiklos Vajna, Jul 1, 2013
  8. Junio C HamanoJul 1, 2013
  9. Michael HaggertyJul 2, 2013
  10. merge: handle --ff/--no-ff/--ff-only as a tri-state optionMiklos Vajna, Jul 2, 2013
  11. Junio C HamanoJul 2, 2013
  12. Junio C HamanoJul 2, 2013

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.