This repository was archived by the owner on Feb 6, 2026. It is now read-only.
Merged
Conversation
dd7f1a4 to
c403c8b
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issues with workspace/branch creation, addressing both frontend state management problems and backend recovery scenarios.
Changes:
- Fixed Svelte reactive state issues by capturing variable values at the start of async operations to prevent stale closures
- Added recovery logic to create worktrees for existing local branches instead of failing
- Refactored modal state management to use individual properties instead of objects to prevent null reference issues during teardown
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/NewBranchModal.svelte | Captures reactive variables (projectId, selectedRepo, branchName, etc.) at the start of async functions to prevent values from changing mid-operation |
| src/lib/BranchHome.svelte | Refactors from passing GitProject object to individual projectId/repoPath strings, adds async closeNewBranchModal with tick() to prevent teardown issues, updates branch reconciliation to match by repo+branch name for recovery |
| src-tauri/src/lib.rs | Adds branch_exists check to create worktrees for existing branches instead of failing, improving recovery from partial failures |
| src-tauri/src/git/worktree.rs | Implements create_worktree_for_existing_branch function to checkout existing branches to new worktrees |
| src-tauri/src/git/mod.rs | Exports the new create_worktree_for_existing_branch function |
Comments suppressed due to low confidence (3)
src/lib/NewBranchModal.svelte:387
- The captured variable createProjectId is defined but never used. Lines 387 and 417 use the reactive projectId directly, which defeats the purpose of capturing it. Similarly, line 387 uses selectedRepo directly instead of createRepoPath. These should be changed to use the captured values (createProjectId and createRepoPath) to ensure consistency throughout the async operation and prevent stale closure issues.
const createProjectId = projectId;
const createRepoPath = selectedRepo;
const createBranchName = branchName.trim();
const createBaseBranch = effectiveBaseBranch;
const createSelectedBaseBranch = selectedBaseBranch ?? undefined;
try {
// If no project ID was provided, get or create one for this repo
const effectiveProjectId =
projectId || (await branchService.getOrCreateGitProject(selectedRepo)).id;
src-tauri/src/lib.rs:1683
- The recovery logic for existing branches is incomplete. When a branch exists locally and a worktree is created for it, a new Branch object with a new UUID is always created (line 1671). If a database row already exists for this (repo_path, branch_name) combination, the INSERT at line 1680 will fail with a UNIQUE constraint violation, causing the newly created worktree to be cleaned up and returning an error to the user. This leaves the user unable to create a worktree for the existing branch. Consider querying the database first to check if a row exists, and if so, either return the existing branch or update its worktree_path rather than always attempting to insert a new row.
// If branch already exists locally, set up a worktree for it instead of failing.
// Otherwise create both branch and worktree from the selected base.
let branch_exists = git::branch_exists(repo, &branch_name).map_err(|e| e.to_string())?;
let worktree_path = if branch_exists {
git::create_worktree_for_existing_branch(repo, &branch_name)
.map_err(|e| e.to_string())?
} else {
git::create_worktree(repo, &branch_name, &base_branch).map_err(|e| e.to_string())?
};
// Create the branch record
let branch = Branch::new(
&project_id,
&repo_path,
&branch_name,
worktree_path.to_string_lossy().to_string(),
&base_branch,
);
// If DB insert fails, clean up the worktree.
if let Err(e) = store.create_branch(&branch) {
let _ = git::remove_worktree(repo, &worktree_path); // Best-effort cleanup
return Err(e.to_string());
}
src/lib/NewBranchModal.svelte:276
- The captured variable createProjectId is defined but never used. Line 276 and 305 use the reactive projectId directly, which defeats the purpose of capturing it. Similarly, line 276 uses selectedRepo directly instead of createRepoPath. These should be changed to use the captured values (createProjectId and createRepoPath) to ensure consistency throughout the async operation and prevent stale closure issues.
const createProjectId = projectId;
const createRepoPath = selectedRepo;
try {
const effectiveProjectId =
projectId || (await branchService.getOrCreateGitProject(selectedRepo)).id;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Changed both handleSelectPR and handleCreate error handlers to use createProjectId instead of the reactive projectId prop. This ensures consistency with other captured values (createRepoPath, createBranchName, createBaseBranch) and prevents potential issues if projectId changes during the async operation.
wesbillman
approved these changes
Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.