MCPcopy Index your code
hub / github.com/21st-dev/1code / createStatusRouter

Function createStatusRouter

src/main/lib/git/status.ts:14–186  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12import { gitCache } from "./cache";
13
14export 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

Callers 1

createGitRouterFunction · 0.90

Calls 9

assertRegisteredWorktreeFunction · 0.90
parseGitStatusFunction · 0.90
applyNumstatToFilesFunction · 0.90
parseNameStatusFunction · 0.90
getBranchComparisonFunction · 0.85
getTrackingBranchStatusFunction · 0.85
applyUntrackedLineCountFunction · 0.85
getStatusMethod · 0.80
setStatusMethod · 0.80

Tested by

no test coverage detected