crewAIInc / crewAIInc/crewAI

[BUG] Deploy initial-commit step reads .git/info/exclude with the locale encoding and crashes on Windows for UTF-8 patterns

Open Beginner friendly
#7,585 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
58.8k
Forks
8.5k
Avg merge
1d 15h
Merged PRs (30d)
109

Description

Description

Repository._ensure_initial_commit_excludes in lib/cli/src/crewai_cli/git.py (used by Repository.initialize / create_initial_commit_if_needed, the crewai deploy path that auto-creates an initial commit) reads and rewrites .git/info/exclude with Path.read_text() / Path.write_text() and no encoding. Git stores ignore patterns as raw UTF-8 bytes regardless of platform, but on Windows Python decodes them as cp1252. Any pattern containing a code point whose UTF-8 encoding includes 0x81/0x8D/0x8F/0x90/0x9D (curly quotes, many CJK characters, Đ, Ł, Ё) raises UnicodeDecodeError and aborts the deploy. On non-UTF-8 CJK code pages (cp932, cp936) ordinary filenames hit this. The rewrite also converts the file's line endings to CRLF on Windows.

Steps to Reproduce

On Windows with the default cp1252 locale:

import os, subprocess, tempfile
from crewai_cli.git import Repository

d = tempfile.mkdtemp()
subprocess.run(["git", "init", "-q", d], check=True)
excl = os.path.join(d, ".git", "info", "exclude")
with open(excl, "ab") as f:
    f.write("notes \u201cdraft\u201d.md\n".encode("utf-8"))   # curly quotes -> bytes E2 80 9C / E2 80 9D
Repository(path=d, fetch=False)._ensure_initial_commit_excludes()
Expected behavior

Existing patterns are preserved byte-for-byte and the CrewAI block is appended, on every platform, with the file's line endings left alone.

Screenshots/Code snippets
  File "...\lib\cli\src\crewai_cli\git.py", line 166, in _ensure_initial_commit_excludes
    existing = exclude_file.read_text() if exclude_file.exists() else ""
  File "...\Lib\encodings\cp1252.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 6: character maps to <undefined>
Operating System

Windows 11

Python Version

3.13

crewAI Version

main @ bbcebffbf (1.15.22+)

crewai-tools Version

same workspace commit

Proposed fix

Read and write the file as UTF-8 (encoding="utf-8"), and write with newline="\n" so the rewrite does not change line endings. PR with a regression test follows.

Disclosure per CONTRIBUTING: this report and the fix were prepared with the help of an AI coding assistant; please apply the llm-generated label.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/cli/src/crewai_cli/git.py at Repository._ensure_initial_commit_excludes, used by Repository.initialize and create_initial_commit_if_needed. Reproduce the Windows failure with the issue's UTF-8 exclude pattern, then add regression coverage for preserving UTF-8 content and existing line endings. Done means deploy initialization handles the file without decoding errors or changing its existing patterns and line endings.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, python
Domain
cli, devtools
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.