Skip to content

Expose git.closeRepository and git.openRepository commands for programmatic use #291791

@quasarea

Description

@quasarea

Problem

VS Code's Git extension allows users to manually close and open repositories via the Source Control panel context menu ("Close Repository" / "Open Repository"). However, these actions are not exposed as commands that can be invoked programmatically by extensions or tools.

Use Case

When working with multi-repository workspaces (common in enterprise environments with component-based architectures), users frequently clone repositories into the workspace for temporary work. After completing tasks, these repos clutter the Source Control panel even though they're no longer actively being worked on.

Current workaround: Users must manually right-click each repo and select "Close Repository".

Desired behavior: Extensions and tools (including AI assistants like GitHub Copilot) should be able to:

  1. Close inactive repositories to reduce clutter
  2. Reopen repositories when work resumes on them

Proposed Solution

Expose two new commands in the Git extension:

// Close a repository (remove from Source Control tracking, files remain on disk)
git.closeRepository: (repositoryPath: string) => void

// Open/reopen a repository (add to Source Control tracking)
git.openRepository: (repositoryPath: string) => void

Benefits

  1. Better multi-repo workspace management - Extensions can help manage repository visibility
  2. Improved AI assistant integration - Tools like Copilot could automatically close repos after completing work
  3. Workflow automation - Task runners could open/close repos as part of build or deployment workflows
  4. Consistency - Aligns with other Git commands that are already exposed (e.g., git.checkout, git.pull)

Additional Context

  • The internal functionality already exists (the UI uses it)
  • Similar to how workbench.action.closeActiveEditor is exposed for editor management
  • Would complement existing git.openRepository prompt behavior when opening files from closed repos

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions