From cc27978e4471adbbefe88ed447c363c8191e9a59 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 19:06:38 -0500 Subject: [PATCH] fix(loop): read untracked paths NUL-separated so a non-ASCII new file no longer crashes a kept-tree refusal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3616. `untracked_paths()` read `git ls-files --others --exclude-standard` line by line. Under git's default `core.quotePath=true` a non-ASCII name such as `docs/café.md` came back C-quoted, quotes included. `retain_tree_after_refusal` passed that string to `git add -N`, which matched nothing and exited 128, so a guard refusal that kept the tree crashed the driver. `untracked_paths()` now passes `-z` and splits on NUL, so callers get the real name (the same read `squash_commit`'s new-file detection uses). Tests: - tests/test_untracked_paths_non_ascii.py:NonAsciiUntrackedPaths — the real name is returned; a kept tree marks a new non-ASCII file intent-to-add without crashing (both fail on the unchanged code) Verification: - scripts/smoke-test.sh: 5163 tests OK (4 skipped), ruff and bats green Co-Authored-By: Claude Opus 5.5 --- ...-guard-refusal-that-keeps-the-tree-no-l.md | 5 ++ specfuse/loop/loop.py | 8 +- tests/test_untracked_paths_non_ascii.py | 74 +++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 changelog.d/3616-a-guard-refusal-that-keeps-the-tree-no-l.md create mode 100644 tests/test_untracked_paths_non_ascii.py diff --git a/changelog.d/3616-a-guard-refusal-that-keeps-the-tree-no-l.md b/changelog.d/3616-a-guard-refusal-that-keeps-the-tree-no-l.md new file mode 100644 index 00000000..0789d3cc --- /dev/null +++ b/changelog.d/3616-a-guard-refusal-that-keeps-the-tree-no-l.md @@ -0,0 +1,5 @@ +--- +class: fixed +trace: #3616 +--- +A guard refusal that keeps the tree no longer crashes the driver when the attempt created a file with a non-ASCII name: untracked paths are read NUL-separated, so git no longer receives a quoted name. diff --git a/specfuse/loop/loop.py b/specfuse/loop/loop.py index 60f357b7..97a57bf5 100644 --- a/specfuse/loop/loop.py +++ b/specfuse/loop/loop.py @@ -3094,12 +3094,16 @@ def untracked_paths() -> set[str]: Snapshotted per-WU immediately before dispatch so `squash_commit` can tell "the operator already had this file" from "this run created it" — only the latter belongs in the WU's commit. See issue #150 and `squash_commit`. + + Read NUL-separated (`-z`): line output C-quotes a non-ASCII name under + git's default `core.quotePath`, and a quoted name passed back to git as a + pathspec matches nothing (#3616). """ out = subprocess.run( - ["git", "ls-files", "--others", "--exclude-standard"], + ["git", "ls-files", "--others", "--exclude-standard", "-z"], capture_output=True, text=True, check=True, ).stdout - return {line.strip() for line in out.splitlines() if line.strip()} + return {p for p in out.split("\0") if p} def _path_state(path: str) -> "tuple[int, str] | None": diff --git a/tests/test_untracked_paths_non_ascii.py b/tests/test_untracked_paths_non_ascii.py new file mode 100644 index 00000000..00cd6708 --- /dev/null +++ b/tests/test_untracked_paths_non_ascii.py @@ -0,0 +1,74 @@ +# +# Copyright 2026 Specfuse contributors +# Licensed under the Apache License, Version 2.0. See LICENSE. +# +"""A kept tree whose attempt created a non-ASCII-named file (#3616). + +`untracked_paths` read `git ls-files --others` line by line, so with git's +default `core.quotePath=true` a name like `café.md` came back C-quoted +(`"caf\\303\\251.md"`, quotes included). `retain_tree_after_refusal` then +passed that quoted string to `git add -N`, which matched nothing and exited +128, crashing the driver on a guard refusal that kept the tree. +""" + +from __future__ import annotations + +import os +import subprocess +import tempfile +import unittest +from pathlib import Path + +from tests._loop_loader import load_loop + +loop = load_loop() + +CAFE = "docs/café.md" + + +def _git(*args) -> str: + return subprocess.run(["git", *args], check=True, capture_output=True, + text=True).stdout + + +class NonAsciiUntrackedPaths(unittest.TestCase): + def setUp(self): + self._cwd = os.getcwd() + self._tmp = tempfile.TemporaryDirectory() + os.chdir(self._tmp.name) + _git("init", "-q") + _git("config", "user.email", "t@example.com") + _git("config", "user.name", "t") + _git("config", "commit.gpgSign", "false") + Path("tracked.txt").write_text("v1\n") + _git("add", ".") + _git("commit", "-q", "-m", "base") + + def tearDown(self): + os.chdir(self._cwd) + self._tmp.cleanup() + + def test_untracked_paths_returns_the_real_name(self): + Path("docs").mkdir() + Path(CAFE).write_text("x\n") + self.assertEqual(loop.untracked_paths(), {CAFE}) + + def test_kept_tree_marks_a_new_non_ascii_file_intent_to_add(self): + head_before = loop.git("rev-parse", "HEAD") + untracked_before = loop.untracked_paths() + Path("docs").mkdir() + Path(CAFE).write_text("x\n") + Path("tracked.txt").write_text("v2\n") + + loop.retain_tree_after_refusal( + head_before, Path("events.jsonl"), untracked_before) + + self.assertEqual(loop.untracked_paths(), set()) + # Intent-to-add: in the index (ls-files), still uncommitted. + self.assertIn(CAFE, _git("ls-files", "-z").split("\0")) + self.assertEqual(loop.git("rev-parse", "HEAD"), head_before) + self.assertEqual(Path(CAFE).read_text(), "x\n") + + +if __name__ == "__main__": + unittest.main()