Skip to content

Commit 8d305fd

Browse files
committed
Merge branch 'co/t6050-pipefix'
Avoid losing exit status by having Git command being tested on the upstream side of a pipe. * co/t6050-pipefix: t6050: avoid pipes with upstream Git commands
2 parents cec4461 + 9e362dd commit 8d305fd

File tree

1 file changed

+86
-47
lines changed

1 file changed

+86
-47
lines changed

t/t6050-replace.sh

Lines changed: 86 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,42 @@ test_expect_success 'set up buggy branch' '
9898
'
9999

100100
test_expect_success 'replace the author' '
101-
git cat-file commit $HASH2 | grep "author A U Thor" &&
102-
R=$(git cat-file commit $HASH2 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
103-
git cat-file commit $R | grep "author O Thor" &&
101+
git cat-file commit $HASH2 >actual &&
102+
test_grep "author A U Thor" actual &&
103+
R=$(sed -e "s/A U/O/" actual | git hash-object -t commit --stdin -w) &&
104+
git cat-file commit $R >actual &&
105+
test_grep "author O Thor" actual &&
104106
git update-ref refs/replace/$HASH2 $R &&
105-
git show HEAD~5 | grep "O Thor" &&
106-
git show $HASH2 | grep "O Thor"
107+
git show HEAD~5 >actual &&
108+
test_grep "O Thor" actual &&
109+
git show $HASH2 >actual &&
110+
test_grep "O Thor" actual
107111
'
108112

109113
test_expect_success 'test --no-replace-objects option' '
110-
git cat-file commit $HASH2 | grep "author O Thor" &&
111-
git --no-replace-objects cat-file commit $HASH2 | grep "author A U Thor" &&
112-
git show $HASH2 | grep "O Thor" &&
113-
git --no-replace-objects show $HASH2 | grep "A U Thor"
114+
git cat-file commit $HASH2 >actual &&
115+
test_grep "author O Thor" actual &&
116+
git --no-replace-objects cat-file commit $HASH2 >actual &&
117+
test_grep "author A U Thor" actual &&
118+
git show $HASH2 >actual &&
119+
test_grep "O Thor" actual &&
120+
git --no-replace-objects show $HASH2 >actual &&
121+
test_grep "A U Thor" actual
114122
'
115123

116124
test_expect_success 'test GIT_NO_REPLACE_OBJECTS env variable' '
117-
GIT_NO_REPLACE_OBJECTS=1 git cat-file commit $HASH2 | grep "author A U Thor" &&
118-
GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 | grep "A U Thor"
125+
GIT_NO_REPLACE_OBJECTS=1 git cat-file commit $HASH2 >actual &&
126+
test_grep "author A U Thor" actual &&
127+
GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 >actual &&
128+
test_grep "A U Thor" actual
119129
'
120130

121131
test_expect_success 'test core.usereplacerefs config option' '
122132
test_config core.usereplacerefs false &&
123-
git cat-file commit $HASH2 | grep "author A U Thor" &&
124-
git show $HASH2 | grep "A U Thor"
133+
git cat-file commit $HASH2 >actual &&
134+
test_grep "author A U Thor" actual &&
135+
git show $HASH2 >actual &&
136+
test_grep "A U Thor" actual
125137
'
126138

127139
cat >tag.sig <<EOF
@@ -148,14 +160,18 @@ test_expect_success 'repack, clone and fetch work' '
148160
git clone --no-hardlinks . clone_dir &&
149161
(
150162
cd clone_dir &&
151-
git show HEAD~5 | grep "A U Thor" &&
152-
git show $HASH2 | grep "A U Thor" &&
163+
git show HEAD~5 >actual &&
164+
test_grep "A U Thor" actual &&
165+
git show $HASH2 >actual &&
166+
test_grep "A U Thor" actual &&
153167
git cat-file commit $R &&
154168
git repack -a -d &&
155169
test_must_fail git cat-file commit $R &&
156170
git fetch ../ "refs/replace/*:refs/replace/*" &&
157-
git show HEAD~5 | grep "O Thor" &&
158-
git show $HASH2 | grep "O Thor" &&
171+
git show HEAD~5 >actual &&
172+
test_grep "O Thor" actual &&
173+
git show $HASH2 >actual &&
174+
test_grep "O Thor" actual &&
159175
git cat-file commit $R
160176
)
161177
'
@@ -169,13 +185,15 @@ test_expect_success '"git replace" listing and deleting' '
169185
test_must_fail git replace --delete &&
170186
test_must_fail git replace -l -d $HASH2 &&
171187
git replace -d $HASH2 &&
172-
git show $HASH2 | grep "A U Thor" &&
188+
git show $HASH2 >actual &&
189+
test_grep "A U Thor" actual &&
173190
test -z "$(git replace -l)"
174191
'
175192

176193
test_expect_success '"git replace" replacing' '
177194
git replace $HASH2 $R &&
178-
git show $HASH2 | grep "O Thor" &&
195+
git show $HASH2 >actual &&
196+
test_grep "O Thor" actual &&
179197
test_must_fail git replace $HASH2 $R &&
180198
git replace -f $HASH2 $R &&
181199
test_must_fail git replace -f &&
@@ -186,7 +204,8 @@ test_expect_success '"git replace" resolves sha1' '
186204
SHORTHASH2=$(git rev-parse --short=8 $HASH2) &&
187205
git replace -d $SHORTHASH2 &&
188206
git replace $SHORTHASH2 $R &&
189-
git show $HASH2 | grep "O Thor" &&
207+
git show $HASH2 >actual &&
208+
test_grep "O Thor" actual &&
190209
test_must_fail git replace $HASH2 $R &&
191210
git replace -f $HASH2 $R &&
192211
test_must_fail git replace --force &&
@@ -209,10 +228,12 @@ test_expect_success '"git replace" resolves sha1' '
209228
#
210229
test_expect_success 'create parallel branch without the bug' '
211230
git replace -d $HASH2 &&
212-
git show $HASH2 | grep "A U Thor" &&
231+
git show $HASH2 >actual &&
232+
test_grep "A U Thor" actual &&
213233
git checkout $HASH1 &&
214234
git cherry-pick $HASH2 &&
215-
git show $HASH5 | git apply &&
235+
git show $HASH5 >actual &&
236+
git apply actual &&
216237
git commit --amend -m "hello: 4 more lines WITHOUT the bug" hello &&
217238
PARA2=$(git rev-parse --verify HEAD) &&
218239
git cherry-pick $HASH3 &&
@@ -225,7 +246,8 @@ test_expect_success 'create parallel branch without the bug' '
225246
git checkout main &&
226247
cur=$(git rev-parse --verify HEAD) &&
227248
test "$cur" = "$HASH7" &&
228-
git log --pretty=oneline | grep $PARA2 &&
249+
git log --pretty=oneline >actual &&
250+
test_grep $PARA2 actual &&
229251
git remote add cloned ./clone_dir
230252
'
231253

@@ -234,23 +256,30 @@ test_expect_success 'push to cloned repo' '
234256
(
235257
cd clone_dir &&
236258
git checkout parallel &&
237-
git log --pretty=oneline | grep $PARA2
259+
git log --pretty=oneline >actual &&
260+
test_grep $PARA2 actual
238261
)
239262
'
240263

241264
test_expect_success 'push branch with replacement' '
242-
git cat-file commit $PARA3 | grep "author A U Thor" &&
243-
S=$(git cat-file commit $PARA3 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
244-
git cat-file commit $S | grep "author O Thor" &&
265+
git cat-file commit $PARA3 >actual &&
266+
test_grep "author A U Thor" actual &&
267+
S=$(sed -e "s/A U/O/" actual | git hash-object -t commit --stdin -w) &&
268+
git cat-file commit $S >actual &&
269+
test_grep "author O Thor" actual &&
245270
git replace $PARA3 $S &&
246-
git show $HASH6~2 | grep "O Thor" &&
247-
git show $PARA3 | grep "O Thor" &&
271+
git show $HASH6~2 >actual &&
272+
test_grep "O Thor" actual &&
273+
git show $PARA3 >actual &&
274+
test_grep "O Thor" actual &&
248275
git push cloned $HASH6^:refs/heads/parallel2 &&
249276
(
250277
cd clone_dir &&
251278
git checkout parallel2 &&
252-
git log --pretty=oneline | grep $PARA3 &&
253-
git show $PARA3 | grep "A U Thor"
279+
git log --pretty=oneline >actual &&
280+
test_grep $PARA3 actual &&
281+
git show $PARA3 >actual &&
282+
test_grep "A U Thor" actual
254283
)
255284
'
256285

@@ -260,14 +289,14 @@ test_expect_success 'fetch branch with replacement' '
260289
cd clone_dir &&
261290
git fetch origin refs/heads/tofetch:refs/heads/parallel3 &&
262291
git log --pretty=oneline parallel3 >output.txt &&
263-
! grep $PARA3 output.txt &&
292+
test_grep ! $PARA3 output.txt &&
264293
git show $PARA3 >para3.txt &&
265-
grep "A U Thor" para3.txt &&
294+
test_grep "A U Thor" para3.txt &&
266295
git fetch origin "refs/replace/*:refs/replace/*" &&
267296
git log --pretty=oneline parallel3 >output.txt &&
268-
grep $PARA3 output.txt &&
297+
test_grep $PARA3 output.txt &&
269298
git show $PARA3 >para3.txt &&
270-
grep "O Thor" para3.txt
299+
test_grep "O Thor" para3.txt
271300
)
272301
'
273302

@@ -284,8 +313,8 @@ test_expect_success 'bisect and replacements' '
284313
'
285314

286315
test_expect_success 'index-pack and replacements' '
287-
git --no-replace-objects rev-list --objects HEAD |
288-
git --no-replace-objects pack-objects test- &&
316+
git --no-replace-objects rev-list --objects HEAD >actual &&
317+
git --no-replace-objects pack-objects test- <actual &&
289318
git index-pack test-*.pack
290319
'
291320

@@ -319,7 +348,8 @@ test_expect_success '-f option bypasses the type check' '
319348
'
320349

321350
test_expect_success 'git cat-file --batch works on replace objects' '
322-
git replace | grep $PARA3 &&
351+
git replace >actual &&
352+
test_grep $PARA3 actual &&
323353
echo $PARA3 | git cat-file --batch
324354
'
325355

@@ -344,7 +374,8 @@ test_expect_success 'test --format medium' '
344374
echo "$PARA3 -> $S" &&
345375
echo "$MYTAG -> $HASH1"
346376
} | sort >expected &&
347-
git replace -l --format medium | sort >actual &&
377+
git replace -l --format medium >output &&
378+
sort output >actual &&
348379
test_cmp expected actual
349380
'
350381

