Skip to content

Commit 1bec4d1

Browse files
derrickstoleegitster
authored andcommitted
t2407: test bisect and rebase as black-boxes
The tests added by d2ba271 (branch: check for bisects and rebases, 2022-06-14) modified hidden state to verify the branch_checked_out() helper. While this indeed checks that the method implementation is _as designed_, it doesn't show that it is _correct_. Specifically, if 'git bisect' or 'git rebase' change their back-end for preserving refs, then these tests do not demonstrate that drift as a bug in branch_checked_out(). Modify the tests in t2407 to actually rely on a paused bisect or rebase. This requires adding the !SANITIZE_LEAK prereq for tests using those builtins. The logic is still tested for leaks in the final test which does set up that back-end directly for an error state that should not be possible using Git commands. Reported-by: Junio C Hamano <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7fefa1b commit 1bec4d1

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

t/t2407-worktree-heads.sh

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ TEST_PASSES_SANITIZE_LEAK=true
77

88
test_expect_success 'setup' '
99
test_commit init &&
10-
git branch -f fake-1 &&
11-
git branch -f fake-2 &&
1210
1311
for i in 1 2 3 4
1412
do
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 - &&
1519
test_commit $i &&
1620
git branch wt-$i &&
21+
git branch fake-$i &&
1722
git worktree add wt-$i wt-$i || return 1
1823
done &&
1924
@@ -44,26 +49,26 @@ test_expect_success 'refuse to overwrite: checked out in worktree' '
4449
done
4550
'
4651

47-
test_expect_success 'refuse to overwrite: worktree in bisect' '
48-
test_when_finished rm -rf .git/worktrees/wt-*/BISECT_* &&
52+
test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in bisect' '
53+
test_when_finished git -C wt-4 bisect reset &&
4954
50-
touch .git/worktrees/wt-4/BISECT_LOG &&
51-
echo refs/heads/fake-2 >.git/worktrees/wt-4/BISECT_START &&
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 &&
5259
53-
test_must_fail git branch -f fake-2 HEAD 2>err &&
54-
grep "cannot force update the branch '\''fake-2'\'' checked out at.*wt-4" err
60+
test_must_fail git branch -f wt-4 HEAD 2>err &&
61+
grep "cannot force update the branch '\''wt-4'\'' checked out at.*wt-4" err
5562
'
5663

57-
test_expect_success 'refuse to overwrite: worktree in rebase' '
58-
test_when_finished rm -rf .git/worktrees/wt-*/rebase-merge &&
64+
test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase' '
65+
test_when_finished git -C wt-2 rebase --abort &&
5966
60-
mkdir -p .git/worktrees/wt-3/rebase-merge &&
61-
touch .git/worktrees/wt-3/rebase-merge/interactive &&
62-
echo refs/heads/fake-1 >.git/worktrees/wt-3/rebase-merge/head-name &&
63-
echo refs/heads/fake-2 >.git/worktrees/wt-3/rebase-merge/onto &&
67+
# This will fail part-way through due to a conflict.
68+
test_must_fail git -C wt-2 rebase conflict-2 &&
6469
65-
test_must_fail git branch -f fake-1 HEAD 2>err &&
66-
grep "cannot force update the branch '\''fake-1'\'' checked out at.*wt-3" err
70+
test_must_fail git branch -f wt-2 HEAD 2>err &&
71+
grep "cannot force update the branch '\''wt-2'\'' checked out at.*wt-2" err
6772
'
6873

6974
test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: checked out' '
@@ -77,24 +82,24 @@ test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: checked out' '
7782
'
7883

7984
test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in bisect' '
80-
test_when_finished rm -rf .git/worktrees/wt-*/BISECT_* &&
85+
test_when_finished git -C wt-4 bisect reset &&
8186
82-
touch .git/worktrees/wt-4/BISECT_LOG &&
83-
echo refs/heads/fake-2 >.git/worktrees/wt-4/BISECT_START &&
87+
# Set up a bisect so HEAD no longer points to wt-4.
88+
git -C wt-4 bisect start &&
89+
git -C wt-4 bisect bad wt-4 &&
90+
git -C wt-4 bisect good wt-1 &&
8491
85-
test_must_fail git fetch server +refs/heads/fake-2:refs/heads/fake-2 2>err &&
92+
test_must_fail git fetch server +refs/heads/wt-4:refs/heads/wt-4 2>err &&
8693
grep "refusing to fetch into branch" err
8794
'
8895

8996
test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in rebase' '
90-
test_when_finished rm -rf .git/worktrees/wt-*/rebase-merge &&
97+
test_when_finished git -C wt-3 rebase --abort &&
9198
92-
mkdir -p .git/worktrees/wt-4/rebase-merge &&
93-
touch .git/worktrees/wt-4/rebase-merge/interactive &&
94-
echo refs/heads/fake-1 >.git/worktrees/wt-4/rebase-merge/head-name &&
95-
echo refs/heads/fake-2 >.git/worktrees/wt-4/rebase-merge/onto &&
99+
# This will fail part-way through due to a conflict.
100+
test_must_fail git -C wt-3 rebase conflict-3 &&
96101
97-
test_must_fail git fetch server +refs/heads/fake-1:refs/heads/fake-1 2>err &&
102+
test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err &&
98103
grep "refusing to fetch into branch" err
99104
'
100105

0 commit comments

Comments
 (0)