diff --git a/src/vs/platform/agentHost/node/agentHostGitService.ts b/src/vs/platform/agentHost/node/agentHostGitService.ts index 85c3cca861b..467c4d3faf6 100644 --- a/src/vs/platform/agentHost/node/agentHostGitService.ts +++ b/src/vs/platform/agentHost/node/agentHostGitService.ts @@ -788,27 +788,32 @@ export function parseGitDiffRawNumstat(output: string, repositoryRoot: URI, sess return changes.map(change => { const stats = numStats.get(change.newPath ?? change.oldPath ?? ''); - const hasBefore = change.kind !== FileEditKind.Create; - const hasAfter = change.kind !== FileEditKind.Delete; + + const before = change.kind !== FileEditKind.Create && change.oldPath + ? { + uri: URI.joinPath(repositoryRoot, change.oldPath).toString(), + content: { uri: buildGitBlobUri(sessionUri, beforeRef, change.oldPath) }, + } + : undefined; + + const after = change.kind !== FileEditKind.Delete && change.newPath + ? { + uri: URI.joinPath(repositoryRoot, change.newPath).toString(), + content: afterRef !== undefined + ? { uri: buildGitBlobUri(sessionUri, afterRef, change.newPath) } + : { uri: URI.joinPath(repositoryRoot, change.newPath).toString() } + } + : undefined; + + const diff = { + added: stats?.added ?? 0, + removed: stats?.removed ?? 0 + }; + return { - ...(hasBefore && change.oldPath ? { - before: { - uri: URI.joinPath(repositoryRoot, change.oldPath).toString(), - content: { uri: buildGitBlobUri(sessionUri, beforeRef, change.oldPath) }, - }, - } : {}), - ...(hasAfter && change.newPath ? { - after: afterRef !== undefined - ? { - uri: buildGitBlobUri(sessionUri, afterRef, change.newPath), - content: { uri: buildGitBlobUri(sessionUri, afterRef, change.newPath) }, - } - : { - uri: URI.joinPath(repositoryRoot, change.newPath).toString(), - content: { uri: URI.joinPath(repositoryRoot, change.newPath).toString() }, - }, - } : {}), - diff: { added: stats?.added ?? 0, removed: stats?.removed ?? 0 }, + ...(before ? { before } : {}), + ...(after ? { after } : {}), + diff }; }); } diff --git a/src/vs/platform/agentHost/test/node/agentHostGitService.test.ts b/src/vs/platform/agentHost/test/node/agentHostGitService.test.ts index 452c179a0a0..27714293d8c 100644 --- a/src/vs/platform/agentHost/test/node/agentHostGitService.test.ts +++ b/src/vs/platform/agentHost/test/node/agentHostGitService.test.ts @@ -246,11 +246,11 @@ suite('AgentHostGitService', () => { assert.deepStrictEqual(diffs, [ { before: { uri: 'file:///repo/modified.ts', content: { uri: buildGitBlobUri(sessionUri, sha, 'modified.ts') } }, - after: { uri: buildGitBlobUri(sessionUri, toSha, 'modified.ts'), content: { uri: buildGitBlobUri(sessionUri, toSha, 'modified.ts') } }, + after: { uri: 'file:///repo/modified.ts', content: { uri: buildGitBlobUri(sessionUri, toSha, 'modified.ts') } }, diff: { added: 5, removed: 2 }, }, { - after: { uri: buildGitBlobUri(sessionUri, toSha, 'added.ts'), content: { uri: buildGitBlobUri(sessionUri, toSha, 'added.ts') } }, + after: { uri: 'file:///repo/added.ts', content: { uri: buildGitBlobUri(sessionUri, toSha, 'added.ts') } }, diff: { added: 10, removed: 0 }, }, { @@ -259,7 +259,7 @@ suite('AgentHostGitService', () => { }, { before: { uri: 'file:///repo/old/path.ts', content: { uri: buildGitBlobUri(sessionUri, sha, 'old/path.ts') } }, - after: { uri: buildGitBlobUri(sessionUri, toSha, 'new/path.ts'), content: { uri: buildGitBlobUri(sessionUri, toSha, 'new/path.ts') } }, + after: { uri: 'file:///repo/new/path.ts', content: { uri: buildGitBlobUri(sessionUri, toSha, 'new/path.ts') } }, diff: { added: 3, removed: 3 }, }, ]);