feat(worktree): ✨ Fix branch tracking and support remote branch checkout - #157
Conversation
…tracking Add the ability to create a worktree from a remote branch by automatically creating a local tracking branch. Previously, users could only select local branches in the worktree dialog, limiting the ability to work on un-checked-out remote branches. Key changes include: - Expose a `trackUpstream` field in the worktree creation input model to control whether the new branch tracks the base ref as its upstream; defaults to `false` for feature branches - Respect `trackUpstream` in the backend worktree add command by passing `--no-track` when the flag is `false` - In the UI dialog, compute remote branches that have no local counterpart and display them in a dedicated section labeled "remote" alongside local branches - When a remote branch is selected, construct a create-branch input with `trackUpstream: true` so the local branch automatically tracks the remote ref, enabling `git pull` to work out of the box This allows developers to spin up a worktree from any remote branch (e.g., a PR branch) without needing to manually create a local branch beforehand.
AI Code Review SummaryPR: #157 (feat(worktree): ✨ Fix branch tracking and support remote branch checkout) Overall AssessmentDetected 5 actionable findings, prioritize CRITICAL/HIGH before merge. Major Findings by Severity
Actionable Suggestions
Potential Risks
Test Suggestions
File-Level Coverage Notes
Inline Downgraded Items (processed but not inline)
Coverage Status
Uncovered list:
No-patch covered list:
Runtime/Budget
|
| branch: &str, | ||
| create_branch: bool, | ||
| base_ref: Option<&str>, | ||
| track_upstream: bool, |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| branch, | ||
| baseBranch, | ||
| selectedExistingBranch, | ||
| remoteBranchesWithoutLocal, |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| createBranch: false, | ||
| path: path.trim() || undefined, | ||
| }; | ||
| // Check if the selected branch is a remote ref. |
There was a problem hiding this comment.
[HIGH] No test coverage for remote-branch selection and submission logic
The remote-branch submit path and filtering logic have no automated test coverage, so regressions in branch creation from remote refs are likely to slip through.
Suggestion: Add Vitest tests that mock branches, workspaceCreateWorktree, and onClose/onCreated. Cover: (1) selecting a remote branch and submitting—verify the input includes createBranch:true and correct baseRef; (2) selecting a local branch and submitting—verify createBranch:false with no baseRef; (3) edge cases where branch name has multiple slashes; (4) when both local and remote lists are empty, the empty state message renders.
Risk: Untested remote-branch workflow may silently send incorrect git commands, causing silent failures or wrong branch creation on the filesystem.
Confidence: 0.92
| // the base ref so that `git push` won't accidentally target the base | ||
| // branch's upstream. When track_upstream is true (e.g. checking out a | ||
| // remote branch locally), we let Git set up tracking normally. | ||
| if base_ref.is_some() && !track_upstream { |
There was a problem hiding this comment.
[MEDIUM] Missing tests for new track_upstream field and --no-track logic
The new track_upstream field and its conditional --no-track argument have no corresponding tests in the existing test suite, leaving the feature uncovered.
Suggestion: Add integration tests in src-tauri/tests/ (e.g., worktree_manager.rs) for: (1) track_upstream=false with base_ref → expects --no-track in args; (2) track_upstream=true with base_ref → omits --no-track; (3) create_branch=false → ignores track_upstream; (4) base_ref=None with track_upstream=false → no --no-track.
Risk: Without tests, future refactors could silently break upstream tracking behavior, affecting worktree-based branching workflows.
Confidence: 0.85
| ); | ||
|
|
||
| // Remote branches that don't already have a local counterpart. | ||
| const remoteBranchesWithoutLocal = useMemo(() => { |
There was a problem hiding this comment.
[MEDIUM] Missing boundary test for remoteBranchesWithoutLocal filter
Edge cases in the remote-branch dedup filter (names with slashes, fully remote repos) are not covered by tests.
Suggestion: Add unit tests for the filter logic (or component tests) with branches like 'origin/feature/my/branch' when a local 'feature/my/branch' also exists, and when only remote branches exist.
Risk: Branch names with multiple slashes could be incorrectly classified as having a local counterpart, hiding remote branches from the selector.
Confidence: 0.85
| return branches.filter((b) => { | ||
| if (!b.isRemote) return false; | ||
| // Strip the remote prefix (e.g. "origin/feature-x" → "feature-x") | ||
| const slashIdx = b.name.indexOf("/"); |
There was a problem hiding this comment.
[MEDIUM] Remote branch name deduplication may incorrectly match similar names
Using b.name.slice(slashIdx + 1) strips only the first path component (the remote name). For remotes with nested branch names (e.g., origin/feature/sub-feature), the resulting local name guess may be wrong, leading to false positives or negatives in the 'without local' filter.
Suggestion: Consider using b.name.replace(/^[^/]+\//, '') to strip exactly the remote prefix, or better, compare against the branch's ref or use the Git API to determine the true local tracking branch name derived from branches data if available.
Risk: May incorrectly hide or show remote branches that have slashes in their names, potentially causing confusion or duplicate branch entries.
Confidence: 0.85
| // the base ref so that `git push` won't accidentally target the base | ||
| // branch's upstream. When track_upstream is true (e.g. checking out a | ||
| // remote branch locally), we let Git set up tracking normally. | ||
| if base_ref.is_some() && !track_upstream { |
There was a problem hiding this comment.
[LOW] track_upstream silently ignored when create_branch is false
If someone sets track_upstream=true while create_branch=false, the flag has no effect and no diagnostic is given, which might lead to confusion.
Suggestion: Consider adding a warning log or returning a validation error when track_upstream is set but create_branch is false.
Risk: Users may expect track_upstream=true to set upstream tracking even without branch creation and be surprised when it does nothing. No data corruption, but it's a minor UX trap.
Confidence: 0.85
Summary
--no-trackwhen creating a new branch from a base ref, unlesstrackUpstreamis explicitly trueTest Plan
🤖 Generated with TiyCode