Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { IGitCommitMessageService } from '../../../platform/git/common/gitCommit
import { IGitService } from '../../../platform/git/common/gitService';
import { toGitUri } from '../../../platform/git/common/utils';
import { ILogService } from '../../../platform/log/common/logService';
import { coalesce } from '../../../util/vs/base/common/arrays';
import { Disposable } from '../../../util/vs/base/common/lifecycle';
import { derived, IObservable } from '../../../util/vs/base/common/observable';
import * as path from '../../../util/vs/base/common/path';
Expand Down Expand Up @@ -182,32 +181,17 @@ export class ChatSessionWorktreeService extends Disposable implements IChatSessi
// Background session that has the changes committed in the worktree. To apply the
// changes, we need to migrate them from the worktree to the main repository using
// a patch file.
const changes = await this.gitService.diffBetweenWithStats(
const patch = await this.gitService.diffBetweenPatch(
vscode.Uri.file(worktreeProperties.worktreePath),
worktreeProperties.baseCommit,
worktreeProperties.branchName);

// Temporary solution until there is git extension API
const diffs = await Promise.all((changes ?? [])
.map(change => {
return this.gitService.diffBetweenPatch(
vscode.Uri.file(worktreeProperties.worktreePath),
worktreeProperties.baseCommit,
worktreeProperties.branchName,
change.uri.fsPath
);
}));

const patch = coalesce(diffs).map(line => `${line}\n`);
if (patch.length === 0) {
return;
}
worktreeProperties.branchName,
);

// Write the patch to a temporary file
const encoder = new TextEncoder();
const patchFilePath = path.join(worktreeProperties.repositoryPath, '.git', `${worktreeProperties.branchName}.patch`);
const patchFileUri = vscode.Uri.file(patchFilePath);
await vscode.workspace.fs.writeFile(patchFileUri, encoder.encode(patch.join('')));
await vscode.workspace.fs.writeFile(patchFileUri, encoder.encode(patch));

try {
// Apply patch
Expand Down
2 changes: 1 addition & 1 deletion src/platform/git/common/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface IGitService extends IDisposable {
add(uri: URI, paths: string[]): Promise<void>;
log(uri: URI, options?: LogOptions): Promise<Commit[] | undefined>;
diffBetween(uri: URI, ref1: string, ref2: string): Promise<Change[] | undefined>;
diffBetweenPatch(uri: URI, ref1: string, ref2: string, path: string): Promise<string | undefined>;
diffBetweenPatch(uri: URI, ref1: string, ref2: string, path?: string): Promise<string | undefined>;
diffBetweenWithStats(uri: URI, ref1: string, ref2: string, path?: string): Promise<DiffChange[] | undefined>;
diffWith(uri: URI, ref: string): Promise<Change[] | undefined>;
diffIndexWithHEADShortStats(uri: URI): Promise<CommitShortStat | undefined>;
Expand Down
1 change: 1 addition & 0 deletions src/platform/git/vscode/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export interface Repository {
diffBlobs(object1: string, object2: string): Promise<string>;
diffBetween(ref1: string, ref2: string): Promise<Change[]>;
diffBetween(ref1: string, ref2: string, path: string): Promise<string>;
diffBetweenPatch(ref1: string, ref2: string, path?: string): Promise<string>;
diffBetweenWithStats(ref1: string, ref2: string, path?: string): Promise<DiffChange[]>;


Expand Down
4 changes: 2 additions & 2 deletions src/platform/git/vscode/gitServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ export class GitServiceImpl extends Disposable implements IGitService {
return repository?.diffBetween(ref1, ref2);
}

async diffBetweenPatch(uri: vscode.Uri, ref1: string, ref2: string, path: string): Promise<string | undefined> {
async diffBetweenPatch(uri: vscode.Uri, ref1: string, ref2: string, path?: string): Promise<string | undefined> {
const gitAPI = this.gitExtensionService.getExtensionApi();
const repository = gitAPI?.getRepository(uri);
return repository?.diffBetween(ref1, ref2, path);
return repository?.diffBetweenPatch(ref1, ref2, path);
}

async diffBetweenWithStats(uri: vscode.Uri, ref1: string, ref2: string, path?: string): Promise<DiffChange[] | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ignore/node/test/mockGitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class MockGitService implements IGitService {
return Promise.resolve(undefined);
}

diffBetweenPatch(uri: URI, ref1: string, ref2: string, path: string): Promise<string | undefined> {
diffBetweenPatch(uri: URI, ref1: string, ref2: string, path?: string): Promise<string | undefined> {
return Promise.resolve(undefined);
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/test/node/simulationWorkspaceServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ export class TestingGitService implements IGitService {
return [];
}

async diffBetweenPatch(uri: URI, ref1: string, ref2: string, path: string): Promise<string | undefined> {
async diffBetweenPatch(uri: URI, ref1: string, ref2: string, path?: string): Promise<string | undefined> {
return undefined;
}

Expand Down