path: root/t/
diff options
authorJunio C Hamano <>2013-10-23 23:47:32 (GMT)
committerJunio C Hamano <>2013-10-29 20:06:08 (GMT)
commitd96855ff517560650c62eca51a8bb78263f6a3ef (patch)
tree6fb9e42186c21d95b9c86af87eb8f8ed7a80d028 /t/
parent16e57aec7f672fabe38fa0e4d39252eb9c7a1563 (diff)
merge-base: teach "--fork-point" mode
The "git pull --rebase" command computes the fork point of the branch being rebased using the reflog entries of the "base" branch (typically a remote-tracking branch) the branch's work was based on, in order to cope with the case in which the "base" branch has been rewound and rebuilt. For example, if the history looked like this: o---B1 / ---o---o---B2--o---o---o---Base \ B3 \ Derived where the current tip of the "base" branch is at Base, but earlier fetch observed that its tip used to be B3 and then B2 and then B1 before getting to the current commit, and the branch being rebased on top of the latest "base" is based on commit B3, it tries to find B3 by going through the output of "git rev-list --reflog base" (i.e. Base, B1, B2, B3) until it finds a commit that is an ancestor of the current tip "Derived". Internally, we have get_merge_bases_many() that can compute this with one-go. We would want a merge-base between Derived and a fictitious merge commit that would result by merging all the historical tips of "base". When such a commit exist, we should get a single result, which exactly match one of the reflog entries of "base". Teach "git merge-base" a new mode, "--fork-point", to compute exactly that. Helped-by: Martin von Zweigbergk <> Helped-by: John Keeping <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 't/')
1 files changed, 28 insertions, 0 deletions
diff --git a/t/ b/t/
index f80bba8..30a6833 100755
--- a/t/
+++ b/t/
@@ -230,4 +230,32 @@ test_expect_success 'criss-cross merge-base for octopus-step' '
test_cmp expected.sorted actual.sorted
+test_expect_success 'using reflog to find the fork point' '
+ git reset --hard &&
+ git checkout -b base $E &&
+ (
+ for count in 1 2 3
+ do
+ git commit --allow-empty -m "Base commit #$count" &&
+ git rev-parse HEAD >expect$count &&
+ git checkout -B derived &&
+ git commit --allow-empty -m "Derived #$count" &&
+ git rev-parse HEAD >derived$count &&
+ git checkout -B base $E || exit 1
+ done
+ for count in 1 2 3
+ do
+ git merge-base --fork-point base $(cat derived$count) >actual &&
+ test_cmp expect$count actual || exit 1
+ done
+ ) &&
+ # check that we correctly default to HEAD
+ git checkout derived &&
+ git merge-base --fork-point base >actual &&
+ test_cmp expect3 actual