()
| 39 | } |
| 40 | |
| 41 | export const createGitOperationsRouter = () => { |
| 42 | return router({ |
| 43 | // NOTE: saveFile is defined in file-contents.ts with hardened path validation |
| 44 | // Do NOT add saveFile here - it would overwrite the secure version |
| 45 | |
| 46 | fetch: publicProcedure |
| 47 | .input( |
| 48 | z.object({ |
| 49 | worktreePath: z.string(), |
| 50 | }), |
| 51 | ) |
| 52 | .mutation(async ({ input }): Promise<{ success: boolean }> => { |
| 53 | assertRegisteredWorktree(input.worktreePath); |
| 54 | |
| 55 | return withGitLock(input.worktreePath, async () => { |
| 56 | const git = createGitForNetwork(input.worktreePath); |
| 57 | await withLockRetry(input.worktreePath, () => |
| 58 | git.fetch(["--all", "--prune"]) |
| 59 | ); |
| 60 | invalidateGitStateCaches(input.worktreePath); |
| 61 | return { success: true }; |
| 62 | }); |
| 63 | }), |
| 64 | |
| 65 | checkout: publicProcedure |
| 66 | .input( |
| 67 | z.object({ |
| 68 | worktreePath: z.string(), |
| 69 | branch: z.string(), |
| 70 | }), |
| 71 | ) |
| 72 | .mutation(async ({ input }): Promise<{ success: boolean }> => { |
| 73 | assertRegisteredWorktree(input.worktreePath); |
| 74 | |
| 75 | return withGitLock(input.worktreePath, async () => { |
| 76 | // Check for uncommitted changes before checkout |
| 77 | if (await hasUncommittedChanges(input.worktreePath)) { |
| 78 | throw new Error( |
| 79 | "Cannot switch branches: you have uncommitted changes. Please commit or stash your changes first." |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | const git = createGit(input.worktreePath); |
| 84 | await withLockRetry(input.worktreePath, () => |
| 85 | git.checkout(input.branch) |
| 86 | ); |
| 87 | invalidateGitStateCaches(input.worktreePath); |
| 88 | return { success: true }; |
| 89 | }); |
| 90 | }), |
| 91 | |
| 92 | getHistory: publicProcedure |
| 93 | .input( |
| 94 | z.object({ |
| 95 | worktreePath: z.string(), |
| 96 | limit: z.number().optional().default(50), |
| 97 | }), |
| 98 | ) |
no test coverage detected