commit-reach(paint_down_to_common): plug two memory leaks
[git.git] / t / t2407-worktree-heads.sh
blobf6835c91dcc49cfeb23881fe0ef7a96629bfb2e6
1 #!/bin/sh
3 test_description='test operations trying to overwrite refs at worktree HEAD'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup' '
9 test_commit init &&
11 for i in 1 2 3 4
13 git checkout -b conflict-$i &&
14 echo "not I" >$i.t &&
15 git add $i.t &&
16 git commit -m "will conflict" &&
18 git checkout - &&
19 test_commit $i &&
20 git branch wt-$i &&
21 git branch fake-$i &&
22 git worktree add wt-$i wt-$i || return 1
23 done &&
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
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
36 git -C server checkout -b fake-$i &&
37 test_commit -C server f-$i || return 1
38 done
41 test_expect_success 'refuse to overwrite: checked out in worktree' '
42 for i in 1 2 3 4
44 test_must_fail git branch -f wt-$i HEAD 2>err &&
45 grep "cannot force update the branch" err &&
47 test_must_fail git branch -D wt-$i 2>err &&
48 grep "cannot delete branch" err || return 1
49 done
52 test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in bisect' '
53 test_when_finished git -C wt-4 bisect reset &&
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 &&
60 test_must_fail git branch -f wt-4 HEAD 2>err &&
61 grep "cannot force update the branch '\''wt-4'\'' used by worktree at.*wt-4" err
64 test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (apply)' '
65 test_when_finished git -C wt-2 rebase --abort &&
67 # This will fail part-way through due to a conflict.
68 test_must_fail git -C wt-2 rebase --apply conflict-2 &&
70 test_must_fail git branch -f wt-2 HEAD 2>err &&
71 grep "cannot force update the branch '\''wt-2'\'' used by worktree at.*wt-2" err
74 test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (merge)' '
75 test_when_finished git -C wt-2 rebase --abort &&
77 # This will fail part-way through due to a conflict.
78 test_must_fail git -C wt-2 rebase conflict-2 &&
80 test_must_fail git branch -f wt-2 HEAD 2>err &&
81 grep "cannot force update the branch '\''wt-2'\'' used by worktree at.*wt-2" err
84 test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase with --update-refs' '
85 test_when_finished git -C wt-3 rebase --abort &&
87 git branch -f can-be-updated wt-3 &&
88 test_must_fail git -C wt-3 rebase --update-refs conflict-3 &&
90 for i in 3 4
92 test_must_fail git branch -f can-be-updated HEAD 2>err &&
93 grep "cannot force update the branch '\''can-be-updated'\'' used by worktree at.*wt-3" err ||
94 return 1
95 done
98 test_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 &&
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
108 test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in bisect' '
109 test_when_finished git -C wt-4 bisect reset &&
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 &&
116 test_must_fail git fetch server +refs/heads/wt-4:refs/heads/wt-4 2>err &&
117 grep "refusing to fetch into branch" err
120 test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in rebase' '
121 test_when_finished git -C wt-3 rebase --abort &&
123 # This will fail part-way through due to a conflict.
124 test_must_fail git -C wt-3 rebase conflict-3 &&
126 test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err &&
127 grep "refusing to fetch into branch" err
130 test_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_* &&
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 &&
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 &&
150 for i in 1 2
152 test_must_fail git branch -f fake-$i HEAD 2>err &&
153 grep "cannot force update the branch '\''fake-$i'\'' used by worktree at" err ||
154 return 1
155 done
158 . "$TEST_DIRECTORY"/lib-rebase.sh
160 test_expect_success !SANITIZE_LEAK 'refuse to overwrite during rebase with --update-refs' '
161 git commit --fixup HEAD~2 --allow-empty &&
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 &&
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
175 # This must be the last test in this file
176 test_expect_success '$EDITOR and friends are unchanged' '
177 test_editor_unchanged
180 test_done