Bug Description
gtr cd fails with a zsh locale/collation error when the worktree branch name contains a substring that can be interpreted as a character range in reverse order (e.g., x-c in fix-cron).
$ gtr cd fix-cron
gtr: range-endpoints of 'x-c' are in reverse collating sequence order
Root Cause
Zsh interprets character sequences like x-c as glob bracket expression ranges (similar to [x-c]). Under en_US.UTF-8 locale, x has a higher collation value than c, making the range x-c invalid (reverse order). This happens somewhere during the processing of the branch name in the shell function generated by git gtr init zsh.
The error is locale-dependent — under the C locale, character ranges follow strict ASCII byte order and the error does not occur.
Reproduction
Environment:
- macOS (Darwin), zsh with oh-my-zsh + powerlevel10k
- Locale:
LANG=en_US.UTF-8
- gtr version: 2.3.1
- Shell integration:
eval "$(git gtr init zsh)" in .zshrc
Steps:
- Create a worktree with a hyphen in the name where the characters around the hyphen form a reverse range:
- Try to cd into it:
- Observe the error:
gtr: range-endpoints of 'x-c' are in reverse collating sequence order
Branch names that would trigger this: any name where a hyphen creates a reverse character range, e.g.:
fix-cron (x-c → x > c)
fix-auth (x-a → x > a)
test-app (t-a → t > a)
update-branch (e-b → e > b)
Workaround: Setting LC_ALL=C before running the command:
LC_ALL=C gtr cd fix-cron # works
Or permanently in ~/.zshrc:
Suggested Fix
The shell function generated by git gtr init zsh should be resilient to locale settings. A few options:
Option 1: Use emulate -L zsh at the top of the function (Recommended)
This resets all zsh options to defaults within the function scope, preventing locale-dependent glob interpretation:
gtr() {
emulate -L zsh
# ... rest of function
}
emulate -L zsh is the standard idiom for zsh functions that need predictable behavior regardless of user configuration. The -L flag makes it local to the function scope.
Option 2: Set LC_COLLATE=C locally within the function
gtr() {
local LC_COLLATE=C
# ... rest of function
}
Option 3: Disable globbing for the function
gtr() {
setopt local_options no_glob_subst no_bad_pattern
# ... rest of function
}
Option 1 (emulate -L zsh) is the most robust as it protects against all zsh option-related edge cases, not just this one.
Bug Description
gtr cdfails with a zsh locale/collation error when the worktree branch name contains a substring that can be interpreted as a character range in reverse order (e.g.,x-cinfix-cron).Root Cause
Zsh interprets character sequences like
x-cas glob bracket expression ranges (similar to[x-c]). Underen_US.UTF-8locale,xhas a higher collation value thanc, making the rangex-cinvalid (reverse order). This happens somewhere during the processing of the branch name in the shell function generated bygit gtr init zsh.The error is locale-dependent — under the
Clocale, character ranges follow strict ASCII byte order and the error does not occur.Reproduction
Environment:
LANG=en_US.UTF-8eval "$(git gtr init zsh)"in.zshrcSteps:
gtr cd fix-crongtr: range-endpoints of 'x-c' are in reverse collating sequence orderBranch names that would trigger this: any name where a hyphen creates a reverse character range, e.g.:
fix-cron(x-c→ x > c)fix-auth(x-a→ x > a)test-app(t-a→ t > a)update-branch(e-b→ e > b)Workaround: Setting
LC_ALL=Cbefore running the command:Or permanently in
~/.zshrc:export LC_COLLATE=CSuggested Fix
The shell function generated by
git gtr init zshshould be resilient to locale settings. A few options:Option 1: Use
emulate -L zshat the top of the function (Recommended)This resets all zsh options to defaults within the function scope, preventing locale-dependent glob interpretation:
emulate -L zshis the standard idiom for zsh functions that need predictable behavior regardless of user configuration. The-Lflag makes it local to the function scope.Option 2: Set
LC_COLLATE=Clocally within the functionOption 3: Disable globbing for the function
Option 1 (
emulate -L zsh) is the most robust as it protects against all zsh option-related edge cases, not just this one.