Skip to content

Conversation

@lszomoru
Copy link
Member

@lszomoru lszomoru commented Dec 6, 2025

  • getRepository() waits until the initial repository discovery is complete
  • getRepository() now takes an option to open the repository if is not found
  • Computing worktree statistics takes advantage of the new option to not open a repository if not found

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the Copilot CLI worktree statistics computation by adding an option to avoid unnecessarily opening git repositories. The getRepository() method now accepts an optional forceOpen parameter (defaulting to true for backward compatibility) to control whether repositories should be opened if not already discovered. The worktree statistics computation uses forceOpen: false to avoid the overhead of opening repositories that may not yet be discovered.

Key changes:

  • Add optional forceOpen parameter to IGitService.getRepository() with default value of true
  • Ensure getRepository() waits for initial repository discovery to complete before checking opened repositories
  • Refactor worktree statistics computation to use the git service method instead of directly accessing the git extension API

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/platform/git/common/gitService.ts Add optional forceOpen parameter to getRepository() interface
src/platform/git/vscode/gitServiceImpl.ts Implement forceOpen parameter logic and ensure initialization is complete before querying repositories
src/platform/test/node/simulationWorkspaceServices.ts Update test mock signature to match new interface
src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts Use forceOpen: false when computing worktree statistics and refactor to use git service methods

const details: vscode.ChatSessionChangedFile[] = [];
for (const change of [...repository.changes.indexChanges, ...repository.changes.workingTree]) {
try {
const fileStats = await this.gitService.diffIndexWithHEADShortStats(change.uri);
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diffIndexWithHEADShortStats method is being called with change.uri, but the implementation in gitServiceImpl.ts (line 220-227) doesn't pass the file path to the underlying repository method. The repository's diffIndexWithHEADShortStats(path?: string) method expects an optional path parameter (a string), but the service implementation calls it without any arguments.

This means the method will return stats for the entire repository instead of per-file stats. You should either:

  1. Update the service method signature to accept a URI and extract uri.fsPath to pass to the repository method, or
  2. Call the method differently to get per-file statistics.

The old code called gitRepository.diffIndexWithHEADShortStats(change.uri.fsPath) directly, which was correct.

Suggested change
const fileStats = await this.gitService.diffIndexWithHEADShortStats(change.uri);
const fileStats = await this.gitService.diffIndexWithHEADShortStats(change.uri.fsPath);

Copilot uses AI. Check for mistakes.
@lszomoru lszomoru added this pull request to the merge queue Dec 8, 2025
Merged via the queue into main with commit 5168c60 Dec 8, 2025
22 checks passed
@lszomoru lszomoru deleted the lszomoru/novel-silverfish branch December 8, 2025 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants