Merge branch 'jc/rebase-detach-fix'
"git rebase $base $non_branch_commit", when $base is an ancestor or the $non_branch_commit, modified the current branch, which has been corrected. * jc/rebase-detach-fix: rebase: set REF_HEAD_DETACH in checkout_up_to_date() rebase: use test_commit helper in setup
This commit is contained in:
commit
f818536749
@ -829,6 +829,8 @@ static int checkout_up_to_date(struct rebase_options *options)
|
||||
ropts.oid = &options->orig_head;
|
||||
ropts.branch = options->head_name;
|
||||
ropts.flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
|
||||
if (!ropts.branch)
|
||||
ropts.flags |= RESET_HEAD_DETACH;
|
||||
ropts.head_msg = buf.buf;
|
||||
if (reset_head(the_repository, &ropts) < 0)
|
||||
ret = error(_("could not switch to %s"), options->switch_to);
|
||||
|
@ -18,10 +18,7 @@ GIT_AUTHOR_EMAIL=bogus@email@address
|
||||
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
|
||||
|
||||
test_expect_success 'prepare repository with topic branches' '
|
||||
git config core.logAllRefUpdates true &&
|
||||
echo First >A &&
|
||||
git update-index --add A &&
|
||||
git commit -m "Add A." &&
|
||||
test_commit "Add A." A First First &&
|
||||
git checkout -b force-3way &&
|
||||
echo Dummy >Y &&
|
||||
git update-index --add Y &&
|
||||
@ -32,9 +29,7 @@ test_expect_success 'prepare repository with topic branches' '
|
||||
git mv A D/A &&
|
||||
git commit -m "Move A." &&
|
||||
git checkout -b my-topic-branch main &&
|
||||
echo Second >B &&
|
||||
git update-index --add B &&
|
||||
git commit -m "Add B." &&
|
||||
test_commit "Add B." B Second Second &&
|
||||
git checkout -f main &&
|
||||
echo Third >>A &&
|
||||
git update-index A &&
|
||||
@ -399,6 +394,15 @@ test_expect_success 'switch to branch not checked out' '
|
||||
git rebase main other
|
||||
'
|
||||
|
||||
test_expect_success 'switch to non-branch detaches HEAD' '
|
||||
git checkout main &&
|
||||
old_main=$(git rev-parse HEAD) &&
|
||||
git rebase First Second^0 &&
|
||||
test_cmp_rev HEAD Second &&
|
||||
test_cmp_rev main $old_main &&
|
||||
test_must_fail git symbolic-ref HEAD
|
||||
'
|
||||
|
||||
test_expect_success 'refuse to switch to branch checked out elsewhere' '
|
||||
git checkout main &&
|
||||
git worktree add wt &&
|
||||
|
Loading…
Reference in New Issue
Block a user