diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index a7857872671..413a756400c 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -2786,14 +2786,9 @@ export class Repository { return []; } - if (this.kind !== 'repository') { - this.logger.info('[Git][getWorktreesFS] Either a submodule or a worktree, skipping worktree detection'); - return []; - } - try { // List all worktree folder names - const worktreesPath = path.join(this.repositoryRoot, '.git', 'worktrees'); + const worktreesPath = path.join(this.dotGit.commonPath ?? this.dotGit.path, 'worktrees'); const dirents = await fs.readdir(worktreesPath, { withFileTypes: true }); const result: Worktree[] = []; @@ -2812,7 +2807,7 @@ export class Repository { result.push({ name: dirent.name, // Remove '/.git' suffix - path: gitdirContent.replace(/\.git.*$/, ''), + path: gitdirContent.replace(/\/.git.*$/, ''), // Remove 'ref: ' prefix ref: headContent.replace(/^ref: /, ''), }); diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index 95ee8123812..73b7a723c79 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -783,6 +783,11 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi return; } + if (repository.kind === 'worktree') { + this.logger.trace('[Model][open] Automatic detection of git worktrees is not skipped.'); + return; + } + if (repository.worktrees.length > worktreesLimit) { 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)); statusListener.dispose();