Skip to content

Commit 41429cb

Browse files
committed
t6011: fix misconversion from perl to sed
No, this is not about a quiz on regexp compatibility between Perl and sed. Back when cdbdc6b (t: refactor tests depending on Perl substitution operator, 2025-04-03) rewrote many uses of perl with sed, the general pattern of the original scripts were chmod +w some_read_only_file && perl -p -e "regexp to munge" some_read_only_file >some_tmp && mv some_tmp some_read_only_file persumably because the author knew that replacing some_read_only_file with "mv" at the last step would not work without "mv -f" in some environments (GNU seems to succeed without giving any prompt when not running interactively, which is what happens when running t/ scripts). Replacing perl with sed would be fine as long as sed with updated regexp does the equivalent munging. But one place used to use a different construct in the original: perl -i.bak -p -e "regexp to munge" some_read_only_file With _no_ temporary file or "mv", "perl -i" allows you to replace a read-only file in place. When we replaced the use of "perl" with "sed" in the said commit, however, because "sed -i" is not portable, we rewrote that in-place replacement to sed "regexp to munge" some_read_only_file >some_tmp && mv some_tmp some_read_only_file Again, unfortunately that does not work in some environment, without "mv -f". We could run "mv -f" here, but we would then need to remove "chmod +w" and have them use "mv -f" instead at all places that were touched cdbdc6b (t: refactor tests depending on Perl substitution operator, 2025-04-03) to be consistent (and more concise). For now, let's make it consistent in the other direction by mimick the other places that made the target read-write before moving. Speaking of portability, the outcome of using "sed" on non-text files is unspecified, so the entire exercise of cdbdc6b may have needed to be reverted if people still used ancient version of "standard compliant" sed that barfs on non-text files, but these days we may be able to get away with "BSDs and GNU seem OK with it" ;-) But one fix at a time. Reported-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7a7b602 commit 41429cb

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

t/t6011-rev-list-with-bad-commit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ test_expect_success 'verify number of revisions' \
3838
test_expect_success 'corrupt second commit object' '
3939
for p in .git/objects/pack/*.pack
4040
do
41+
chmod +w "$p" &&
4142
sed "s/second commit/socond commit/" "$p" >"$p.munged" &&
4243
mv "$p.munged" "$p" ||
4344
return 1

0 commit comments

Comments
 (0)