fix(git): use compatible git commands for older git versions#385
Conversation
This commit updates git commands to be compatible with older versions of Git (e.g. 2.10.1). Specifically, it replaces branch --show-current with rev-parse --abbrev-ref HEAD and uses the GIT_OPTIONAL_LOCKS environment variable instead of the --no-optional-locks flag.
Use symbolic-ref --short HEAD for branch detection in the GitBranch widget and review cache so unborn branches keep rendering their branch name while detached HEAD still resolves as no branch. Update git command assertions after replacing --no-optional-locks argv usage with GIT_OPTIONAL_LOCKS=0 in the exec environment, including shared coverage for widgets and git remote helpers. Add a small test helper for asserting git exec options without depending on the full process environment. Verification: bun test; bun run lint; git diff --check
|
Thanks for the compatibility fix. I reviewed this against the PR intent and made one follow-up commit: The main issue was that the branch left the test suite failing: I also replaced I'll publish this in the next release. |
Description
This PR improves Git version compatibility by replacing newer Git flags and commands with backwards-compatible equivalents. This prevents
ccstatuslinefrom erroneously falling back to the "no git" state when run on systems with older Git installations (such as Git 2.10.1 built into some macOS environments).Changes Made
--no-optional-locksCLI argument withGIT_OPTIONAL_LOCKS=0environment variable.--no-optional-locksflag was introduced in Git 2.15.0 and causes older Git versions to fail immediately withUnknown option. Passing this configuration via the environment variable achieves the exact same lock-avoidance behavior in newer Git versions while being safely ignored by older versions.git branch --show-currentwithgit rev-parse --abbrev-ref HEAD.--show-currentflag was introduced in Git 2.22.0.rev-parse --abbrev-ref HEADis broadly compatible. Added a fallback to ensure it returnsnullwhen in a detachedHEADstate (matching the behavior of--show-current).Testing
bun run verifyandbun test.