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

[PATCH 3/3] merge-base: find fork-point outside partial reflog

From
Michael J Gruber <git@grubix.eu>
Date
Sep 14, 2017, 13:15 UTC
Message-ID
<f16c671b268432199a0b2e0d22bb1b786a44bb2a.1505394278.git.git@grubix.eu>
In-Reply-To
<68633b20-9e2b-ae23-2ede-8728283250f0@grubix.eu>

In fork-point mode, merge-base adds the commit at refname to a list of candidates to walk from only when the reflog is empty. Therefore, it fails to find merge bases that are descendants of the most recent reflog entry.

Add the commit at the tip unconditionally so that a merge base on the history of refname is found in any case, independent of the state of the reflog.

Signed-off-by: Michael J Gruber <git@grubix.eu>
---
 builtin/merge-base.c  | 2 +-
 t/t6010-merge-base.sh | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 926a7615ea..b5b4cf7eac 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -174,7 +174,7 @@ static int handle_fork_point(int argc, const char **argv)
 	revs.initial = 1;
 	for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
 
-	if (!revs.nr && !get_oid(refname, &oid))
+	if (!get_oid(refname, &oid))
 		add_one_commit(&oid, &revs);
 
 	for (i = 0; i < revs.nr; i++)
diff --git a/t/t6010-merge-base.sh b/t/t6010-merge-base.sh
index 850463d4f2..78342896c7 100755
--- a/t/t6010-merge-base.sh
+++ b/t/t6010-merge-base.sh
@@ -275,6 +275,14 @@ test_expect_success '--fork-point works with merge-base outside reflog' '
 	test_cmp expect actual
 '
 
+test_expect_success '--fork-point works with merge-base outside partial reflog' '
+	git -c core.logallrefupdates=true branch partial-reflog base &&
+	git rev-parse no-reflog >.git/refs/heads/partial-reflog &&
+	git rev-parse no-reflog >expect &&
+	git merge-base --fork-point partial-reflog no-reflog >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'merge-base --octopus --all for complex tree' '
 	# Best common ancestor for JE, JAA and JDD is JC
 	#             JE
-- 
2.14.1.712.gda4591c8a2
Previous: Junio C HamanoNext: Jeff King
Message 20 of 25 in “RE: merge-base not working as expected when base is ahead”
  1. Ekelhart JakobSep 13, 2017
  2. Michael J GruberSep 14, 2017
  3. 0/3 merge-base --fork-point fixesMichael J Gruber, Sep 14, 2017
  4. Johannes SchindelinSep 14, 2017
  5. Jeff KingSep 14, 2017
  6. 2/3 merge-base: return fork-point outside reflogMichael J Gruber, Sep 14, 2017
  7. Junio C HamanoSep 15, 2017
  8. Phillip WoodSep 15, 2017
  9. Michael J GruberSep 15, 2017
  10. Junio C HamanoSep 15, 2017
  11. Junio C HamanoSep 21, 2017
  12. Michael J GruberSep 21, 2017
  13. Junio C HamanoSep 22, 2017
  14. Michael J GruberSep 22, 2017
  15. Junio C HamanoSep 22, 2017
  16. Junio C HamanoOct 3, 2017
  17. Ekelhart JakobNov 8, 2017
  18. Michael J GruberNov 8, 2017
  19. Junio C HamanoNov 9, 2017
  20. 3/3 merge-base: find fork-point outside partial reflogMichael J Gruber, Sep 14, 2017
  21. Jeff KingSep 14, 2017
  22. 1/3 t6010: test actual test outputMichael J Gruber, Sep 14, 2017
  23. Jeff KingSep 14, 2017
  24. Michael J GruberSep 15, 2017
  25. Jeff KingSep 15, 2017

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.