( repository: Repository, file: FileChange, commitish: string, hideWhitespaceInDiff: boolean = false )
| 113 | * to a commit. |
| 114 | */ |
| 115 | export async function getCommitDiff( |
| 116 | repository: Repository, |
| 117 | file: FileChange, |
| 118 | commitish: string, |
| 119 | hideWhitespaceInDiff: boolean = false |
| 120 | ): Promise<IDiff> { |
| 121 | const args = [ |
| 122 | 'log', |
| 123 | commitish, |
| 124 | ...(hideWhitespaceInDiff ? ['-w'] : []), |
| 125 | '-m', |
| 126 | '-1', |
| 127 | '--first-parent', |
| 128 | '--patch-with-raw', |
| 129 | '--format=', |
| 130 | '-z', |
| 131 | '--no-color', |
| 132 | '--', |
| 133 | ensureRelativePath(file.path), |
| 134 | ] |
| 135 | |
| 136 | if ( |
| 137 | file.status.kind === AppFileStatusKind.Renamed || |
| 138 | file.status.kind === AppFileStatusKind.Copied |
| 139 | ) { |
| 140 | args.push(ensureRelativePath(file.status.oldPath)) |
| 141 | } |
| 142 | |
| 143 | const { stdout } = await git(args, repository.path, 'getCommitDiff', { |
| 144 | encoding: 'buffer', |
| 145 | }) |
| 146 | |
| 147 | return buildDiff(stdout, repository, file, commitish, commitish) |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Render the diff between two branches with --merge-base for a file |
no test coverage detected