From 89fc0b53fdb4ea2f9581ea728577f4d2a4947672 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Tue, 19 Jul 2022 18:33:40 +0000 Subject: rebase: update refs from 'update-ref' commands The previous change introduced the 'git rebase --update-refs' option which added 'update-ref ' commands to the todo list of an interactive rebase. Teach Git to record the HEAD position when reaching these 'update-ref' commands. The ref/before/after triple is stored in the $GIT_DIR/rebase-merge/update-refs file. A previous change parsed this file to avoid having other processes updating the refs in that file while the rebase is in progress. Not only do we update the file when the sequencer reaches these 'update-ref' commands, we then update the refs themselves at the end of the rebase sequence. If the rebase is aborted before this final step, then the refs are not updated. The 'before' value is used to ensure that we do not accidentally obliterate a ref that was updated concurrently (say, by an older version of Git or a third-party tool). Now that the 'git rebase --update-refs' command is implemented to write to the update-refs file, we can remove the fake construction of the update-refs file from a test in t2407-worktree-heads.sh. Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- t/t2407-worktree-heads.sh | 21 ++++++--------------- t/t3404-rebase-interactive.sh | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) (limited to 't') diff --git a/t/t2407-worktree-heads.sh b/t/t2407-worktree-heads.sh index 8a03f14df8..50815acd3e 100755 --- a/t/t2407-worktree-heads.sh +++ b/t/t2407-worktree-heads.sh @@ -81,25 +81,16 @@ test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (mer grep "cannot force update the branch '\''wt-2'\'' checked out at.*wt-2" err ' -test_expect_success 'refuse to overwrite: worktree in rebase with --update-refs' ' - test_when_finished rm -rf .git/worktrees/wt-3/rebase-merge && - - mkdir -p .git/worktrees/wt-3/rebase-merge && - touch .git/worktrees/wt-3/rebase-merge/interactive && +test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase with --update-refs' ' + test_when_finished git -C wt-3 rebase --abort && - cat >.git/worktrees/wt-3/rebase-merge/update-refs <<-EOF && - refs/heads/fake-3 - $(git rev-parse HEAD~1) - $(git rev-parse HEAD) - refs/heads/fake-4 - $(git rev-parse HEAD) - $(git rev-parse HEAD) - EOF + git branch -f can-be-updated wt-3 && + test_must_fail git -C wt-3 rebase --update-refs conflict-3 && for i in 3 4 do - test_must_fail git branch -f fake-$i HEAD 2>err && - grep "cannot force update the branch '\''fake-$i'\'' checked out at.*wt-3" err || + test_must_fail git branch -f can-be-updated HEAD 2>err && + grep "cannot force update the branch '\''can-be-updated'\'' checked out at.*wt-3" err || return 1 done ' diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 75c0b90fae..2fffcf5d5f 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1817,6 +1817,23 @@ test_expect_success '--update-refs adds commands with --rebase-merges' ' ) ' +test_expect_success '--update-refs updates refs correctly' ' + git checkout -B update-refs no-conflict-branch && + git branch -f base HEAD~4 && + git branch -f first HEAD~3 && + git branch -f second HEAD~3 && + git branch -f third HEAD~1 && + test_commit extra2 fileX && + git commit --amend --fixup=L && + + git rebase -i --autosquash --update-refs primary && + + test_cmp_rev HEAD~3 refs/heads/first && + test_cmp_rev HEAD~3 refs/heads/second && + test_cmp_rev HEAD~1 refs/heads/third && + test_cmp_rev HEAD refs/heads/no-conflict-branch +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged -- cgit v1.3