Skip to content

Conversation

@lerenn
Copy link
Owner

@lerenn lerenn commented Nov 27, 2025

Summary

Fixed issue where cm wt load -r <repo> <branch> command failed when loading branches from remote.

Problem

The worktree load command was failing with:

fatal: Remote branch <branch> not found in upstream origin

This happened because detached clones were trying to clone from local path with --branch flag, which failed when the branch only existed on the remote (not locally).

Solution

  • Modified createDetachedClone to check if branch exists locally
  • If branch exists locally, use CloneToPath (clones from local path)
  • If branch doesn't exist locally, clone from remote URL and checkout branch
  • Updated CheckoutBranch to handle remote tracking branches when branch doesn't exist locally
  • Updated unit test to match new implementation

Testing

All tests pass:

  • ✅ Lint
  • ✅ Unit tests
  • ✅ Integration tests
  • ✅ E2E tests

Example

go run ./cmd/cm wt load -r github.com/flexaihq/experience fix/temporal-schedule-workflow-task-failed-state

This now works correctly.

Fixed issue where worktree load command failed when loading branches from remote.
The problem was that detached clones were trying to clone from local path with
--branch flag, which failed when the branch only existed on the remote.

Changes:
- Modified createDetachedClone to check if branch exists locally
- If branch exists locally, use CloneToPath (clones from local path)
- If branch doesn't exist locally, clone from remote URL and checkout branch
- Updated CheckoutBranch to handle remote tracking branches when branch doesn't exist locally
- Updated unit test to match new implementation

This fixes the issue where 'cm wt load -r <repo> <branch>' would fail with:
'fatal: Remote branch <branch> not found in upstream origin'

All tests pass: lint, unit, integration, and e2e.
- Fix line length issue in checkout_branch.go (split long error message)
- Reduce complexity in create.go by extracting helper functions
…chExists calls

- Skip EnsureBranchExists when creating detached worktrees since createDetachedClone handles branch checking
- Update TestWorktree_Create_DetachedMode to expect BranchExists to return false, matching the remote clone path behavior
@lerenn lerenn merged commit 594b01f into main Dec 24, 2025
9 checks passed
@lerenn lerenn deleted the fix-loading branch December 24, 2025 13:21
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