Skip to content

Commit 0b25736

Browse files
authored
Git - detect worktrees when opening a worktree (microsoft#258980)
1 parent cc28f16 commit 0b25736

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

extensions/git/src/git.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,14 +2786,9 @@ export class Repository {
27862786
return [];
27872787
}
27882788

2789-
if (this.kind !== 'repository') {
2790-
this.logger.info('[Git][getWorktreesFS] Either a submodule or a worktree, skipping worktree detection');
2791-
return [];
2792-
}
2793-
27942789
try {
27952790
// List all worktree folder names
2796-
const worktreesPath = path.join(this.repositoryRoot, '.git', 'worktrees');
2791+
const worktreesPath = path.join(this.dotGit.commonPath ?? this.dotGit.path, 'worktrees');
27972792
const dirents = await fs.readdir(worktreesPath, { withFileTypes: true });
27982793
const result: Worktree[] = [];
27992794

@@ -2812,7 +2807,7 @@ export class Repository {
28122807
result.push({
28132808
name: dirent.name,
28142809
// Remove '/.git' suffix
2815-
path: gitdirContent.replace(/\.git.*$/, ''),
2810+
path: gitdirContent.replace(/\/.git.*$/, ''),
28162811
// Remove 'ref: ' prefix
28172812
ref: headContent.replace(/^ref: /, ''),
28182813
});

extensions/git/src/model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,11 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi
783783
return;
784784
}
785785

786+
if (repository.kind === 'worktree') {
787+
this.logger.trace('[Model][open] Automatic detection of git worktrees is not skipped.');
788+
return;
789+
}
790+
786791
if (repository.worktrees.length > worktreesLimit) {
787792
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));
788793
statusListener.dispose();

0 commit comments

Comments
 (0)