diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-10-23 16:47:32 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-10-29 13:06:08 -0700 |
commit | d96855ff517560650c62eca51a8bb78263f6a3ef (patch) | |
tree | 6fb9e42186c21d95b9c86af87eb8f8ed7a80d028 /t/t6010-merge-base.sh | |
parent | 16e57aec7f672fabe38fa0e4d39252eb9c7a1563 (diff) | |
download | git-d96855ff517560650c62eca51a8bb78263f6a3ef.tar.gz git-d96855ff517560650c62eca51a8bb78263f6a3ef.tar.xz |
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 <martinvonz@gmail.com>
Helped-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t6010-merge-base.sh')
-rwxr-xr-x | t/t6010-merge-base.sh | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/t/t6010-merge-base.sh b/t/t6010-merge-base.sh index f80bba871..30a68335b 100755 --- a/t/t6010-merge-base.sh +++ b/t/t6010-merge-base.sh @@ -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 +' + test_done |