Skip to content

Commit bcf325a

Browse files
sunshinecogitster
authored andcommitted
t4301: account for behavior differences between sed implementations
It is a common pattern in this script to write the result of `merge-tree -z` (NUL-termination mode) to an "actual" file and then manually append a newline to that file so that it can be diff'd easily with a hand-crafted "expect" file which itself ends with a newline since it has been created by standard Unix tools which terminate lines by default. For instance: git merge-tree --write-tree -z ... >out && printf "\\n" >>out anonymize_hash out >actual && q_to_nul <<-EOF >expect && ... EOF test_cmp expect actual However, one test gets this backward: git merge-tree --write-tree -z ... >out && anonymize_hash out >actual && printf "\\n" >>actual which means that, unlike all other cases, when anonymize_hash() is called, the file being anonymized does not end with a newline. As a result, this test fails on some platforms. anonymize_hash() is implemented like this: anonymize_hash() { sed -e "s/[0-9a-f]\{40,\}/HASH/g" "$@" } The problem arises due to differences in behavior of various `sed` implementations when fed an incomplete line (lacking a newline). Although most modern `sed` implementations output such a line unmolested (i.e. without a newline), some older `sed` implementations forcibly add a newline to the incomplete line (giving the output an extra unexpected newline), while other very old implementations simply swallow an incomplete line and don't emit it at all (making the output shorter than expected). Fix this test by manually adding the newline before passing it through `sed`, thus ensuring identical behavior with all `sed` implementation, and bringing the test in line with other tests in this script. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2987ce7 commit bcf325a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

t/t4301-merge-tree-write-tree.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,8 @@ test_expect_success 'NUL terminated conflicted file "lines"' '
760760
git commit -m "Renamed numbers" &&
761761
762762
test_expect_code 1 git merge-tree --write-tree -z tweak1 side2 >out &&
763+
printf "\\n" >>out &&
763764
anonymize_hash out >actual &&
764-
printf "\\n" >>actual &&
765765
766766
# Expected results:
767767
# "greeting" should merge with conflicts

0 commit comments

Comments
 (0)