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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 12, 2016 at 16:10 UTC
4f21454b55f4237b7d0487ad5099c9edf4fc3967
2 files changed
+9
builtin/merge-base.c
+3
@@ -173,6 +173,9 @@ static int handle_fork_point(int argc, const char **argv)
173
revs.initial = 1;
174
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
175
176
+ if (!revs.nr && !get_sha1(refname, sha1))
177
+ add_one_commit(sha1, &revs);
178
+
179
for (i = 0; i < revs.nr; i++)
180
revs.commit[i]->object.flags &= ~TMP_MARK;
181
t/t6010-merge-base.sh
+6
@@ -258,6 +258,12 @@ test_expect_success 'using reflog to find the fork point' '
258
test_cmp expect3 actual
259
'
260
261
+test_expect_success '--fork-point works with empty reflog' '
262
+ git -c core.logallrefupdates=false branch no-reflog base &&
263
+ git merge-base --fork-point no-reflog derived &&
264
+ test_cmp expect3 actual
265
+'
266
+
267
test_expect_success 'merge-base --octopus --all for complex tree' '
268
# Best common ancestor for JE, JAA and JDD is JC
269
# JE