Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.d/3616-a-guard-refusal-that-keeps-the-tree-no-l.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 6 additions & 2 deletions specfuse/loop/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
74 changes: 74 additions & 0 deletions tests/test_untracked_paths_non_ascii.py
Original file line number Diff line number Diff line change
@@ -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()