MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / processHunk

Function processHunk

src/core/tools/apply-patch/apply.ts:151–184  ·  view source on GitHub ↗
(
	hunk: Hunk,
	readFile: (path: string) => Promise<string>,
)

Source from the content-addressed store, hash-verified

149 * @returns The file change result
150 */
151export async function processHunk(
152 hunk: Hunk,
153 readFile: (path: string) => Promise<string>,
154): Promise<ApplyPatchFileChange> {
155 switch (hunk.type) {
156 case "AddFile":
157 return {
158 type: "add",
159 path: hunk.path,
160 newContent: hunk.contents,
161 }
162
163 case "DeleteFile": {
164 const content = await readFile(hunk.path)
165 return {
166 type: "delete",
167 path: hunk.path,
168 originalContent: content,
169 }
170 }
171
172 case "UpdateFile": {
173 const originalContent = await readFile(hunk.path)
174 const newContent = applyChunksToContent(originalContent, hunk.path, hunk.chunks)
175 return {
176 type: "update",
177 path: hunk.path,
178 movePath: hunk.movePath ?? undefined,
179 originalContent,
180 newContent,
181 }
182 }
183 }
184}
185
186/**
187 * Process all hunks in a patch.

Callers 1

processAllHunksFunction · 0.85

Calls 1

applyChunksToContentFunction · 0.85

Tested by

no test coverage detected