MCPcopy
hub / github.com/21st-dev/1code / createGitOperationsRouter

Function createGitOperationsRouter

src/main/lib/git/git-operations.ts:41–634  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41export 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 )

Callers 1

createGitRouterFunction · 0.90

Calls 11

assertRegisteredWorktreeFunction · 0.90
withGitLockFunction · 0.90
createGitForNetworkFunction · 0.90
withLockRetryFunction · 0.90
hasUncommittedChangesFunction · 0.90
createGitFunction · 0.90
getRepositoryStateFunction · 0.90
isUpstreamMissingErrorFunction · 0.90
fetchGitHubPRStatusFunction · 0.90
invalidateGitStateCachesFunction · 0.85
hasUpstreamBranchFunction · 0.85

Tested by

no test coverage detected