Skip to content

Commit dbc73f7

Browse files
marcelsafinCopilot
andcommitted
git: discover worktrees when opening a worktree directory
When a worktree directory is opened with `git.detectWorktrees` enabled, `checkForWorktrees()` previously returned early without discovering the main repository or sibling worktrees. This left worktree management commands non-functional because: - Commands like "Create Worktree" filter for repository/submodule kind - "Open Worktree" requires gitOpenRepositoryCount > 1 - SCM menu items depend on a repository-kind provider being open Remove the early return for worktree-kind repositories and instead always filter out the current repository from the candidate list. This enables bidirectional worktree discovery (worktree → main repo, and main repo → worktrees) and also fixes a pre-existing off-by-one in the limit/warning logic where the main repo counted itself as a candidate. The existing `isRepositoryOutsideWorkspace()` check already allows this because it recognizes paths that appear in any open repository's worktree list, and `getRepositoryExact()` prevents duplicate/recursive opens. Also fixes a confusing log message that said detection "is not skipped" when it was in fact skipping. Fixes #264209 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 78e3397 commit dbc73f7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

extensions/git/src/model.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -807,17 +807,17 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi
807807
return;
808808
}
809809

810-
if (repository.kind === 'worktree') {
811-
this.logger.trace('[Model][open] Automatic detection of git worktrees is not skipped.');
812-
return;
813-
}
810+
// Discover additional worktrees for the repository, but do not
811+
// include the currently opened repository itself.
812+
const candidateWorktrees = repository.worktrees
813+
.filter(w => !pathEquals(w.path, repository.root));
814814

815-
if (repository.worktrees.length > worktreesLimit) {
816-
window.showWarningMessage(l10n.t('The "{0}" repository has {1} worktrees which won\'t be opened automatically. You can still open each one individually by opening a file within.', path.basename(repository.root), repository.worktrees.length));
815+
if (candidateWorktrees.length > worktreesLimit) {
816+
window.showWarningMessage(l10n.t('The "{0}" repository has {1} worktrees which won\'t be opened automatically. You can still open each one individually by opening a file within.', path.basename(repository.root), candidateWorktrees.length - worktreesLimit));
817817
statusListener.dispose();
818818
}
819819

820-
repository.worktrees
820+
candidateWorktrees
821821
.slice(0, worktreesLimit)
822822
.forEach(w => {
823823
this.logger.trace(`[Model][open] Opening worktree: '${w.path}'`);

0 commit comments

Comments
 (0)