-
Notifications
You must be signed in to change notification settings - Fork 928
Fetch and point new workspaces to origin/main #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling and worktree existence validation.
The
refreshGitStatusmutation has several reliability concerns:Line 476:
fetchOriginMainis not wrapped in try-catch, unlike the best-effort approach in the create mutation (lines 45-49). Network failures will cause the entire operation to fail with an unclear error.Line 479:
checkNeedsRebasecan throw if git operations fail or the worktree is in a bad state, but is not wrapped in error handling.Missing validation: The mutation doesn't verify that the worktree exists on disk using
worktreeExistsbefore attempting git operations. If the worktree was manually deleted, git operations will fail. The delete mutation performs this check (lines 325-328).These issues create a poor user experience with unclear error messages and inconsistent error handling across mutations.
Apply this diff to add error handling and validation:
refreshGitStatus: publicProcedure .input(z.object({ workspaceId: z.string() })) .mutation(async ({ input }) => { const workspace = db.data.workspaces.find( (w) => w.id === input.workspaceId, ); if (!workspace) { throw new Error(`Workspace ${input.workspaceId} not found`); } const worktree = db.data.worktrees.find( (wt) => wt.id === workspace.worktreeId, ); if (!worktree) { throw new Error( `Worktree for workspace ${input.workspaceId} not found`, ); } const project = db.data.projects.find( (p) => p.id === workspace.projectId, ); if (!project) { throw new Error(`Project ${workspace.projectId} not found`); } + + // Verify worktree exists on disk + const exists = await worktreeExists(project.mainRepoPath, worktree.path); + if (!exists) { + throw new Error( + `Worktree at ${worktree.path} not found on disk. It may have been manually removed.`, + ); + } - // Fetch origin/main to get latest - await fetchOriginMain(project.mainRepoPath); + // Fetch origin/main to get latest (best-effort) + try { + await fetchOriginMain(project.mainRepoPath); + } catch (error) { + console.warn('Failed to fetch origin/main:', error); + // Continue with stale origin/main - we can still check rebase status + } - // Check if worktree branch is behind origin/main - const needsRebase = await checkNeedsRebase(worktree.path); + // Check if worktree branch is behind origin/main + let needsRebase = false; + try { + needsRebase = await checkNeedsRebase(worktree.path); + } catch (error) { + console.error('Failed to check rebase status:', error); + throw new Error( + `Failed to check git status: ${error instanceof Error ? error.message : String(error)}`, + ); + } const gitStatus = { branch: worktree.branch, needsRebase, lastRefreshed: Date.now(), }; // Update worktree in db await db.update((data) => { const wt = data.worktrees.find((w) => w.id === worktree.id); if (wt) { wt.gitStatus = gitStatus; } }); return { gitStatus }; }),🤖 Prompt for AI Agents