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

Function getUntrackedFilePatch

projects/electron/src/modules/code/git.ts:1894–1920  ·  view source on GitHub ↗
(
    workDir: string,
    filePath: string,
    contextLines: 1 | 3 | 10 | 25 | 100,
    allowTruncation: boolean = true
)

Source from the content-addressed store, hash-verified

1892}
1893
1894async function getUntrackedFilePatch(
1895 workDir: string,
1896 filePath: string,
1897 contextLines: 1 | 3 | 10 | 25 | 100,
1898 allowTruncation: boolean = true
1899): Promise<GetFilePatchResponse> {
1900 const resolvedPath = resolveWorktreeFilePath(workDir, filePath)
1901 if (!resolvedPath) {
1902 throw new Error(`Untracked file path escapes worktree: ${filePath}`)
1903 }
1904
1905 if (!fs.existsSync(resolvedPath.absolutePath)) {
1906 return createEmptyFilePatchResponse()
1907 }
1908
1909 const result = await execCommand(
1910 "git",
1911 ["diff", "--no-index", `-U${contextLines}`, "--", "/dev/null", resolvedPath.relativePath],
1912 { cwd: workDir, maxBuffer: 50 * 1024 * 1024 }
1913 )
1914
1915 if (!result.success && result.code !== 1) {
1916 throw new Error(`Failed to get untracked file patch: ${result.stderr}`)
1917 }
1918
1919 return finalizeFilePatchResponse(result.stdout, allowTruncation)
1920}
1921
1922/**
1923 * Get file content at a specific treeish

Callers 1

Calls 4

execCommandFunction · 0.90
resolveWorktreeFilePathFunction · 0.85

Tested by

no test coverage detected