Skip to content
This repository was archived by the owner on Sep 23, 2026. It is now read-only.
Closed
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
fix: handle non-UTF-8 filenames in git ls-files on Windows
On Chinese Windows systems the default subprocess encoding is GBK,
which crashes on UTF-8 filenames from git ls-files. Pass explicit
encoding="utf-8" and errors="replace" to all three subprocess.run
calls in file_filter.py.

Also guard _parse_ls_files_output against None stdout so the
AttributeError ('NoneType' has no attribute 'split') doesn't
propagate when the subprocess fails silently.

Fixes #1866
  • Loading branch information
he-yufeng committed Apr 15, 2026
commit 83396fa9ae9411998467ca37b566722ec7220eb8
12 changes: 10 additions & 2 deletions src/kimi_cli/utils/file_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ def git_index_mtime(root: Path) -> float | None:
return None


def _parse_ls_files_output(stdout: str, *, filter_ignored: bool = True) -> list[str]:
def _parse_ls_files_output(stdout: str | None, *, filter_ignored: bool = True) -> list[str]:
"""Parse NUL-delimited ``git ls-files -z`` output into paths with synthesised dirs.

When *filter_ignored* is *True*, paths whose segments match
``is_ignored()`` are excluded so that tracked ``node_modules/``,
``vendor/``, etc. do not pollute completion candidates.
"""
if not stdout:
return []
paths: list[str] = []
seen_dirs: set[str] = set()
ignored_prefixes: set[str] = set()
Expand Down Expand Up @@ -193,9 +195,11 @@ def _git_deleted_files(root: Path, scope: str | None = None) -> set[str]:
cwd=root,
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
timeout=_GIT_LS_FILES_TIMEOUT,
)
if result.returncode == 0:
if result.returncode == 0 and result.stdout:
return {e for e in result.stdout.split("\0") if e}
except Exception:
pass
Expand Down Expand Up @@ -236,6 +240,8 @@ def list_files_git(
cwd=root,
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
timeout=_GIT_LS_FILES_TIMEOUT,
)
if result.returncode != 0:
Expand Down Expand Up @@ -265,6 +271,8 @@ def list_files_git(
cwd=root,
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
timeout=_GIT_LS_FILES_TIMEOUT,
)
if others.returncode == 0:
Expand Down
Loading