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
8 changes: 4 additions & 4 deletions core/team/worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def _install_team_exclude(self) -> None:
info = common / "info"
info.mkdir(parents=True, exist_ok=True)
exclude = info / "exclude"
existing = exclude.read_text() if exclude.exists() else ""
existing = exclude.read_text(encoding="utf-8") if exclude.exists() else ""
if _EXCLUDE_BEGIN in existing:
return # already installed
block = "\n".join((_EXCLUDE_BEGIN, *_TEAM_EXCLUDE, _EXCLUDE_END))
sep = "" if not existing or existing.endswith("\n") else "\n"
exclude.write_text(f"{existing}{sep}{block}\n")
exclude.write_text(f"{existing}{sep}{block}\n", encoding="utf-8")

def create(self, worker_id: str) -> str:
"""Create an isolated worktree on a fresh branch for ``worker_id``."""
Expand Down Expand Up @@ -241,10 +241,10 @@ def _remove_team_exclude(self) -> None:
exclude = common / "info" / "exclude"
if not exclude.exists():
return
text = exclude.read_text()
text = exclude.read_text(encoding="utf-8")
if _EXCLUDE_BEGIN not in text:
return
before, _, rest = text.partition(_EXCLUDE_BEGIN)
_, _, after = rest.partition(_EXCLUDE_END)
cleaned = (before.rstrip("\n") + "\n" + after.lstrip("\n")).strip("\n")
exclude.write_text(cleaned + "\n" if cleaned else "")
exclude.write_text(cleaned + "\n" if cleaned else "", encoding="utf-8")
17 changes: 17 additions & 0 deletions tests/test_team_worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,20 @@ def test_team_exclude_is_local_idempotent_and_reverted(tmp_path):
text = exclude.read_text()
assert _EXCLUDE_BEGIN not in text # our block gone
assert "user-secret.txt" in text # the user's rule preserved


def test_team_exclude_keeps_non_ascii_user_rules(tmp_path):
m = _mgr(tmp_path)
m.ensure_base()
exclude = m.base / ".git" / "info" / "exclude"
m.cleanup_all()
# Users write their own exclude rules as UTF-8. Such a rule must survive
# install/remove whatever the locale encoding is: cp1252, the Windows
# default, cannot even decode these bytes.
original = "数据/\n".encode() + exclude.read_bytes()
exclude.write_bytes(original)

m.ensure_base()
assert "数据/" in exclude.read_text(encoding="utf-8")
m.cleanup_all()
assert exclude.read_bytes().splitlines() == original.splitlines()