Skip to content

Commit 2557225

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 Now, when a worktree is opened, `checkForWorktrees()` discovers and opens sibling worktrees and the main repository (excluding the current worktree from the candidate list). This enables the full worktree management workflow regardless of which worktree is opened first. 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 2557225

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

extensions/git/src/model.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -807,17 +807,18 @@ 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-
}
814-
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));
810+
// When a worktree is opened, discover sibling worktrees and the
811+
// main repository so that worktree management commands are available.
812+
const candidateWorktrees = repository.kind === 'worktree'
813+
? repository.worktrees.filter(w => !pathEquals(w.path, repository.root))
814+
: repository.worktrees;
815+
816+
if (candidateWorktrees.length > worktreesLimit) {
817+
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));
817818
statusListener.dispose();
818819
}
819820

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

0 commit comments

Comments
 (0)