Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t2407-worktree-heads.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t2407-worktree-heads.sh` 179 lines ยท 5587 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='test operations trying to overwrite refs at worktree HEAD' 4 5 . ./test-lib.sh 6 7 test_expect_success 'setup' ' 8 test_commit init && 9 10 for i in 1 2 3 4 11 do 12 git checkout -b conflict-$i && 13 echo "not I" >$i.t && 14 git add $i.t && 15 git commit -m "will conflict" && 16 17 git checkout - && 18 test_commit $i && 19 git branch wt-$i && 20 git branch fake-$i && 21 git worktree add wt-$i wt-$i || return 1 22 done && 23 24 # Create a server that updates each branch by one commit 25 git init server && 26 test_commit -C server initial && 27 git remote add server ./server && 28 for i in 1 2 3 4 29 do 30 git -C server checkout -b wt-$i && 31 test_commit -C server A-$i || return 1 32 done && 33 for i in 1 2 34 do 35 git -C server checkout -b fake-$i && 36 test_commit -C server f-$i || return 1 37 done 38 ' 39 40 test_expect_success 'refuse to overwrite: checked out in worktree' ' 41 for i in 1 2 3 4 42 do 43 test_must_fail git branch -f wt-$i HEAD 2>err && 44 test_grep "cannot force update the branch" err && 45 46 test_must_fail git branch -D wt-$i 2>err && 47 test_grep "cannot delete branch" err || return 1 48 done 49 ' 50 51 test_expect_success 'refuse to overwrite: worktree in bisect' ' 52 test_when_finished git -C wt-4 bisect reset && 53 54 # Set up a bisect so HEAD no longer points to wt-4. 55 git -C wt-4 bisect start && 56 git -C wt-4 bisect bad wt-4 && 57 git -C wt-4 bisect good wt-1 && 58 59 test_must_fail git branch -f wt-4 HEAD 2>err && 60 test_grep "cannot force update the branch '\''wt-4'\'' used by worktree at.*wt-4" err 61 ' 62 63 test_expect_success 'refuse to overwrite: worktree in rebase (apply)' ' 64 test_when_finished git -C wt-2 rebase --abort && 65 66 # This will fail part-way through due to a conflict. 67 test_must_fail git -C wt-2 rebase --apply conflict-2 && 68 69 test_must_fail git branch -f wt-2 HEAD 2>err && 70 test_grep "cannot force update the branch '\''wt-2'\'' used by worktree at.*wt-2" err 71 ' 72 73 test_expect_success 'refuse to overwrite: worktree in rebase (merge)' ' 74 test_when_finished git -C wt-2 rebase --abort && 75 76 # This will fail part-way through due to a conflict. 77 test_must_fail git -C wt-2 rebase conflict-2 && 78 79 test_must_fail git branch -f wt-2 HEAD 2>err && 80 test_grep "cannot force update the branch '\''wt-2'\'' used by worktree at.*wt-2" err 81 ' 82 83 test_expect_success 'refuse to overwrite: worktree in rebase with --update-refs' ' 84 test_when_finished git -C wt-3 rebase --abort && 85 86 git branch -f can-be-updated wt-3 && 87 test_must_fail git -C wt-3 rebase --update-refs conflict-3 && 88 89 for i in 3 4 90 do 91 test_must_fail git branch -f can-be-updated HEAD 2>err && 92 test_grep "cannot force update the branch '\''can-be-updated'\'' used by worktree at.*wt-3" err || 93 return 1 94 done 95 ' 96 97 test_expect_success 'refuse to fetch over ref: checked out' ' 98 test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err && 99 test_grep "refusing to fetch into branch '\''refs/heads/wt-3'\''" err && 100 101 # General fetch into refs/heads/ will fail on first ref, 102 # so use a generic error message check. 103 test_must_fail git fetch server +refs/heads/*:refs/heads/* 2>err && 104 test_grep "refusing to fetch into branch" err 105 ' 106 107 test_expect_success 'refuse to fetch over ref: worktree in bisect' ' 108 test_when_finished git -C wt-4 bisect reset && 109 110 # Set up a bisect so HEAD no longer points to wt-4. 111 git -C wt-4 bisect start && 112 git -C wt-4 bisect bad wt-4 && 113 git -C wt-4 bisect good wt-1 && 114 115 test_must_fail git fetch server +refs/heads/wt-4:refs/heads/wt-4 2>err && 116 test_grep "refusing to fetch into branch" err 117 ' 118 119 test_expect_success 'refuse to fetch over ref: worktree in rebase' ' 120 test_when_finished git -C wt-3 rebase --abort && 121 122 # This will fail part-way through due to a conflict. 123 test_must_fail git -C wt-3 rebase conflict-3 && 124 125 test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err && 126 test_grep "refusing to fetch into branch" err 127 ' 128 129 test_expect_success 'refuse to overwrite when in error states' ' 130 test_when_finished rm -rf .git/worktrees/wt-*/rebase-merge && 131 test_when_finished rm -rf .git/worktrees/wt-*/BISECT_* && 132 133 # Both branches are currently under rebase. 134 mkdir -p .git/worktrees/wt-3/rebase-merge && 135 touch .git/worktrees/wt-3/rebase-merge/interactive && 136 echo refs/heads/fake-1 >.git/worktrees/wt-3/rebase-merge/head-name && 137 echo refs/heads/fake-2 >.git/worktrees/wt-3/rebase-merge/onto && 138 mkdir -p .git/worktrees/wt-4/rebase-merge && 139 touch .git/worktrees/wt-4/rebase-merge/interactive && 140 echo refs/heads/fake-2 >.git/worktrees/wt-4/rebase-merge/head-name && 141 echo refs/heads/fake-1 >.git/worktrees/wt-4/rebase-merge/onto && 142 143 # Both branches are currently under bisect. 144 touch .git/worktrees/wt-4/BISECT_LOG && 145 echo refs/heads/fake-2 >.git/worktrees/wt-4/BISECT_START && 146 touch .git/worktrees/wt-1/BISECT_LOG && 147 echo refs/heads/fake-1 >.git/worktrees/wt-1/BISECT_START && 148 149 for i in 1 2 150 do 151 test_must_fail git branch -f fake-$i HEAD 2>err && 152 test_grep "cannot force update the branch '\''fake-$i'\'' used by worktree at" err || 153 return 1 154 done 155 ' 156 157 . "$TEST_DIRECTORY"/lib-rebase.sh 158 159 test_expect_success 'refuse to overwrite during rebase with --update-refs' ' 160 git commit --fixup HEAD~2 --allow-empty && 161 ( 162 set_cat_todo_editor && 163 test_must_fail git rebase -i --update-refs HEAD~3 >todo && 164 test_grep ! "update-refs" todo 165 ) && 166 git branch -f allow-update HEAD~2 && 167 ( 168 set_cat_todo_editor && 169 test_must_fail git rebase -i --update-refs HEAD~3 >todo && 170 test_grep "update-ref refs/heads/allow-update" todo 171 ) 172 ' 173 174 # This must be the last test in this file 175 test_expect_success '$EDITOR and friends are unchanged' ' 176 test_editor_unchanged 177 ' 178 179 test_done