Repository navigation
fix(git): handle non-ASCII branches over legacy pipes in create_new_feature_branch.py - #5475
Conversation
…eature_branch.py On redirected Windows pipes (cp1252) or non-UTF-8 locales, create_new_feature_branch.py failed on non-ASCII branches in three places: --json used ensure_ascii=False and raised UnicodeEncodeError on stdout, stderr and text-mode prints raised UnicodeEncodeError when reporting the branch name, and git subprocess calls used text=True without encoding="utf-8" so existing UTF-8 branches containing cp1252-undefined bytes such as 0x90 left result.stdout as None and crashed _git_lines() with AttributeError. Emit --json with default ensure_ascii=True (matching github#5048, github#5466, and resolve_tasks.py), fall back to backslashreplace when writing text lines to a narrow stdio encoding, decode git subprocess output as UTF-8 with replacement, and bump the git extension to 1.0.7. Fixes github#5474 Assisted-by: OpenCode (model: Gemini 4 Carbon, autonomous)
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified for the Git extension’s Unicode branch-creation update.
No open issues 🎉
What changed in this PR
Fixes #5474 by making the Git extension’s Python branch-creation helper handle non-ASCII names over legacy-encoded pipes, complementing earlier core Python and PowerShell fixes.
Changes:
- Emits ASCII-safe JSON, adds encoding fallback for text output, and explicitly decodes Git output as UTF-8.
- Adds regression coverage for Unicode branch creation, reuse, numbering, and error handling under cp1252 pipes.
- Bumps the Git extension to
1.0.7.
The PR reports before-and-after regression results; these were not independently rerun.
| File | Description |
|---|---|
tests/extensions/git/test_git_extension.py |
Updates the expected manifest version to 1.0.7. |
tests/extensions/git/test_git_extension_python_parity.py |
Adds legacy-pipe Unicode regression tests. |
extensions/git/scripts/python/create_new_feature_branch.py |
Handles output encoding and UTF-8 Git subprocess decoding. |
extensions/git/extension.yml |
Bumps the extension version to 1.0.7. |
extensions/catalog.json |
Synchronizes the catalog version with the manifest. |
Review effort: Balanced (adaptive)
|
Please fix test & lint errors |
Bump git extension version to 1.0.8 following github#5124 (1.0.7 on main). Assisted-by: OpenCode (model: Gemini 4 Carbon, autonomous)
|
Merged On the previous CI run ( AI disclosure: posted on behalf of @adityajai119 by OpenCode (model: Gemini 4 Carbon, autonomous mode), which inspected the CI job log, merged |
Description
Fixes #5474.
Python counterpart to #5466 (
create-new-feature-branch.ps1) and #5048 (core Python helpers). Whenextensions/git/scripts/python/create_new_feature_branch.pyruns over redirected Windows pipes (cp1252) or non-UTF-8 locales with non-ASCII branch names (fromGIT_BRANCH_NAME,branch_prefix, or existing UTF-8 feature branches created by corecreate-new-featuresince #4780), three paths fail with unhandled tracebacks:--jsoncallsprint(json.dumps(payload, ensure_ascii=False, separators=(",", ":"))), raisingUnicodeEncodeErroroncp1252stdout instead of emitting\uXXXXASCII escapes likeresolve_tasks.pyand the core Python helpers._err()hints (# To persist: ..., duplicate-branch errors, no-git warnings) and text-modeprint()calls raiseUnicodeEncodeErroron narrowsys.stderr/sys.stdoutstreams after Git has already created the branch._git_lines()andsubprocess.run(["git", ...], capture_output=True, text=True)omitencoding="utf-8", so existing branches containing bytes undefined incp1252(such as0x90in003-后台信息架构) causesubprocess._readerthreadto fail withUnicodeDecodeError, leavingresult.stdoutasNoneand crashing_git_lines()withAttributeError: 'NoneType' object has no attribute 'splitlines'even when creating an ASCII branch.This PR:
--jsonincreate_new_feature_branch.pyto defaultensure_ascii=True(json.dumps(payload, separators=(",", ":"))) so JSON output is pure ASCII and decodes back to the exactBRANCH_NAMEandFEATURE_NUMunder any pipe encoding._err()and text-mode stdout lines through a helper that falls back toerrors="backslashreplace"only when the target stream cannot encode a character.encoding="utf-8", errors="replace"tosubprocess.run(["git", ...])calls increate_new_feature_branch.pyand guards(result.stdout or "").splitlines().gitextension from1.0.6to1.0.7inextensions/git/extension.yml,extensions/catalog.json, and its manifest test.Testing
.\.venv\Scripts\specify.exe --help.\.venv\Scripts\python.exe -m pytest tests/extensions/git tests/contract tests/test_timestamp_branches.py -q(308 passed, 177 skippedwith both PowerShell 7.7.0 and Windows PowerShell 5.1.26100.9836 active; skips are Bash and POSIX-only cases)Added
TestCreateFeatureBranchPythonLegacyPipe(6 test cases, isolated with an emptyGIT_CONFIG_GLOBALandGIT_CONFIG_NOSYSTEM=1plusPYTHONIOENCODING=cp1252):--json --dry-run,--jsonbranch creation, and--json --allow-existing-branchwith Latin-1 (é), CJK (后台), and non-BMP (U+1F680) characters inBRANCH_NAMEandFEATURE_NUM, plus sequential auto-numbering and text mode when003-后台信息架构already exists underLC_ALL=C. All 6 cases fail onmain(UnicodeEncodeErrorandAttributeError: 'NoneType' object has no attribute 'splitlines') and pass with this fix.--allow-existing-branchon an existing non-ASCII branch and passing an overlong UTF-8GIT_BRANCH_NAME(> 244bytes) exit1cleanly with empty stdout and no traceback undercp1252.Also verified
.github/scripts/check_extension_version_bump.py origin/main HEAD(Extension version guard: all invariants hold.),uvx ruff@0.15.0 check src tests extensions/git/scripts/python(All checks passed!), andgit diff origin/main...HEAD --check(clean).AI Disclosure
AI disclosure: OpenCode with Gemini 4 Carbon (max reasoning effort, autonomous agent mode), acting on behalf of @adityajai119, found and reproduced the bug, wrote the fix and regression tests, ran all checks above, and drafted this PR description. The commit carries an
Assisted-by: OpenCode (model: Gemini 4 Carbon, autonomous)trailer.