t2027: avoid using pipes
Whenever a git command is present in the upstream of a pipe, its failure gets masked by piping. Hence we should avoid it for testing the upstream git command. By writing out the output of the git command to a file, we can test the exit codes of both the commands as a failure exit code in any command is able to stop the && chain. Signed-off-by: Prathamesh Chavan <pc44800@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Prathamesh Chavan committed
Apr 4, 2017 at 03:05 UTC
210e5dba0b43db7136d9a054fed55965c8b1a843
1 file changed
+21
-14
t/t2027-worktree-list.sh
+21
-14
@@ -20,7 +20,7 @@ test_expect_success 'rev-parse --git-common-dir on main worktree' '
20
21
test_expect_success 'rev-parse --git-path objects linked worktree' '
22
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" &&
24
git worktree add --detach linked-tree master &&
25
git -C linked-tree rev-parse --git-path objects >actual &&
26
test_cmp expect actual
@@ -28,19 +28,21 @@ test_expect_success 'rev-parse --git-path objects linked worktree' '
28
29
test_expect_success '"list" all worktrees from main' '
30
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" &&
32
git worktree add --detach here master &&
33
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 &&
36
test_cmp expect actual
37
'
38
39
test_expect_success '"list" all worktrees from linked' '
40
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" &&
42
git worktree add --detach here master &&
43
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 &&
46
test_cmp expect actual
47
'
48
@@ -49,7 +51,7 @@ test_expect_success '"list" all worktrees --porcelain' '
51
echo "HEAD $(git rev-parse HEAD)" >>expect &&
52
echo "branch $(git symbolic-ref HEAD)" >>expect &&
53
echo >>expect &&
52
- test_when_finished "rm -rf here && git worktree prune" &&
54
+ test_when_finished "rm -rf here actual expect && git worktree prune" &&
55
git worktree add --detach here master &&
56
echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect &&
57
echo "HEAD $(git rev-parse HEAD)" >>expect &&
@@ -69,16 +71,17 @@ test_expect_success 'bare repo setup' '
71
'
72
73
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" &&
75
git -C bare1 worktree add --detach ../there master &&
76
echo "$(pwd)/bare1 (bare)" >expect &&
77
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 &&
80
test_cmp expect actual
81
'
82
83
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" &&
85
git -C bare1 worktree add --detach ../there master &&
86
echo "worktree $(pwd)/bare1" >expect &&
87
echo "bare" >>expect &&
@@ -92,11 +95,12 @@ test_expect_success '"list" all worktrees --porcelain from bare main' '
95
'
96
97
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" &&
99
git -C bare1 worktree add --detach ../there master &&
100
echo "$(pwd)/bare1 (bare)" >expect &&
101
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 &&
104
test_cmp expect actual
105
'
106
@@ -118,9 +122,11 @@ test_expect_success 'broken main worktree still at the top' '
122
cd linked &&
123
echo "worktree $(pwd)" >expected &&
124
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 &&
127
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 &&
130
grep -F "(error)" actual.2
131
)
132
'
@@ -134,7 +140,8 @@ test_expect_success 'linked worktrees are sorted' '
140
test_commit new &&
141
git worktree add ../first &&
142
git worktree add ../second &&
137
- git worktree list --porcelain | grep ^worktree >actual
143
+ git worktree list --porcelain >out &&
144
+ grep ^worktree out >actual
145
) &&
146
cat >expected <<-EOF &&
147
worktree $(pwd)/sorted/main