mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-04 08:28:36 +00:00
fix(dream): limit newline normalization to CRLF
This commit is contained in:
parent
ed47cf1562
commit
6e462e62a6
@ -365,7 +365,7 @@ class GitStore:
|
|||||||
wt_path = self._workspace / path
|
wt_path = self._workspace / path
|
||||||
try:
|
try:
|
||||||
wt_text = (
|
wt_text = (
|
||||||
wt_path.read_text(encoding="utf-8")
|
wt_path.read_bytes().decode("utf-8")
|
||||||
if wt_path.exists()
|
if wt_path.exists()
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
@ -377,12 +377,12 @@ class GitStore:
|
|||||||
changed += 1
|
changed += 1
|
||||||
summary_lines.append(f"{path}: binary or non-UTF-8 file changed")
|
summary_lines.append(f"{path}: binary or non-UTF-8 file changed")
|
||||||
continue
|
continue
|
||||||
# Git blobs preserve line endings while read_text() normalizes
|
# Treat CRLF and LF as equivalent without hiding other
|
||||||
# them. Compare the same logical lines used by the diff.
|
# newline changes, such as a missing final newline.
|
||||||
|
if head_text.replace("\r\n", "\n") == wt_text.replace("\r\n", "\n"):
|
||||||
|
continue
|
||||||
head_lines = head_text.splitlines()
|
head_lines = head_text.splitlines()
|
||||||
wt_lines = wt_text.splitlines()
|
wt_lines = wt_text.splitlines()
|
||||||
if head_lines == wt_lines:
|
|
||||||
continue
|
|
||||||
changed += 1
|
changed += 1
|
||||||
hunks = list(difflib.unified_diff(
|
hunks = list(difflib.unified_diff(
|
||||||
head_lines,
|
head_lines,
|
||||||
|
|||||||
@ -697,6 +697,22 @@ class TestDreamContentDiff:
|
|||||||
assert status == ""
|
assert status == ""
|
||||||
assert store.dream_content_diff() == ""
|
assert store.dream_content_diff() == ""
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("before", "after", "changed"),
|
||||||
|
[
|
||||||
|
(b"# Memory\r\n", b"# Memory\n", False),
|
||||||
|
(b"# Memory\n", b"# Memory", True),
|
||||||
|
(b"# Memory\r", b"# Memory\n", True),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_only_ignores_crlf_lf_changes(self, store, before, after, changed):
|
||||||
|
store.memory_file.write_bytes(before)
|
||||||
|
store.git.init()
|
||||||
|
|
||||||
|
store.memory_file.write_bytes(after)
|
||||||
|
|
||||||
|
assert bool(store.dream_content_diff()) is changed
|
||||||
|
|
||||||
def test_reflects_real_content_edits(self, store):
|
def test_reflects_real_content_edits(self, store):
|
||||||
store.git.init()
|
store.git.init()
|
||||||
store.git.auto_commit("initial")
|
store.git.auto_commit("initial")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user