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.oid = &options->orig_head;
|
||||||
ropts.branch = options->head_name;
|
ropts.branch = options->head_name;
|
||||||
ropts.flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
|
ropts.flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
|
||||||
|
if (!ropts.branch)
|
||||||
|
ropts.flags |= RESET_HEAD_DETACH;
|
||||||
ropts.head_msg = buf.buf;
|
ropts.head_msg = buf.buf;
|
||||||
if (reset_head(the_repository, &ropts) < 0)
|
if (reset_head(the_repository, &ropts) < 0)
|
||||||
ret = error(_("could not switch to %s"), options->switch_to);
|
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
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
|
||||||
|
|
||||||
test_expect_success 'prepare repository with topic branches' '
|
test_expect_success 'prepare repository with topic branches' '
|
||||||
git config core.logAllRefUpdates true &&
|
test_commit "Add A." A First First &&
|
||||||
echo First >A &&
|
|
||||||
git update-index --add A &&
|
|
||||||
git commit -m "Add A." &&
|
|
||||||
git checkout -b force-3way &&
|
git checkout -b force-3way &&
|
||||||
echo Dummy >Y &&
|
echo Dummy >Y &&
|
||||||
git update-index --add Y &&
|
git update-index --add Y &&
|
||||||
@ -32,9 +29,7 @@ test_expect_success 'prepare repository with topic branches' '
|
|||||||
git mv A D/A &&
|
git mv A D/A &&
|
||||||
git commit -m "Move A." &&
|
git commit -m "Move A." &&
|
||||||
git checkout -b my-topic-branch main &&
|
git checkout -b my-topic-branch main &&
|
||||||
echo Second >B &&
|
test_commit "Add B." B Second Second &&
|
||||||
git update-index --add B &&
|
|
||||||
git commit -m "Add B." &&
|
|
||||||
git checkout -f main &&
|
git checkout -f main &&
|
||||||
echo Third >>A &&
|
echo Third >>A &&
|
||||||
git update-index A &&
|
git update-index A &&
|
||||||
@ -399,6 +394,15 @@ test_expect_success 'switch to branch not checked out' '
|
|||||||
git rebase main other
|
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' '
|
test_expect_success 'refuse to switch to branch checked out elsewhere' '
|
||||||
git checkout main &&
|
git checkout main &&
|
||||||
git worktree add wt &&
|
git worktree add wt &&
|
||||||
|
Loading…
Reference in New Issue
Block a user