MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / handleGetWorktreeFilePatch

Function handleGetWorktreeFilePatch

projects/electron/src/modules/code/git.ts:2074–2127  ·  view source on GitHub ↗
(params: GetWorktreeFilePatchParams)

Source from the content-addressed store, hash-verified

2072}
2073
2074async function handleGetWorktreeFilePatch(params: GetWorktreeFilePatchParams): Promise<GetFilePatchResponse> {
2075 const startTime = Date.now()
2076 logger.info("[Git:getWorktreeFilePatch] Getting file patch", JSON.stringify({
2077 workDir: params.workDir,
2078 from: params.fromTreeish,
2079 filePath: params.filePath,
2080 oldPath: params.oldPath,
2081 contextLines: params.contextLines,
2082 }))
2083
2084 try {
2085 validatePatchContextLines(params.contextLines)
2086 if (isGeneratedFile(params.filePath)) {
2087 logger.info("[Git:getWorktreeFilePatch] Skipping generated file", JSON.stringify({ filePath: params.filePath }))
2088 return createEmptyFilePatchResponse()
2089 }
2090 if (!resolveWorktreeFilePath(params.workDir, params.filePath)) {
2091 throw new Error(`Worktree file path escapes worktree: ${params.filePath}`)
2092 }
2093 if (params.oldPath && !resolveWorktreeFilePath(params.workDir, params.oldPath)) {
2094 throw new Error(`Worktree file path escapes worktree: ${params.oldPath}`)
2095 }
2096
2097 const pathspecs = getFilePatchPathspecs(params.filePath, params.oldPath)
2098 const result = await execGit(
2099 ["diff", "-M", `-U${params.contextLines}`, params.fromTreeish, "--", ...pathspecs],
2100 params.workDir
2101 )
2102
2103 if (!result.success) {
2104 throw new Error(`Failed to get worktree file patch: ${result.stderr}`)
2105 }
2106
2107 const allowTruncation = params.allowTruncation !== false
2108 let response = finalizeFilePatchResponse(result.stdout, allowTruncation)
2109 if (!response.patch && !params.oldPath) {
2110 response = await getUntrackedFilePatch(params.workDir, params.filePath, params.contextLines, allowTruncation)
2111 }
2112
2113 logger.info("[Git:getWorktreeFilePatch] File patch ready", JSON.stringify({
2114 filePath: params.filePath,
2115 hasPatch: response.patch.length > 0,
2116 truncated: response.truncated,
2117 heavy: response.heavy,
2118 changedLines: response.stats.changedLines,
2119 duration: Date.now() - startTime,
2120 }))
2121
2122 return response
2123 } catch (error: any) {
2124 logger.error("[Git:getWorktreeFilePatch] Error:", JSON.stringify({ error: error.message, duration: Date.now() - startTime }))
2125 throw error
2126 }
2127}
2128
2129async function handleGetCommitFilePatch(params: GetCommitFilePatchParams): Promise<GetFilePatchResponse> {
2130 const startTime = Date.now()

Callers 1

Calls 9

isGeneratedFileFunction · 0.85
resolveWorktreeFilePathFunction · 0.85
getFilePatchPathspecsFunction · 0.85
execGitFunction · 0.85
getUntrackedFilePatchFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected