Skip to content

Commit

Permalink
rebase: disable fork-point by default
Browse files Browse the repository at this point in the history
It is possible that the upstream branch was at some point in the wrong
commit. The user might do 'git reset --hard' to restore that branch to
the right place, the wrong location is already in the reflog.

If the user tries to do a rebase without arguments the fork-point
feature will be used automatically and the wrong point in the reflog
used as one of the possible heads to check for bases.

This is especially bad when upstream was already in the same place as
the current branch (say upstream was fast-forwarded to topic by
mistake), in which case the rebase would silently ignore all the commits
and reset to upstream. The user would wonder what happened with his
commits, or worst; assume they were already in upstream.

This is a very bad situation we should try to avoid.

We cannot rely on the fact that the reflog will always contain only
good heads, therefore the fork-point should be disabled by default.

The fork-point feature is still useful, but it should be enabled
manually, only when the user knows what he is doing, and that all the
points in the reflog of the upstream branch are desirable.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
  • Loading branch information
felipec committed May 13, 2014
1 parent a7000a9 commit 0e59c7f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion git-rebase.sh
Expand Up @@ -67,7 +67,7 @@ verbose=
diffstat=
test "$(git config --bool rebase.stat)" = true && diffstat=t
autostash="$(git config --bool rebase.autostash || echo false)"
fork_point=auto
fork_point=
git_am_opt=
rebase_root=
force_rebase=
Expand Down
26 changes: 24 additions & 2 deletions t/t3400-rebase.sh
Expand Up @@ -134,7 +134,7 @@ test_expect_success 'fail when upstream arg is missing and not configured' '
test_must_fail git rebase
'

test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '
test_expect_success 'find common base in @{upstream}s reflog with --fork-point' '
git checkout -b default-base master &&
git checkout -b default topic &&
git config branch.default.remote . &&
Expand All @@ -146,7 +146,7 @@ test_expect_success 'default to common base in @{upstream}s reflog if no upstrea
git checkout default-base &&
git reset --hard HEAD^ &&
git checkout default &&
git rebase &&
git rebase --fork-point &&
git rev-parse --verify default-base >expect &&
git rev-parse default~1 >actual &&
test_cmp expect actual
Expand Down Expand Up @@ -215,4 +215,26 @@ test_expect_success 'rebase commit with an ancient timestamp' '
grep "author .* 34567 +0600$" actual
'

test_expect_success 'rebase fork-point works as expected' '
(
git init test &&
cd test &&
echo one > one &&
git add one &&
git commit -m one &&
git checkout -t -b topic &&
echo two > two &&
git add two &&
git commit -m two &&
git checkout master &&
git merge topic &&
git reset --hard @^ &&
git checkout topic &&
git rebase &&
echo two > expected &&
git log -1 --format=%s > actual &&
test_cmp expected actual
)
'

test_done

0 comments on commit 0e59c7f

Please sign in to comment.