Skip to content
Draft
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 @@ -249,7 +249,29 @@ export class CopilotCLIChatSessionItemProvider extends Disposable implements vsc
}

public async provideChatSessionItems(token: vscode.CancellationToken): Promise<vscode.ChatSessionItem[]> {
const sessions = await this.copilotcliSessionService.getAllSessions(token);
let sessions = await this.copilotcliSessionService.getAllSessions(token);
// additional filtering based on worktree matching workspace's git repo worktrees
const currentWorkspaceGitWorktrees: string[] = [];
const repository = this.gitService.activeRepository.get();
if (repository) {
const worktrees = await this.gitService.getWorktrees(repository.rootUri);
for (const worktree of worktrees) {
currentWorkspaceGitWorktrees.push(worktree.path);
}
}

if (currentWorkspaceGitWorktrees.length > 0) {
// we know the current workspace git worktrees, filter sessions based on that
sessions = sessions.filter(session => {
const worktreePath = this.worktreeManager.getWorktreePath(session.id);
if (worktreePath) {
// only include sessions whose worktree belongs to current workspace
return currentWorkspaceGitWorktrees.some(wsWorktree => isEqual(URI.file(wsWorktree), URI.file(worktreePath)));
}
// include sessions without worktree as well
return true;
});
}
const diskSessions = await Promise.all(sessions.map(async session => this._toChatSessionItem(session)));

const count = diskSessions.length;
Expand All @@ -261,6 +283,16 @@ export class CopilotCLIChatSessionItemProvider extends Disposable implements vsc
private async _toChatSessionItem(session: ICopilotCLISessionItem): Promise<vscode.ChatSessionItem> {
const resource = SessionIdForCLI.getResource(_untitledSessionIdMap.get(session.id) ?? session.id);
const worktreePath = this.worktreeManager.getWorktreePath(session.id);
if (worktreePath) {
console.log('[CopilotCLIChatSessionItemProvider]_toChatSessionItem', session.id, session.label, worktreePath);
// now let's check if the worktree belongs to the workspace
this.gitService.repositories.forEach(repo => {
this.gitService.getWorktrees(repo.rootUri).then(worktrees => {
console.log('[CopilotCLIChatSessionItemProvider]_toChatSessionItem', 'worktrees', worktrees);
});
});
}

const worktreeRelativePath = this.worktreeManager.getWorktreeRelativePath(session.id);

const label = session.label;
Expand Down
1 change: 1 addition & 0 deletions src/platform/git/common/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface IGitService extends IDisposable {
diffIndexWithHEADShortStats(uri: URI): Promise<CommitShortStat | undefined>;
fetch(uri: URI, remote?: string, ref?: string, depth?: number): Promise<void>;
getMergeBase(uri: URI, ref1: string, ref2: string): Promise<string | undefined>;
getWorktrees(uri: URI): Promise<{ name: string; path: string; ref: string }[]>;

createWorktree(uri: URI, options?: { path?: string; commitish?: string; branch?: string }): Promise<string | undefined>;
deleteWorktree(uri: URI, path: string, options?: { force?: boolean }): Promise<void>;
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 @@ -286,6 +286,7 @@ export interface Repository {
popStash(index?: number): Promise<void>;
dropStash(index?: number): Promise<void>;

getWorktrees(): Promise<{ name: string; path: string; ref: string }[]>;
createWorktree(options?: { path?: string; commitish?: string; branch?: string }): Promise<string>;
deleteWorktree(path: string, options?: { force?: boolean }): Promise<void>;

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

async getWorktrees(uri: URI): Promise<{ name: string; path: string; ref: string }[]> {
const gitAPI = this.gitExtensionService.getExtensionApi();
const repository = gitAPI?.getRepository(uri);
return await repository?.getWorktrees() || [];
}

async createWorktree(uri: URI, options?: { path?: string; commitish?: string; branch?: string }): Promise<string | undefined> {
const gitAPI = this.gitExtensionService.getExtensionApi();
const repository = gitAPI?.getRepository(uri);
Expand Down