()
| 12 | import { gitCache } from "./cache"; |
| 13 | |
| 14 | export const createStatusRouter = () => { |
| 15 | return router({ |
| 16 | getStatus: publicProcedure |
| 17 | .input( |
| 18 | z.object({ |
| 19 | worktreePath: z.string(), |
| 20 | defaultBranch: z.string().optional(), |
| 21 | }), |
| 22 | ) |
| 23 | .query(async ({ input }): Promise<GitChangesStatus> => { |
| 24 | assertRegisteredWorktree(input.worktreePath); |
| 25 | |
| 26 | // Check cache first |
| 27 | const cached = gitCache.getStatus<GitChangesStatus>(input.worktreePath); |
| 28 | if (cached) { |
| 29 | console.log("[getStatus] Cache hit for:", input.worktreePath); |
| 30 | return cached; |
| 31 | } |
| 32 | |
| 33 | console.log("[getStatus] Cache miss, fetching:", input.worktreePath); |
| 34 | const git = simpleGit(input.worktreePath); |
| 35 | const defaultBranch = input.defaultBranch || "main"; |
| 36 | |
| 37 | const status = await git.status(); |
| 38 | const parsed = parseGitStatus(status); |
| 39 | |
| 40 | // Run independent git operations in parallel (VS Code style) |
| 41 | const [branchComparison, trackingStatus] = await Promise.all([ |
| 42 | getBranchComparison(git, defaultBranch), |
| 43 | getTrackingBranchStatus(git), |
| 44 | ]); |
| 45 | |
| 46 | // Run numstat operations in parallel |
| 47 | await Promise.all([ |
| 48 | applyNumstatToFiles(git, parsed.staged, [ |
| 49 | "diff", |
| 50 | "--cached", |
| 51 | "--numstat", |
| 52 | ]), |
| 53 | applyNumstatToFiles(git, parsed.unstaged, ["diff", "--numstat"]), |
| 54 | applyUntrackedLineCount(input.worktreePath, parsed.untracked), |
| 55 | ]); |
| 56 | |
| 57 | const result: GitChangesStatus = { |
| 58 | branch: parsed.branch, |
| 59 | defaultBranch, |
| 60 | againstBase: branchComparison.againstBase, |
| 61 | commits: branchComparison.commits, |
| 62 | staged: parsed.staged, |
| 63 | unstaged: parsed.unstaged, |
| 64 | untracked: parsed.untracked, |
| 65 | ahead: branchComparison.ahead, |
| 66 | behind: branchComparison.behind, |
| 67 | pushCount: trackingStatus.pushCount, |
| 68 | pullCount: trackingStatus.pullCount, |
| 69 | hasUpstream: trackingStatus.hasUpstream, |
| 70 | }; |
| 71 |
no test coverage detected