Skip to content

Commit da4c600

Browse files
committed
Merge branch 'pc/t2027-git-to-pipe-cleanup'
Having a git command on the upstream side of a pipe in a test script will hide the exit status from the command, which may cause us to fail to notice a breakage; rewrite tests in a script to avoid this issue. * pc/t2027-git-to-pipe-cleanup: t2027: avoid using pipes
2 parents 768c7cb + 210e5db commit da4c600

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

t/t2027-worktree-list.sh

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,29 @@ test_expect_success 'rev-parse --git-common-dir on main worktree' '
2020

2121
test_expect_success 'rev-parse --git-path objects linked worktree' '
2222
echo "$(git rev-parse --show-toplevel)/.git/objects" >expect &&
23-
test_when_finished "rm -rf linked-tree && git worktree prune" &&
23+
test_when_finished "rm -rf linked-tree actual expect && git worktree prune" &&
2424
git worktree add --detach linked-tree master &&
2525
git -C linked-tree rev-parse --git-path objects >actual &&
2626
test_cmp expect actual
2727
'
2828

2929
test_expect_success '"list" all worktrees from main' '
3030
echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
31-
test_when_finished "rm -rf here && git worktree prune" &&
31+
test_when_finished "rm -rf here out actual expect && git worktree prune" &&
3232
git worktree add --detach here master &&
3333
echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
34-
git worktree list | sed "s/ */ /g" >actual &&
34+
git worktree list >out &&
35+
sed "s/ */ /g" <out >actual &&
3536
test_cmp expect actual
3637
'
3738

3839
test_expect_success '"list" all worktrees from linked' '
3940
echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
40-
test_when_finished "rm -rf here && git worktree prune" &&
41+
test_when_finished "rm -rf here out actual expect && git worktree prune" &&
4142
git worktree add --detach here master &&
4243
echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
43-
git -C here worktree list | sed "s/ */ /g" >actual &&
44+
git -C here worktree list >out &&
45+
sed "s/ */ /g" <out >actual &&
4446
test_cmp expect actual
4547
'
4648

@@ -49,7 +51,7 @@ test_expect_success '"list" all worktrees --porcelain' '
4951
echo "HEAD $(git rev-parse HEAD)" >>expect &&
5052
echo "branch $(git symbolic-ref HEAD)" >>expect &&
5153
echo >>expect &&
52-
test_when_finished "rm -rf here && git worktree prune" &&
54+
test_when_finished "rm -rf here actual expect && git worktree prune" &&
5355
git worktree add --detach here master &&
5456
echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect &&
5557
echo "HEAD $(git rev-parse HEAD)" >>expect &&
@@ -69,16 +71,17 @@ test_expect_success 'bare repo setup' '
6971
'
7072

7173
test_expect_success '"list" all worktrees from bare main' '
72-
test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
74+
test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" &&
7375
git -C bare1 worktree add --detach ../there master &&
7476
echo "$(pwd)/bare1 (bare)" >expect &&
7577
echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
76-
git -C bare1 worktree list | sed "s/ */ /g" >actual &&
78+
git -C bare1 worktree list >out &&
79+
sed "s/ */ /g" <out >actual &&
7780
test_cmp expect actual
7881
'
7982

8083
test_expect_success '"list" all worktrees --porcelain from bare main' '
81-
test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
84+
test_when_finished "rm -rf there actual expect && git -C bare1 worktree prune" &&
8285
git -C bare1 worktree add --detach ../there master &&
8386
echo "worktree $(pwd)/bare1" >expect &&
8487
echo "bare" >>expect &&
@@ -92,11 +95,12 @@ test_expect_success '"list" all worktrees --porcelain from bare main' '
9295
'
9396

9497
test_expect_success '"list" all worktrees from linked with a bare main' '
95-
test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
98+
test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" &&
9699
git -C bare1 worktree add --detach ../there master &&
97100
echo "$(pwd)/bare1 (bare)" >expect &&
98101
echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
99-
git -C there worktree list | sed "s/ */ /g" >actual &&
102+
git -C there worktree list >out &&
103+
sed "s/ */ /g" <out >actual &&
100104
test_cmp expect actual
101105
'
102106

@@ -118,9 +122,11 @@ test_expect_success 'broken main worktree still at the top' '
118122
cd linked &&
119123
echo "worktree $(pwd)" >expected &&
120124
echo "ref: .broken" >../.git/HEAD &&
121-
git worktree list --porcelain | head -n 3 >actual &&
125+
git worktree list --porcelain >out &&
126+
head -n 3 out >actual &&
122127
test_cmp ../expected actual &&
123-
git worktree list | head -n 1 >actual.2 &&
128+
git worktree list >out &&
129+
head -n 1 out >actual.2 &&
124130
grep -F "(error)" actual.2
125131
)
126132
'
@@ -134,7 +140,8 @@ test_expect_success 'linked worktrees are sorted' '
134140
test_commit new &&
135141
git worktree add ../first &&
136142
git worktree add ../second &&
137-
git worktree list --porcelain | grep ^worktree >actual
143+
git worktree list --porcelain >out &&
144+
grep ^worktree out >actual
138145
) &&
139146
cat >expected <<-EOF &&
140147
worktree $(pwd)/sorted/main

0 commit comments

Comments
 (0)