diff options
author | Derrick Stolee <derrickstolee@github.com> | 2022-07-19 18:33:35 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-07-19 19:49:03 (GMT) |
commit | aa7f2fd150e7817de6c781dc5911d6c85f334324 (patch) | |
tree | 0de1b907391368987b31a20a9efd7c372eb8a711 /t | |
parent | 18ea59582778bd0b80fc643bc4e2981275d2300d (diff) | |
download | git-aa7f2fd150e7817de6c781dc5911d6c85f334324.zip git-aa7f2fd150e7817de6c781dc5911d6c85f334324.tar.gz git-aa7f2fd150e7817de6c781dc5911d6c85f334324.tar.bz2 |
branch: consider refs under 'update-refs'
The branch_checked_out() helper helps commands like 'git branch' and
'git fetch' from overwriting refs that are currently checked out in
other worktrees.
A future update to 'git rebase' will introduce a new '--update-refs'
option which will update the local refs that point to commits that are
being rebased. To avoid collisions as the rebase completes, we want to
make the future data store for these refs to be considered by
branch_checked_out().
The data store is a plaintext file inside the 'rebase-merge' directory
for that worktree. The file lists refnames followed by two OIDs, each on
separate lines. The OIDs will be used to store the original values of
the refs and the to-be-written values as the rebase progresses, but can
be ignored at the moment.
Create a new sequencer_get_update_refs_state() method that parses this
file and populates a struct string_list with the ref-OID pairs. We can
then use this list to add to the current_checked_out_branches strmap
used by branch_checked_out().
To properly navigate to the rebase directory for a given worktree,
extract the static strbuf_worktree_gitdir() method to a public API
method.
We can test that this works without having Git write this file by
artificially creating one in our test script, at least until 'git rebase
--update-refs' is implemented and we can use it directly.
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-x | t/t2407-worktree-heads.sh | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/t/t2407-worktree-heads.sh b/t/t2407-worktree-heads.sh index a67ce5f..97f5c87 100755 --- a/t/t2407-worktree-heads.sh +++ b/t/t2407-worktree-heads.sh @@ -81,6 +81,29 @@ 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 && + + 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 + + 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 || + return 1 + done +' + test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: checked out' ' test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err && grep "refusing to fetch into branch '\''refs/heads/wt-3'\''" err && |