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>
Jialong Wang committed
Mar 16, 2026 at 21:15 UTC
4c2390067030d67c1b79fd96eb656ae63b91643b
1 file changed
+16
-8
t/t2203-add-intent.sh
+16
-8
@@ -16,7 +16,8 @@ test_expect_success 'intent to add' '
16
'
17
18
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 &&
21
cat >expect <<-\EOF &&
22
DA 1.t
23
A elif
@@ -26,7 +27,8 @@ test_expect_success 'git status' '
27
'
28
29
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 &&
32
nam1=$(echo 1 | git hash-object --stdin) &&
33
nam2=$(git hash-object elif) &&
34
cat >expect <<-EOF &&
@@ -171,17 +173,20 @@ test_expect_success 'rename detection finds the right names' '
173
mv first third &&
174
git add -N third &&
175
174
- git status | grep -v "^?" >actual.1 &&
176
+ git status >actual.raw.1 &&
177
+ grep -v "^?" actual.raw.1 >actual.1 &&
178
test_grep "renamed: *first -> third" actual.1 &&
179
177
- git status --porcelain | grep -v "^?" >actual.2 &&
180
+ git status --porcelain >actual.raw.2 &&
181
+ grep -v "^?" actual.raw.2 >actual.2 &&
182
cat >expected.2 <<-\EOF &&
183
R first -> third
184
EOF
185
test_cmp expected.2 actual.2 &&
186
187
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 &&
190
cat >expected.3 <<-EOF &&
191
2 .R N... 100644 100644 100644 $hash $hash R100 third first
192
EOF
@@ -211,11 +216,13 @@ test_expect_success 'double rename detection in status' '
216
mv second third &&
217
git add -N third &&
218
214
- git status | grep -v "^?" >actual.1 &&
219
+ git status >actual.raw.1 &&
220
+ grep -v "^?" actual.raw.1 >actual.1 &&
221
test_grep "renamed: *first -> second" actual.1 &&
222
test_grep "renamed: *second -> third" actual.1 &&
223
218
- git status --porcelain | grep -v "^?" >actual.2 &&
224
+ git status --porcelain >actual.raw.2 &&
225
+ grep -v "^?" actual.raw.2 >actual.2 &&
226
cat >expected.2 <<-\EOF &&
227
R first -> second
228
R second -> third
@@ -223,7 +230,8 @@ test_expect_success 'double rename detection in status' '
230
test_cmp expected.2 actual.2 &&
231
232
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 &&
235
cat >expected.3 <<-EOF &&
236
2 R. N... 100644 100644 100644 $hash $hash R100 second first
237
2 .R N... 100644 100644 100644 $hash $hash R100 third second