@@ -356,7 +387,8 @@ test_expect_success 'test --format long' '
356387
echo "$PARA3 (commit) -> $S (commit)" &&
357388
echo "$MYTAG (tag) -> $HASH1 (commit)"
358389
} | sort >expected &&
359-
git replace --format=long | sort >actual &&
390+
git replace --format=long >output &&
391+
sort output >actual &&
360392
test_cmp expected actual
361393
'
362394

@@ -374,21 +406,27 @@ test_expect_success 'setup fake editors' '
374406
test_expect_success '--edit with and without already replaced object' '
375407
test_must_fail env GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
376408
GIT_EDITOR=./fakeeditor git replace --force --edit "$PARA3" &&
377-
git replace -l | grep "$PARA3" &&
378-
git cat-file commit "$PARA3" | grep "A fake Thor" &&
409+
git replace -l >actual &&
410+
test_grep "$PARA3" actual &&
411+
git cat-file commit "$PARA3" >actual &&
412+
test_grep "A fake Thor" actual &&
379413
git replace -d "$PARA3" &&
380414
GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
381-
git replace -l | grep "$PARA3" &&
382-
git cat-file commit "$PARA3" | grep "A fake Thor"
415+
git replace -l >actual &&
416+
test_grep "$PARA3" actual &&
417+
git cat-file commit "$PARA3" >actual &&
418+
test_grep "A fake Thor" actual
383419
'
384420

385421
test_expect_success '--edit and change nothing or command failed' '
386422
git replace -d "$PARA3" &&
387423
test_must_fail env GIT_EDITOR=true git replace --edit "$PARA3" &&
388424
test_must_fail env GIT_EDITOR="./failingfakeeditor" git replace --edit "$PARA3" &&
389425
GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
390-
git replace -l | grep "$PARA3" &&
391-
git cat-file commit "$PARA3" | grep "A fake Thor"
426+
git replace -l >actual &&
427+
test_grep "$PARA3" actual &&
428+
git cat-file commit "$PARA3" >actual &&
429+
test_grep "A fake Thor" actual
392430
'
393431

394432
test_expect_success 'replace ref cleanup' '
@@ -468,7 +506,8 @@ test_expect_success GPG 'set up a merge commit with a mergetag' '
468506
git checkout main &&
469507
git merge -s ours test_tag &&
470508
HASH10=$(git rev-parse --verify HEAD) &&
471-
git cat-file commit $HASH10 | grep "^mergetag object"
509+
git cat-file commit $HASH10 >actual &&
510+
test_grep "^mergetag object" actual
472511
'
473512

474513
test_expect_success GPG '--graft on a commit with a mergetag' '

0 commit comments

Comments
 (0)