MCPcopy Create free account
hub / github.com/arctic-cli/interface / maybeParseApplyPatch

Function maybeParseApplyPatch

packages/arctic/src/patch/index.ts:238–292  ·  view source on GitHub ↗
(
    argv: string[],
  )

Source from the content-addressed store, hash-verified

236
237 // Apply patch functionality
238 export function maybeParseApplyPatch(
239 argv: string[],
240 ):
241 | { type: MaybeApplyPatch.Body; args: ApplyPatchArgs }
242 | { type: MaybeApplyPatch.PatchParseError; error: Error }
243 | { type: MaybeApplyPatch.NotApplyPatch } {
244 const APPLY_PATCH_COMMANDS = ["apply_patch", "applypatch"]
245
246 // Direct invocation: apply_patch <patch>
247 if (argv.length === 2 && APPLY_PATCH_COMMANDS.includes(argv[0])) {
248 try {
249 const { hunks } = parsePatch(argv[1])
250 return {
251 type: MaybeApplyPatch.Body,
252 args: {
253 patch: argv[1],
254 hunks,
255 },
256 }
257 } catch (error) {
258 return {
259 type: MaybeApplyPatch.PatchParseError,
260 error: error as Error,
261 }
262 }
263 }
264
265 // Bash heredoc form: bash -lc 'apply_patch <<"EOF" ...'
266 if (argv.length === 3 && argv[0] === "bash" && argv[1] === "-lc") {
267 // Simple extraction - in real implementation would need proper bash parsing
268 const script = argv[2]
269 const heredocMatch = script.match(/apply_patch\s*<<['"](\w+)['"]\s*\n([\s\S]*?)\n\1/)
270
271 if (heredocMatch) {
272 const patchContent = heredocMatch[2]
273 try {
274 const { hunks } = parsePatch(patchContent)
275 return {
276 type: MaybeApplyPatch.Body,
277 args: {
278 patch: patchContent,
279 hunks,
280 },
281 }
282 } catch (error) {
283 return {
284 type: MaybeApplyPatch.PatchParseError,
285 error: error as Error,
286 }
287 }
288 }
289 }
290
291 return { type: MaybeApplyPatch.NotApplyPatch }
292 }
293
294 // File content manipulation
295 interface ApplyPatchFileUpdate {

Callers 1

Calls 1

parsePatchFunction · 0.85

Tested by

no test coverage detected