Skip to content

Commit 4c23900

Browse files
Jialong Wanggitster
authored andcommitted
t2203: avoid suppressing git status exit code
When git status is piped into grep, the exit status of the Git command is hidden by the pipeline. Capture the status output in a temporary file first, and then filter it as needed, so that any failure from git status is still noticed by the test suite. Signed-off-by: Jialong Wang <jerrywang183@yahoo.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ca1db8a commit 4c23900

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

t/t2203-add-intent.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ test_expect_success 'intent to add' '
1616
'
1717

1818
test_expect_success 'git status' '
19-
git status --porcelain | grep -v actual >actual &&
19+
git status --porcelain >actual.raw &&
20+
grep -v actual actual.raw >actual &&
2021
cat >expect <<-\EOF &&
2122
DA 1.t
2223
A elif
@@ -26,7 +27,8 @@ test_expect_success 'git status' '
2627
'
2728

2829
test_expect_success 'git status with porcelain v2' '
29-
git status --porcelain=v2 | grep -v "^?" >actual &&
30+
git status --porcelain=v2 >actual.raw &&
31+
grep -v "^?" actual.raw >actual &&
3032
nam1=$(echo 1 | git hash-object --stdin) &&
3133
nam2=$(git hash-object elif) &&
3234
cat >expect <<-EOF &&
@@ -171,17 +173,20 @@ test_expect_success 'rename detection finds the right names' '
171173
mv first third &&
172174
git add -N third &&
173175
174-
git status | grep -v "^?" >actual.1 &&
176+
git status >actual.raw.1 &&
177+
grep -v "^?" actual.raw.1 >actual.1 &&
175178
test_grep "renamed: *first -> third" actual.1 &&
176179
177-
git status --porcelain | grep -v "^?" >actual.2 &&
180+
git status --porcelain >actual.raw.2 &&
181+
grep -v "^?" actual.raw.2 >actual.2 &&
178182
cat >expected.2 <<-\EOF &&
179183
R first -> third
180184
EOF
181185
test_cmp expected.2 actual.2 &&
182186
183187
hash=$(git hash-object third) &&
184-
git status --porcelain=v2 | grep -v "^?" >actual.3 &&
188+
git status --porcelain=v2 >actual.raw.3 &&
189+
grep -v "^?" actual.raw.3 >actual.3 &&
185190
cat >expected.3 <<-EOF &&
186191
2 .R N... 100644 100644 100644 $hash $hash R100 third first
187192
EOF
@@ -211,19 +216,22 @@ test_expect_success 'double rename detection in status' '
211216
mv second third &&
212217
git add -N third &&
213218
214-
git status | grep -v "^?" >actual.1 &&
219+
git status >actual.raw.1 &&
220+
grep -v "^?" actual.raw.1 >actual.1 &&
215221
test_grep "renamed: *first -> second" actual.1 &&
216222
test_grep "renamed: *second -> third" actual.1 &&
217223
218-
git status --porcelain | grep -v "^?" >actual.2 &&
224+
git status --porcelain >actual.raw.2 &&
225+
grep -v "^?" actual.raw.2 >actual.2 &&
219226
cat >expected.2 <<-\EOF &&
220227
R first -> second
221228
R second -> third
222229
EOF
223230
test_cmp expected.2 actual.2 &&
224231
225232
hash=$(git hash-object third) &&
226-
git status --porcelain=v2 | grep -v "^?" >actual.3 &&
233+
git status --porcelain=v2 >actual.raw.3 &&
234+
grep -v "^?" actual.raw.3 >actual.3 &&
227235
cat >expected.3 <<-EOF &&
228236
2 R. N... 100644 100644 100644 $hash $hash R100 second first
229237
2 .R N... 100644 100644 100644 $hash $hash R100 third second

0 commit comments

Comments
 (0)