Ignore leading and trailing blank lines for comparison
```git-check-assertions run test/mechanicaldiff.bats assert_success git checkout HEAD~ bin run test/mechanicaldiff.bats assert_failure assert_output --partial "-- command failed --" ```
This commit is contained in:
parent
3d814b5b15
commit
0b3d0d8f46
2 changed files with 29 additions and 1 deletions
|
|
@ -4,6 +4,16 @@ import re
|
|||
import sys
|
||||
|
||||
|
||||
def trim_blank_ends(lines: list[str]) -> list[str]:
|
||||
start = 0
|
||||
end = len(lines)
|
||||
while start < end and lines[start] == "\n":
|
||||
start += 1
|
||||
while end > start and lines[end - 1] == "\n":
|
||||
end -= 1
|
||||
return lines[start:end]
|
||||
|
||||
|
||||
def filter_change_block(
|
||||
change_lines: list[str], search: str, replace: str
|
||||
) -> list[str]:
|
||||
|
|
@ -27,7 +37,7 @@ def filter_change_block(
|
|||
transformed_removed = [
|
||||
re.sub(search, replace, line) for line in removed_lines
|
||||
]
|
||||
if transformed_removed == added_lines:
|
||||
if trim_blank_ends(transformed_removed) == trim_blank_ends(added_lines):
|
||||
return change_lines
|
||||
|
||||
if len(removed_lines) != len(added_lines):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue