From c3cf2aff08b2045194018c3c9a62206f84663f1f Mon Sep 17 00:00:00 2001 From: Muhammad Wasif Ali Wasif <76695420+wachi35676@users.noreply.github.com> Date: Tue, 13 Oct 2026 23:35:32 +0500 Subject: [PATCH] fix(tools): write technical debt files with LF line endings On Windows debt_split rewrote the index and the debt files with CRLF, and resolve staged them that way when core.autocrlf is off. The files are now written through open(..., newline="\n"), which also works on Python 3.9, where Path.write_text has no newline argument. Co-Authored-By: Claude Opus 5.5 --- tools/debt_split.py | 11 ++++++++--- tools/tests/test_debt_split.py | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/debt_split.py b/tools/debt_split.py index 5c27562a4e..2967f6c46a 100644 --- a/tools/debt_split.py +++ b/tools/debt_split.py @@ -77,6 +77,11 @@ def read_debt(root, name): return sections +def write_lf(path, text): + with open(path, "w", encoding="utf-8", newline="\n") as file: + file.write(text) + + def write_debt(root, name, sections, order): path = root / debt_file(name) sections = {section: entries for section, entries in sections.items() if entries} @@ -85,7 +90,7 @@ def write_debt(root, name, sections, order): path.unlink() return path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(render(f"# {name} technical debt", sections, order), encoding="utf-8") + write_lf(path, render(f"# {name} technical debt", sections, order)) def sections_of(text): @@ -132,7 +137,7 @@ def command_split(root): write_debt(root, name, existing, order) if index_note() not in index: index.insert(1, index_note()) - (root / INDEX).write_text(render_index(index), encoding="utf-8") + write_lf(root / INDEX, render_index(index)) print("\n".join(sorted(debt_file(name) for name in files))) @@ -215,7 +220,7 @@ def command_resolve(root): touched = apply_change(root, base, theirs, ours) except LookupError as error: sys.exit(str(error)) - (root / INDEX).write_text(ours, encoding="utf-8") + write_lf(root / INDEX, ours) git(root, "add", "--", INDEX, *touched) print("\n".join(touched)) diff --git a/tools/tests/test_debt_split.py b/tools/tests/test_debt_split.py index 8ffc27c4ca..d8fd887317 100644 --- a/tools/tests/test_debt_split.py +++ b/tools/tests/test_debt_split.py @@ -84,6 +84,8 @@ class DebtSplitTests(unittest.TestCase): self.assertNotIn(entry.split(" - ")[0], text) for kept in ("- A toolchain limitation", "Everything throws, except:", SHARED, "### Silent stubs", "[debt](debt/)"): self.assertIn(kept, text) + for path in (INDEX, "docs/dev/debt/libSceA.md"): + self.assertNotIn(b"\r", (self.root / path).read_bytes()) def test_split_again_appends_to_existing_files(self): self.split() @@ -116,6 +118,8 @@ class DebtSplitTests(unittest.TestCase): self.assertEqual(sorted(result.stdout.split()), ["docs/dev/debt/libSceA.md", "docs/dev/debt/libSceB.md", "docs/dev/debt/libSceC.md"]) self.assertEqual(self.git("diff", "--name-only", "--diff-filter=U").stdout, "") + for path in (INDEX, "docs/dev/debt/libSceA.md"): + self.assertNotIn(b"\r", (self.root / path).read_bytes()) self.git("rebase", "--continue") a = self.read("docs/dev/debt/libSceA.md") self.assertLess(a.index("`sceAOne`"), a.index("`sceAFour`"))