mirror of
https://github.com/newren/git-filter-repo.git
synced 2024-06-03 10:55:20 +02:00
filter-repo: add tests for --replace-text in binary blobs
The --replace-text failed to detect blobs as binary and incorrectly applied to all blobs. Prior to switch from python2 to python3 it incorrectly designated blobs containing 0 character instead of NUL byte as binary and would have been causing text replacements to apply to binary files and not apply to text files containing 0 character. Add regression tests with blobs containing; 0 character, NUL byte, and both 0 character and NUL byte. Signed-off-by: rndbit <rndbit@filter.bitman.net>
This commit is contained in:
parent
9cfe2b4090
commit
993216739e
|
@ -850,6 +850,87 @@ test_expect_success '--replace-text all options' '
|
|||
)
|
||||
'
|
||||
|
||||
test_expect_success '--replace-text binary zero_byte-0_char' '
|
||||
(
|
||||
set -e
|
||||
set -u
|
||||
REPO=replace-text-detect-binary
|
||||
FILE=mangle.bin
|
||||
OLD_STR=replace-from
|
||||
NEW_STR=replace-with
|
||||
# used with printf, contains a zero byte and a "0" character, binary
|
||||
OLD_CONTENT_FORMAT="${OLD_STR}\\0${OLD_STR}\\n0\\n"
|
||||
# expect content unchanged due to binary
|
||||
NEW_CONTENT_FORMAT="${OLD_CONTENT_FORMAT}"
|
||||
|
||||
rm -rf "${REPO}"
|
||||
git init "${REPO}"
|
||||
cd "${REPO}"
|
||||
echo "${OLD_STR}==>${NEW_STR}" >../replace-rules
|
||||
printf "${NEW_CONTENT_FORMAT}" > ../expect
|
||||
printf "${OLD_CONTENT_FORMAT}" > "${FILE}"
|
||||
git add "${FILE}"
|
||||
git commit -m 'test'
|
||||
git filter-repo --force --replace-text ../replace-rules
|
||||
|
||||
test_cmp ../expect "${FILE}"
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success '--replace-text binary zero_byte-no_0_char' '
|
||||
(
|
||||
set -e
|
||||
set -u
|
||||
REPO=replace-text-detect-binary
|
||||
FILE=mangle.bin
|
||||
OLD_STR=replace-from
|
||||
NEW_STR=replace-with
|
||||
# used with printf, contains a zero byte but no "0" character, binary
|
||||
OLD_CONTENT_FORMAT="${OLD_STR}\\0${OLD_STR}\\n"
|
||||
# expect content unchanged due to binary
|
||||
NEW_CONTENT_FORMAT="${OLD_CONTENT_FORMAT}"
|
||||
|
||||
rm -rf "${REPO}"
|
||||
git init "${REPO}"
|
||||
cd "${REPO}"
|
||||
echo "${OLD_STR}==>${NEW_STR}" >../replace-rules
|
||||
printf "${NEW_CONTENT_FORMAT}" > ../expect
|
||||
printf "${OLD_CONTENT_FORMAT}" > "${FILE}"
|
||||
git add "${FILE}"
|
||||
git commit -m 'test'
|
||||
git filter-repo --force --replace-text ../replace-rules
|
||||
|
||||
test_cmp ../expect "${FILE}"
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success '--replace-text text-file no_zero_byte-zero_char' '
|
||||
(
|
||||
set -e
|
||||
set -u
|
||||
REPO=replace-text-detect-binary
|
||||
FILE=mangle.bin
|
||||
OLD_STR=replace-from
|
||||
NEW_STR=replace-with
|
||||
# used with printf, contains no zero byte but contains a "0" character, text
|
||||
OLD_CONTENT_FORMAT="${OLD_STR}0\\n0${OLD_STR}\\n0\\n"
|
||||
# expect content changed due to text
|
||||
NEW_CONTENT_FORMAT="${NEW_STR}0\\n0${NEW_STR}\\n0\\n"
|
||||
|
||||
rm -rf "${REPO}"
|
||||
git init "${REPO}"
|
||||
cd "${REPO}"
|
||||
echo "${OLD_STR}==>${NEW_STR}" >../replace-rules
|
||||
printf "${NEW_CONTENT_FORMAT}" > ../expect
|
||||
printf "${OLD_CONTENT_FORMAT}" > "${FILE}"
|
||||
git add "${FILE}"
|
||||
git commit -m 'test'
|
||||
git filter-repo --force --replace-text ../replace-rules
|
||||
|
||||
test_cmp ../expect "${FILE}"
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success '--strip-blobs-bigger-than' '
|
||||
setup_analyze_me &&
|
||||
(
|
||||
|
|
Loading…
Reference in New Issue
Block a user