| 99 | } |
| 100 | |
| 101 | async function createTrackedFilePatch( |
| 102 | repositoryRoot: string, |
| 103 | relativePath: string, |
| 104 | originalPath?: string, |
| 105 | ): Promise<string | null> { |
| 106 | const paths = originalPath && originalPath !== relativePath |
| 107 | ? [originalPath, relativePath] |
| 108 | : [relativePath]; |
| 109 | try { |
| 110 | return await git(repositoryRoot, [ |
| 111 | "diff", |
| 112 | "--no-color", |
| 113 | "--no-ext-diff", |
| 114 | "--unified=3", |
| 115 | "HEAD", |
| 116 | "--", |
| 117 | ...paths, |
| 118 | ], TEXT_PREVIEW_MAX_BYTES * 4); |
| 119 | } catch { |
| 120 | return null; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | export async function getGitFileDiff(cwd: string, filePath: string): Promise<GitFileDiffResponse> { |
| 125 | const repositoryRoot = await findRepositoryRoot(cwd); |