MCPcopy
hub / github.com/desktop/desktop / getCommitDiff

Function getCommitDiff

app/src/lib/git/diff.ts:115–148  ·  view source on GitHub ↗
(
  repository: Repository,
  file: FileChange,
  commitish: string,
  hideWhitespaceInDiff: boolean = false
)

Source from the content-addressed store, hash-verified

113 * to a commit.
114 */
115export 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

Callers 2

_changeFileSelectionMethod · 0.90

Calls 4

gitFunction · 0.90
ensureRelativePathFunction · 0.85
buildDiffFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected