Skip to content

Fix autocd support for git worktrees - #364

Open
pellejacobs wants to merge 1 commit into
scmbreeze:mainfrom
pellejacobs:fix-worktree-autocd
Open

pellejacobs wants to merge 1 commit into
scmbreeze:mainfrom
pellejacobs:fix-worktree-autocd

Conversation

@pellejacobs

@pellejacobs pellejacobs commented May 5, 2026

Copy link
Copy Markdown

#353 introduced support for git worktrees. However, autocd seems broken on unix systems as bash variables
are case sensitive on unix.

Therefore, when trying to cd into a worktree through gco 1, the error fatal: 'worktree-name' is already checked out at '/path/to/worktree.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed environment variable reference in git branch checkout shortcuts, ensuring numbered shortcuts correctly resolve target branches.

scmbreeze#353 introduced support for git worktrees. However, autocd seems broken on unix systems as bash variables
are case sensitive on unix.

Therefore, when trying to cd into a worktree through `gco 1`, the error `fatal: 'worktree-name' is already checked out at '/path/to/worktree`.
@coderabbitai

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8f95cf1c-01b3-410e-8181-06f5b8711141

📥 Commits

Reviewing files that changed from the base of the PR and between 0074697 and 29396f5.

📒 Files selected for processing (1)
  • lib/git/branch_shortcuts.sh

📝 Walkthrough

Walkthrough

A single variable reference is corrected in the git branch shortcuts function. The _scmb_git_checkout_shortcuts function now uses GIT_ENV_CHAR instead of git_env_char when constructing the branch variable lookup key for numbered checkout operations.

Changes

Git Checkout Shortcuts Variable Reference

Layer / File(s) Summary
Variable Reference Fix
lib/git/branch_shortcuts.sh
In _scmb_git_checkout_shortcuts, branch_var assignment changes from "${git_env_char}$1" to "${GIT_ENV_CHAR}$1", correcting the environment variable prefix used for branch lookups.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A typo in the git commands, oh what a sight,
git_env_charGIT_ENV_CHAR—now it's right!
One humble variable, lowercase to caps so true,
The branch shortcuts hop and skip, fresh and new. 🌿✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix autocd support for git worktrees' directly addresses the PR's main objective: fixing a regression that broke autocd functionality for git worktrees by correcting case-sensitivity in bash variable references.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mmcrockett

Copy link
Copy Markdown
Contributor

Dang should've looked in PRs first but I also fixed more broadly - #366 - I'm not sure it's just the upcasing since in my investigation the $1 only accidentally works for gco 1 but not any other number. It also doesn't use the built-in function in scm_breeze that handles the branch lookup well.

ghthor added a commit that referenced this pull request Jul 23, 2026
…e :) (#371)

#### Problem
I wanted to get git worktrees into an scm breez-ish way and along the
way I found a bug-ish thing in interactions between ClaudeCode and scm
breeze and also added some niceties to the repo.

#### What
- Full worktree support in scm breezish way - `gwt` `gwta` `gwtr`
aliases, you can pass `gco 2` and it knows to cd to the directory for
you
- Concept of worktree `sibling` or `feature` or just a different
directory you want as default instead of `git` defaulting to directory
you're in (more documentation near the setting in code)
- Non-private `_` fns moved to `__` to help with a ClaudeCode quirk
- Docker 'testing' helper so I could isolate from my local scrips more
easily - helps with multiple shell types (bash and zsh) testing
- Pulled in an outstanding fix for `git rev-parse --show-toplevel`
- Fixed several worktree bugs in scm breeze, ie. #364 is accidentally
fixed by my refactors and I also intentionally fixed where a `/` in the
name didn't work correctly.

#### Why
- I'm using worktrees more with ai and I love scm breeze
features/shortcuts etc
- I'm annoyed with worktree default of being in the current directory -
it just isn't how my brain wants it organized and thought maybe others
felt this way
- I spent a lot of time debugging ClaudeCode not being able to call my
`ls` and `cat` because I wrapped in the super helpful
`_scmb_git_branch_shortcuts` but ClaudeCode ignores all single `_` fns
and it caused a lot of pain so I renamed _only_ the fns that are used in
a non-private way to have `__` in front.
- I was having trouble testing local b/c I couldn't tell if a quirk was
in my extra shell fns or in scm breeze so created a docker tester to
help - also helpful it supports bash and zsh so you can easily test
different shells
- I just saw #365 and seemed reasonable to pull in to my fork
- Bugs are annoying!

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added a Docker sandbox for trying the tool in an isolated environment,
with build/run instructions and an included shell session.
* Added shortcuts for working with git worktrees, including creating,
removing, and switching more naturally between branches and their
worktrees.
* **Bug Fixes**
* Improved path handling for status-related shortcuts so file paths
resolve from the correct project root.
* **Documentation**
  * Expanded the README with a new Docker sandbox section.
* **Tests**
  * Updated coverage to match the improved command evaluation behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@mmcrockett

Copy link
Copy Markdown
Contributor

Hi @pellejacobs - think I improved on what you proposed #371 and it's been merged fyi if you care to close.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants