]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2407-worktree-heads.sh
The third batch
[thirdparty/git.git] / t / t2407-worktree-heads.sh
CommitLineData
31ad6b61
DS
1#!/bin/sh
2
3test_description='test operations trying to overwrite refs at worktree HEAD'
4
5TEST_PASSES_SANITIZE_LEAK=true
6. ./test-lib.sh
7
8test_expect_success 'setup' '
9 test_commit init &&
31ad6b61
DS
10
11 for i in 1 2 3 4
12 do
1bec4d1d
DS
13 git checkout -b conflict-$i &&
14 echo "not I" >$i.t &&
15 git add $i.t &&
16 git commit -m "will conflict" &&
17
18 git checkout - &&
31ad6b61
DS
19 test_commit $i &&
20 git branch wt-$i &&
1bec4d1d 21 git branch fake-$i &&
31ad6b61 22 git worktree add wt-$i wt-$i || return 1
12d47e3b
DS
23 done &&
24
25 # Create a server that updates each branch by one commit
26 git init server &&
27 test_commit -C server initial &&
28 git remote add server ./server &&
29 for i in 1 2 3 4
30 do
31 git -C server checkout -b wt-$i &&
32 test_commit -C server A-$i || return 1
33 done &&
34 for i in 1 2
35 do
36 git -C server checkout -b fake-$i &&
37 test_commit -C server f-$i || return 1
31ad6b61
DS
38 done
39'
40
41test_expect_success 'refuse to overwrite: checked out in worktree' '
42 for i in 1 2 3 4
43 do
308cbaa0 44 test_must_fail git branch -f wt-$i HEAD 2>err &&
b489b9d9
DS
45 grep "cannot force update the branch" err &&
46
308cbaa0 47 test_must_fail git branch -D wt-$i 2>err &&
12b99928 48 grep "cannot delete branch" err || return 1
31ad6b61
DS
49 done
50'
51
1bec4d1d
DS
52test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in bisect' '
53 test_when_finished git -C wt-4 bisect reset &&
d2ba271a 54
1bec4d1d
DS
55 # Set up a bisect so HEAD no longer points to wt-4.
56 git -C wt-4 bisect start &&
57 git -C wt-4 bisect bad wt-4 &&
58 git -C wt-4 bisect good wt-1 &&
d2ba271a 59
1bec4d1d 60 test_must_fail git branch -f wt-4 HEAD 2>err &&
4970bede 61 grep "cannot force update the branch '\''wt-4'\'' used by worktree at.*wt-4" err
d2ba271a
DS
62'
63
18ea5958
DS
64test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (apply)' '
65 test_when_finished git -C wt-2 rebase --abort &&
66
67 # This will fail part-way through due to a conflict.
68 test_must_fail git -C wt-2 rebase --apply conflict-2 &&
69
70 test_must_fail git branch -f wt-2 HEAD 2>err &&
4970bede 71 grep "cannot force update the branch '\''wt-2'\'' used by worktree at.*wt-2" err
18ea5958
DS
72'
73
74test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (merge)' '
1bec4d1d 75 test_when_finished git -C wt-2 rebase --abort &&
d2ba271a 76
1bec4d1d
DS
77 # This will fail part-way through due to a conflict.
78 test_must_fail git -C wt-2 rebase conflict-2 &&
d2ba271a 79
1bec4d1d 80 test_must_fail git branch -f wt-2 HEAD 2>err &&
4970bede 81 grep "cannot force update the branch '\''wt-2'\'' used by worktree at.*wt-2" err
d2ba271a
DS
82'
83
89fc0b53
DS
84test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase with --update-refs' '
85 test_when_finished git -C wt-3 rebase --abort &&
aa7f2fd1 86
89fc0b53
DS
87 git branch -f can-be-updated wt-3 &&
88 test_must_fail git -C wt-3 rebase --update-refs conflict-3 &&
aa7f2fd1
DS
89
90 for i in 3 4
91 do
89fc0b53 92 test_must_fail git branch -f can-be-updated HEAD 2>err &&
4970bede 93 grep "cannot force update the branch '\''can-be-updated'\'' used by worktree at.*wt-3" err ||
aa7f2fd1
DS
94 return 1
95 done
96'
97
12d47e3b
DS
98test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: checked out' '
99 test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err &&
100 grep "refusing to fetch into branch '\''refs/heads/wt-3'\''" err &&
101
102 # General fetch into refs/heads/ will fail on first ref,
103 # so use a generic error message check.
104 test_must_fail git fetch server +refs/heads/*:refs/heads/* 2>err &&
105 grep "refusing to fetch into branch" err
106'
107
108test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in bisect' '
1bec4d1d 109 test_when_finished git -C wt-4 bisect reset &&
12d47e3b 110
1bec4d1d
DS
111 # Set up a bisect so HEAD no longer points to wt-4.
112 git -C wt-4 bisect start &&
113 git -C wt-4 bisect bad wt-4 &&
114 git -C wt-4 bisect good wt-1 &&
12d47e3b 115
1bec4d1d 116 test_must_fail git fetch server +refs/heads/wt-4:refs/heads/wt-4 2>err &&
12d47e3b
DS
117 grep "refusing to fetch into branch" err
118'
119
120test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in rebase' '
1bec4d1d 121 test_when_finished git -C wt-3 rebase --abort &&
12d47e3b 122
1bec4d1d
DS
123 # This will fail part-way through due to a conflict.
124 test_must_fail git -C wt-3 rebase conflict-3 &&
12d47e3b 125
1bec4d1d 126 test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err &&
12d47e3b
DS
127 grep "refusing to fetch into branch" err
128'
129
4b6e18f5
DS
130test_expect_success 'refuse to overwrite when in error states' '
131 test_when_finished rm -rf .git/worktrees/wt-*/rebase-merge &&
132 test_when_finished rm -rf .git/worktrees/wt-*/BISECT_* &&
133
134 # Both branches are currently under rebase.
135 mkdir -p .git/worktrees/wt-3/rebase-merge &&
136 touch .git/worktrees/wt-3/rebase-merge/interactive &&
137 echo refs/heads/fake-1 >.git/worktrees/wt-3/rebase-merge/head-name &&
138 echo refs/heads/fake-2 >.git/worktrees/wt-3/rebase-merge/onto &&
139 mkdir -p .git/worktrees/wt-4/rebase-merge &&
140 touch .git/worktrees/wt-4/rebase-merge/interactive &&
141 echo refs/heads/fake-2 >.git/worktrees/wt-4/rebase-merge/head-name &&
142 echo refs/heads/fake-1 >.git/worktrees/wt-4/rebase-merge/onto &&
143
144 # Both branches are currently under bisect.
145 touch .git/worktrees/wt-4/BISECT_LOG &&
146 echo refs/heads/fake-2 >.git/worktrees/wt-4/BISECT_START &&
147 touch .git/worktrees/wt-1/BISECT_LOG &&
148 echo refs/heads/fake-1 >.git/worktrees/wt-1/BISECT_START &&
149
150 for i in 1 2
151 do
152 test_must_fail git branch -f fake-$i HEAD 2>err &&
4970bede 153 grep "cannot force update the branch '\''fake-$i'\'' used by worktree at" err ||
4b6e18f5
DS
154 return 1
155 done
156'
157
900b50c2
DS
158. "$TEST_DIRECTORY"/lib-rebase.sh
159
160test_expect_success !SANITIZE_LEAK 'refuse to overwrite during rebase with --update-refs' '
161 git commit --fixup HEAD~2 --allow-empty &&
162 (
163 set_cat_todo_editor &&
164 test_must_fail git rebase -i --update-refs HEAD~3 >todo &&
165 ! grep "update-refs" todo
166 ) &&
167 git branch -f allow-update HEAD~2 &&
168 (
169 set_cat_todo_editor &&
170 test_must_fail git rebase -i --update-refs HEAD~3 >todo &&
171 grep "update-ref refs/heads/allow-update" todo
172 )
173'
174
175# This must be the last test in this file
176test_expect_success '$EDITOR and friends are unchanged' '
177 test_editor_unchanged
178'
179
31ad6b61 180test_done