From 4f21454b55f4237b7d0487ad5099c9edf4fc3967 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Oct 2016 16:10:40 -0400 Subject: [PATCH] merge-base: handle --fork-point without reflog The --fork-point option looks in the reflog to try to find where a derived branch forked from a base branch. However, if the reflog for the base branch is totally empty (as it commonly is right after cloning, which does not write a reflog entry), then our for_each_reflog call will not find any entries, and we will come up with no merge base, even though there may be one with the current tip of the base. We can fix this by just adding the current tip to our list of collected entries. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/merge-base.c | 3 +++ t/t6010-merge-base.sh | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/builtin/merge-base.c b/builtin/merge-base.c index c0d1822eb3..b572a37c26 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -173,6 +173,9 @@ 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_sha1(refname, sha1)) + add_one_commit(sha1, &revs); + for (i = 0; i < revs.nr; i++) revs.commit[i]->object.flags &= ~TMP_MARK; diff --git a/t/t6010-merge-base.sh b/t/t6010-merge-base.sh index 39b3238da2..de3bf0741c 100755 --- a/t/t6010-merge-base.sh +++ b/t/t6010-merge-base.sh @@ -258,6 +258,12 @@ test_expect_success 'using reflog to find the fork point' ' test_cmp expect3 actual ' +test_expect_success '--fork-point works with empty reflog' ' + git -c core.logallrefupdates=false branch no-reflog base && + git merge-base --fork-point no-reflog derived && + test_cmp expect3 actual +' + test_expect_success 'merge-base --octopus --all for complex tree' ' # Best common ancestor for JE, JAA and JDD is JC # JE