diff --git a/core/index.d.ts b/core/index.d.ts index 5e1e31def..1f072112e 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -503,7 +503,7 @@ export interface IdeSettings { export interface IDE { getIdeInfo(): Promise; getIdeSettings(): Promise; - getDiff(includeUnstaged: boolean): Promise; + getDiff(includeUnstaged: boolean): Promise; getClipboardContent(): Promise<{ text: string; copiedAt: string }>; isTelemetryEnabled(): Promise; getUniqueId(): Promise; diff --git a/extensions/vscode/src/util/ideUtils.ts b/extensions/vscode/src/util/ideUtils.ts index 2ce332f02..cfd6898eb 100644 --- a/extensions/vscode/src/util/ideUtils.ts +++ b/extensions/vscode/src/util/ideUtils.ts @@ -570,8 +570,20 @@ export class VsCodeIdeUtils { return repo?.state?.HEAD?.name || "NONE"; } - async getDiff(includeUnstaged: boolean): Promise { - let diffs: string[] = []; + private splitDiff(diffString: string): string[] { + const fileDiffHeaderRegex = /(?=diff --git a\/.* b\/.*)/; + + const diffs = diffString.split(fileDiffHeaderRegex); + + if (diffs[0].trim() === "") { + diffs.shift(); + } + + return diffs; + } + + async getDiff(includeUnstaged: boolean): Promise { + const diffs: string[] = []; for (const dir of this.getWorkspaceDirectories()) { const repo = await this.getRepo(vscode.Uri.file(dir)); @@ -587,9 +599,7 @@ export class VsCodeIdeUtils { } } - const fullDiff = diffs.join("\n\n"); - - return fullDiff; + return diffs.flatMap((diff) => this.splitDiff(diff)); } getHighlightedCode(): RangeInFile[] {