t6050: avoid pipes with upstream Git commands

In pipes, the exit code of a chain of commands is determined by the final command. In order not to miss the exit code of a failed Git command, avoid pipes instead write output of Git commands into a file. For better debugging experience, instances of "grep" were changed to "test_grep". "test_grep" provides more context in case of a failed "grep". Signed-off-by: Chizoba ODINAKA <chizobajames21@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Chizoba ODINAKA committed Oct 22, 2024 at 02:27 UTC 9e362dd060c1ffdba958225f763db4bf9ba451cc
1 file changed +86 -47
t/t6050-replace.sh
+86 -47
@@ -98,30 +98,42 @@ test_expect_success 'set up buggy branch' '
98 '
99
100 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 &&
106 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
111 '
112
113 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
122 '
123
124 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
129 '
130
131 test_expect_success 'test core.usereplacerefs config option' '
132 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
137 '
138
139 cat >tag.sig <<EOF
@@ -148,14 +160,18 @@ test_expect_success 'repack, clone and fetch work' '
160 git clone --no-hardlinks . clone_dir &&
161 (
162 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 &&
167 git cat-file commit $R &&
168 git repack -a -d &&
169 test_must_fail git cat-file commit $R &&
170 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 &&
175 git cat-file commit $R
176 )
177 '
@@ -169,13 +185,15 @@ test_expect_success '"git replace" listing and deleting' '
185 test_must_fail git replace --delete &&
186 test_must_fail git replace -l -d $HASH2 &&
187 git replace -d $HASH2 &&
172 - git show $HASH2 | grep "A U Thor" &&
188 + git show $HASH2 >actual &&
189 + test_grep "A U Thor" actual &&
190 test -z "$(git replace -l)"
191 '
192
193 test_expect_success '"git replace" replacing' '
194 git replace $HASH2 $R &&
178 - git show $HASH2 | grep "O Thor" &&
195 + git show $HASH2 >actual &&
196 + test_grep "O Thor" actual &&
197 test_must_fail git replace $HASH2 $R &&
198 git replace -f $HASH2 $R &&
199 test_must_fail git replace -f &&
@@ -186,7 +204,8 @@ test_expect_success '"git replace" resolves sha1' '
204 SHORTHASH2=$(git rev-parse --short=8 $HASH2) &&
205 git replace -d $SHORTHASH2 &&
206 git replace $SHORTHASH2 $R &&
189 - git show $HASH2 | grep "O Thor" &&
207 + git show $HASH2 >actual &&
208 + test_grep "O Thor" actual &&
209 test_must_fail git replace $HASH2 $R &&
210 git replace -f $HASH2 $R &&
211 test_must_fail git replace --force &&
@@ -209,10 +228,12 @@ test_expect_success '"git replace" resolves sha1' '
228 #
229 test_expect_success 'create parallel branch without the bug' '
230 git replace -d $HASH2 &&
212 - git show $HASH2 | grep "A U Thor" &&
231 + git show $HASH2 >actual &&
232 + test_grep "A U Thor" actual &&
233 git checkout $HASH1 &&
234 git cherry-pick $HASH2 &&
215 - git show $HASH5 | git apply &&
235 + git show $HASH5 >actual &&
236 + git apply actual &&
237 git commit --amend -m "hello: 4 more lines WITHOUT the bug" hello &&
238 PARA2=$(git rev-parse --verify HEAD) &&
239 git cherry-pick $HASH3 &&
@@ -225,7 +246,8 @@ test_expect_success 'create parallel branch without the bug' '
246 git checkout main &&
247 cur=$(git rev-parse --verify HEAD) &&
248 test "$cur" = "$HASH7" &&
228 - git log --pretty=oneline | grep $PARA2 &&
249 + git log --pretty=oneline >actual &&
250 + test_grep $PARA2 actual &&
251 git remote add cloned ./clone_dir
252 '
253
@@ -234,23 +256,30 @@ test_expect_success 'push to cloned repo' '
256 (
257 cd clone_dir &&
258 git checkout parallel &&
237 - git log --pretty=oneline | grep $PARA2
259 + git log --pretty=oneline >actual &&
260 + test_grep $PARA2 actual
261 )
262 '
263
264 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 &&
270 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 &&
275 git push cloned $HASH6^:refs/heads/parallel2 &&
276 (
277 cd clone_dir &&
278 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
283 )
284 '
285
@@ -260,14 +289,14 @@ test_expect_success 'fetch branch with replacement' '
289 cd clone_dir &&
290 git fetch origin refs/heads/tofetch:refs/heads/parallel3 &&
291 git log --pretty=oneline parallel3 >output.txt &&
263 - ! grep $PARA3 output.txt &&
292 + test_grep ! $PARA3 output.txt &&
293 git show $PARA3 >para3.txt &&
265 - grep "A U Thor" para3.txt &&
294 + test_grep "A U Thor" para3.txt &&
295 git fetch origin "refs/replace/*:refs/replace/*" &&
296 git log --pretty=oneline parallel3 >output.txt &&
268 - grep $PARA3 output.txt &&
297 + test_grep $PARA3 output.txt &&
298 git show $PARA3 >para3.txt &&
270 - grep "O Thor" para3.txt
299 + test_grep "O Thor" para3.txt
300 )
301 '
302
@@ -284,8 +313,8 @@ test_expect_success 'bisect and replacements' '
313 '
314
315 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 &&
318 git index-pack test-*.pack
319 '
320
@@ -319,7 +348,8 @@ test_expect_success '-f option bypasses the type check' '
348 '
349
350 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 &&
353 echo $PARA3 | git cat-file --batch
354 '
355
@@ -344,7 +374,8 @@ test_expect_success 'test --format medium' '
374 echo "$PARA3 -> $S" &&
375 echo "$MYTAG -> $HASH1"
376 } | sort >expected &&
347 - git replace -l --format medium | sort >actual &&
377 + git replace -l --format medium >output &&
378 + sort output >actual &&
379 test_cmp expected actual
380 '
381
@@ -356,7 +387,8 @@ test_expect_success 'test --format long' '
387 echo "$PARA3 (commit) -> $S (commit)" &&
388 echo "$MYTAG (tag) -> $HASH1 (commit)"
389 } | sort >expected &&
359 - git replace --format=long | sort >actual &&
390 + git replace --format=long >output &&
391 + sort output >actual &&
392 test_cmp expected actual
393 '
394
@@ -374,12 +406,16 @@ test_expect_success 'setup fake editors' '
406 test_expect_success '--edit with and without already replaced object' '
407 test_must_fail env GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
408 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 &&
413 git replace -d "$PARA3" &&
414 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
419 '
420
421 test_expect_success '--edit and change nothing or command failed' '
@@ -387,8 +423,10 @@ test_expect_success '--edit and change nothing or command failed' '
423 test_must_fail env GIT_EDITOR=true git replace --edit "$PARA3" &&
424 test_must_fail env GIT_EDITOR="./failingfakeeditor" git replace --edit "$PARA3" &&
425 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
430 '
431
432 test_expect_success 'replace ref cleanup' '
@@ -468,7 +506,8 @@ test_expect_success GPG 'set up a merge commit with a mergetag' '
506 git checkout main &&
507 git merge -s ours test_tag &&
508 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
511 '
512
513 test_expect_success GPG '--graft on a commit with a mergetag' '