Skip to content

fix(git): keep Unicode words in git extension branch names (#5553) - #5559

Open
ckr-git wants to merge 3 commits into
github:mainfrom
ckr-git:fix/5553-git-extension-unicode-branch-names
Open

ckr-git wants to merge 3 commits into
github:mainfrom
ckr-git:fix/5553-git-extension-unicode-branch-names

Conversation

@ckr-git

@ckr-git ckr-git commented Nov 24, 2026

Copy link
Copy Markdown

Description

Fixes #5553.

The git extension's branch scripts (bash, PowerShell, Python) still sanitized names with [^a-z0-9]. With the git extension installed, the before_specify hook turned a CJK-only description into the branch 001-, while the core script created specs/001-添加待办事项/. #4780 fixed the core scripts under the UTF-8 naming policy from #4574 and left extensions/git out of scope. This PR ports the same policy to the three extension twins.

Description Before (sh / py / ps) After (all three)
添加待办事项 001- / 001- / error 001-添加待办事项
支持 OAuth2 登录 001-oauth2 001-支持-oauth2-登录
Ünïcödé café 001-caf 001-Ünïcödé-café
Add API for 用户 DB 001-api-db 001-api-用户-db
--short-name "待办 事项!" 001- 001-待办-事项
Add the user login (ASCII) 001-user-login 001-user-login (unchanged)

Changes:

  • Naming. Unicode letters and decimal digits are kept, and only ASCII letters are lowercased. Short non-ASCII words are kept, because CJK words are often two characters. The logic mirrors core create-new-feature.*, and the extension output now matches the core script for the inputs above.
  • {author} and {app}. These template tokens stay ASCII-only. Each script has a separate ASCII cleaner for them, so their behavior does not change.
  • Bash. Unicode is classified through Python, and a UTF-8 locale is selected the same way as in core create-new-feature.sh. The script probes for Python itself (SPECKIT_PYTHON_EXECUTABLE, python3, python, py -3), so it still works when only git-common.sh is loaded or core common.sh predates _python3_command. An explicit non-UTF-8 LC_ALL with Unicode input gives a clear error. ASCII input stays shell-only and needs no Python.
  • Bash truncation. Names are truncated to 244 bytes by whole UTF-8 characters, dropping bytes under LC_ALL=C. On Git Bash for Windows (MSYS, 16-bit wchar_t), the locale-aware ${var%?} split a character outside the BMP when an odd-length ASCII prefix came first. For example, a followed by 70 copies of 𠀀 produced a broken 244-byte name ending in ➳. Core fit_branch_name has the same problem: with that input it returns a name ending in U+FFFD on Git Bash. Core is left unchanged to keep this PR in scope; I can follow up separately if you want.
  • PowerShell. The fallback join is now wrapped in @(), so punctuation-only input such as !!! no longer throws from [string]::Join($null). Core already does this. On main the same crash also blocked every CJK-only description. Truncation drops whole surrogate pairs.
  • Version. The git extension is bumped to 1.0.10 in extension.yml and catalog.json, and the README documents the naming.

Known limitation, inherited from core: Windows PowerShell 5.1 (.NET Framework) uses older Unicode tables than Python 3.12. Characters added in recent Unicode versions, such as U+9FEF, can therefore classify differently. Core create-new-feature.ps1 behaves the same way.

Testing

All commands below were run by Claude Code on my machine. Environment: Windows 11 zh-CN (code page 936), Python 3.12.10, Windows PowerShell 5.1, Git Bash 5.2. Linux runs used Ubuntu 24.04 on WSL2 with Python 3.12.3.

  • Tested locally with .\.venv\Scripts\specify.exe --help.
  • Ran the affected tests: python -m pytest tests/extensions/git -q.
    • Linux (Ubuntu 24.04 on WSL2): 179 passed, 110 skipped (pwsh is not installed there, so the PowerShell cases skip).
    • Linux, new tests against main's scripts: all 13 new bash/Python cases fail. They are cjk_only, cjk_mixed, cjk_acronyms, accented, cjk_short_name, a real branch checkout, {author}/{app} staying ASCII (from a project directory named Café 应用), Python lookup with core / git-common.sh only / an older core common.sh without _python3_command, and three truncation cases.
    • Windows with Git Bash (MSYS) as bash: the full run gave 202 passed, 3 failed, 84 skipped. Two of the failures were the astral truncation cases, caused by the test helper decoding the Python twin's cp936 stderr; after the _run_py fix below, both pass on a re-run. The remaining failure, test_git_branch_name_override_persist_hint_matches_bash, also fails on main (the git error message embeds the bash and Python temp paths, which differ).
    • Windows default (bash resolves to the WSL launcher, so bash cases skip): the 7 new Windows PowerShell 5.1 tests pass, and all 7 fail against main's script. The 5 other failures in this suite are in initialize-repo tests and also fail on main. Their assertions expect English PowerShell output, and the zh-CN host prints 警告:.
    • Test helpers: _run_bash and _branch_state now decode as UTF-8, and _run_py replaces undecodable bytes. Without this, a cp936 or cp1252 console decoded the UTF-8 branch names wrongly before the tests could compare them.
  • Tested with a sample project. Ran specify init "待办 应用" --integration claude --script ps --extension git in a directory with a Chinese name and a space. Then ran the git extension and core feature scripts in PowerShell 5.1 and Git Bash with Chinese descriptions. The branch and specs/ directory names now match.
  • On Git Bash, checked six truncation inputs (a + 𠀀×70, ab + 𠀀×70, 汉×100, ab + 汉×100, é×130, 𠀀×70). All three twins produce the same name of 244 bytes or fewer.
  • Ruff reports no new findings on the changed Python files. shellcheck --severity=error (as in CI) passes; overall shellcheck findings went from 9 to 8.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: Claude Code (model: Claude Opus 5.5, extended thinking, human-supervised) found and reproduced the bug and generated the code and tests in this PR. Two review subagents, also Claude models, reviewed the diff for correctness and for security and scope. One of them found the Git Bash truncation bug, which Claude Code then reproduced and fixed. I reviewed the full diff before filing. The commit carries an Assisted-by: trailer.

The git extension's branch scripts still sanitized names with [^a-z0-9],
so a CJK-only description produced the branch 001- while the core script
created specs/001-<name>/. Port the core scripts' UTF-8 naming policy
(github#4574, github#4780) to the bash, PowerShell, and Python twins:

- keep Unicode letters and decimal digits; lowercase ASCII letters only
- keep short non-ASCII words (CJK words are often two characters)
- leave {author} and {app} template tokens ASCII-only, as before
- bash: classify Unicode via Python and pick a UTF-8 locale, mirroring
  core create-new-feature.sh; truncate to 244 bytes by whole UTF-8
  characters, since MSYS/Cygwin bash's 16-bit wchar_t lets ${var%?}
  split characters outside the BMP
- PowerShell: guard the fallback join with @() so punctuation-only input
  no longer throws on [string]::Join($null); drop whole surrogate pairs
  when truncating

Bump the git extension to 1.0.10.

Assisted-by: Claude Code (model: Claude Opus 5.5, supervised)
@ckr-git
ckr-git requested a review from mnriem as a code owner November 24, 2026 18:13
Copilot AI adaptive review requested due to automatic review settings November 24, 2026 18:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new missing-Python and non-UTF-8 locale failure paths lack extension-specific tests verifying diagnostics, nonzero exits, empty JSON stdout, unchanged Git refs, and successful ASCII controls.

1 open issue
What changed in this PR

Fixes #5553 by extending the core Unicode naming policy to the git extension, keeping non-Latin branch names aligned with specs/ directory names.

Changes:

  • Preserve Unicode letters and decimal digits across all three scripts while keeping {author} and {app} ASCII-only.
  • Handle UTF-8 truncation safely and prevent PowerShell’s punctuation-only fallback from throwing.
  • Add regression coverage, document naming behavior, and bump the extension to 1.0.10.

AI-generated review by GitHub Copilot (model: unknown; autonomous), for the review requester. Source inspection only; tests were not run.

File Description
tests/​extensions/​git/​test_git_extension.py Adds PowerShell Unicode, truncation, and fallback tests.
tests/​extensions/​git/​test_git_extension_python_parity.py Adds Bash/Python Unicode parity and interpreter-discovery tests.
extensions/​git/​scripts/​python/​create_new_feature_branch.py Preserves Unicode words and separates ASCII token cleaning.
extensions/​git/​scripts/​powershell/​create-new-feature-branch.ps1 Adds Unicode naming, safe fallback, and surrogate-aware truncation.
extensions/​git/​scripts/​bash/​create-new-feature-branch.sh Adds Unicode classification, prerequisite checks, and character-safe truncation.
extensions/​git/​README.md Documents Unicode naming and Bash prerequisites.
extensions/​git/​extension.yml Bumps the extension version to 1.0.10.
extensions/​catalog.json Updates the catalog version to 1.0.10.

Review effort: Balanced (adaptive)

Comment on lines +246 to +248
if [ "${#python_cmd[@]}" -eq 0 ]; then
echo "Error: Python 3 is required to create a Unicode branch name" >&2
return 1
@mnriem

mnriem commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

- bash: quote the SPECIFY_FEATURE persist hint with shell_quote, as core
  create-new-feature.sh does, instead of printf %q. Outside a UTF-8
  locale (the macOS default) %q escaped each non-ASCII byte as $'\ooo',
  so stderr was not valid UTF-8 and test_unicode_branch_is_created_and_
  checked_out failed on macOS CI.
- Python: quote the POSIX hint with shlex.quote to stay byte-identical
  with the bash twin.
- tests: cover Unicode names with no Python 3 available and with an
  explicit LC_ALL=C/POSIX (clear error, exit 1, empty stdout, refs
  unchanged, ASCII still succeeds), and the persist hint without a
  UTF-8 locale. Addresses the Copilot review.

Assisted-by: Claude Code (model: Claude Opus 5.5, supervised)
Copilot AI adaptive review requested due to automatic review settings November 25, 2026 07:05
@ckr-git

ckr-git commented Nov 25, 2026

Copy link
Copy Markdown
Author

Posted on behalf of @ckr-git by Claude Code (model: Claude Opus 5.5, extended thinking, human-supervised). Claude Code wrote the fix, the tests, and this summary; @ckr-git reviewed them before posting.

Round 1, commit 22299d8.

Copilot feedback (missing-Python and non-UTF-8 locale paths). Added bash tests for both failure paths, for a Unicode description and for --short-name:

  • No Python 3: python3, python, and py are shimmed to fail. The script exits 1 with "Python 3 is required to create a Unicode branch name", prints nothing on stdout, and leaves git refs unchanged. An ASCII description still succeeds under the same shims.
  • Explicit LC_ALL=C and LC_ALL=POSIX: the script exits 1 with "A UTF-8 locale is required ... LC_ALL=", with empty stdout and refs unchanged. ASCII still succeeds.

macOS CI failure. test_unicode_branch_is_created_and_checked_out failed on macOS because bash's stderr was not valid UTF-8. The persist hint used printf %q, which outside a UTF-8 locale escapes each non-ASCII byte as $'\ooo'. The hint now uses shell_quote, copied from core create-new-feature.sh, and the Python twin uses shlex.quote, as core create_new_feature.py does. Both produce identical output. A new test runs with an empty locale and checks the hint is export SPECIFY_FEATURE='001-添加待办事项'. The Windows jobs in that run were cancelled after the macOS failure, not failed.

Results with this commit:

  • Linux: 184 passed, 110 skipped. Against main's scripts, all 18 new bash/Python cases fail.
  • Windows with Git Bash: 209 passed, 1 failed. The failure is test_git_branch_name_override_persist_hint_matches_bash, which also fails on main locally.
  • shellcheck --severity=error and ruff report nothing new.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The git-extension tests lack coverage for Unicode decimal-digit preservation and rejection of other number categories across the three implementations, including Windows PowerShell 5.1.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Low severity Add Unicode number-category coverage to git-extension tests

extensions/​git/​scripts/​python/​create_new_feature_branch.py:341

The new decimal-digit policy has no coverage in the git-extension tests: the added Unicode cases all use letters. Please port the core tests/test_create_new_feature_python_parity.py::test_unicode_number_categories_match cases into the extension tests, checking that x٥ and x𝟘 are retained while x² and xⅫ become x. Run these cases across the three twins, including Windows PowerShell 5.1, so decimal-digit preservation and rejection of other number categories are both protected.

AI-generated review for the requesting reviewer by GitHub Copilot (model: unknown; autonomous mode; code inspection).

Review effort: Balanced (adaptive)

Port core's test_unicode_number_categories_match cases to the git
extension for bash, Python, and Windows PowerShell 5.1: decimal digits
(x٥, x𝟘) are kept, while other number categories (x², xⅫ) become
separators. Addresses the Copilot review.

Assisted-by: Claude Code (model: Claude Opus 5.5, supervised)
Copilot AI adaptive review requested due to automatic review settings November 25, 2026 07:36
@ckr-git

ckr-git commented Nov 25, 2026

Copy link
Copy Markdown
Author

Posted on behalf of @ckr-git by Claude Code (model: Claude Opus 5.5, extended thinking, human-supervised). Claude Code wrote the tests and this summary; @ckr-git reviewed them before posting.

Round 2, commit 5565bde.

Copilot feedback (Unicode number categories). Ported the core test_unicode_number_categories_match cases to the git extension. They run for bash and Python (parity) and separately for Windows PowerShell 5.1 (and pwsh where available):

  • x٥ → 001-x٥ and x𝟘 → 001-x𝟘 (decimal digits are kept, including outside the BMP).
  • x² → 001-x and xⅫ → 001-x (other number categories become separators).

The scripts already behaved this way, so this commit adds tests only. Against main's scripts, the two decimal-digit cases fail in all three twins and the two separator cases pass, as expected.

The earlier Copilot item (missing-Python and non-UTF-8 locale paths) was addressed in 22299d8; see the round 1 summary above.

Results with this commit:

  • Linux: 188 passed, 118 skipped.
  • Windows PowerShell 5.1: the 4 new cases pass. The full git extension suite has no new failures; the 5 existing initialize-repo failures on a zh-CN host also fail on main.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human review is needed to assess test-coverage gaps around Unicode case folding and successful configured-interpreter and launcher fallback paths.

1 open issue

Review effort: Balanced (adaptive)

@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 25, 2026
@mnriem
mnriem requested a balanced review from Copilot November 25, 2026 15:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Under limited output encodings, Unicode branch names become literal escapes in the persistence hint, so copying it selects a nonexistent feature instead of the newly created branch.

2 open issues

Review effort: Balanced

return f"export {var_name}={escaped_value}"
# shlex.quote matches the bash twin's shell_quote byte for byte, as in
# core create_new_feature.py.
return f"export {var_name}={shlex.quote(value)}"
@mnriem

mnriem commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: git extension drops non-Latin feature descriptions, creating branches named 001-

3 participants