@@ -179,6 +179,7 @@ import type {
179179 GraphItemRefGroupContext ,
180180 GraphTagContextValue ,
181181} from '../../../plus/webviews/graph/protocol' ;
182+ import { asRepoComparisonKey } from '../../../repositories' ;
182183import { countStringLength , filterMap } from '../../../system/array' ;
183184import { gate } from '../../../system/decorators/gate' ;
184185import { debug , log } from '../../../system/decorators/log' ;
@@ -721,6 +722,26 @@ export class LocalGitProvider implements GitProvider, Disposable {
721722 let rootPath ;
722723 let canonicalRootPath ;
723724
725+ function maybeAddRepo ( this : LocalGitProvider , uri : Uri , folder : WorkspaceFolder | undefined , root : boolean ) {
726+ const comparisonId = asRepoComparisonKey ( uri ) ;
727+ if ( repositories . some ( r => r . id === comparisonId ) ) {
728+ Logger . log ( scope , `found ${ root ? 'root ' : '' } repository in '${ uri . fsPath } '; skipping - duplicate` ) ;
729+ return ;
730+ }
731+
732+ const repo = this . container . git . getRepository ( uri ) ;
733+ if ( repo != null ) {
734+ if ( repo . closed && silent === false ) {
735+ repo . closed = false ;
736+ }
737+ Logger . log ( scope , `found ${ root ? 'root ' : '' } repository in '${ uri . fsPath } '; skipping - already open` ) ;
738+ return ;
739+ }
740+
741+ Logger . log ( scope , `found ${ root ? 'root ' : '' } repository in '${ uri . fsPath } '` ) ;
742+ repositories . push ( ...this . openRepository ( folder , uri , root , undefined , silent ) ) ;
743+ }
744+
724745 const uri = await this . findRepositoryUri ( rootUri , true ) ;
725746 if ( uri != null ) {
726747 rootPath = normalizePath ( uri . fsPath ) ;
@@ -730,8 +751,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
730751 canonicalRootPath = normalizePath ( canonicalUri . fsPath ) ;
731752 }
732753
733- Logger . log ( scope , `found root repository in '${ uri . fsPath } '` ) ;
734- repositories . push ( ...this . openRepository ( folder , uri , true , undefined , silent ) ) ;
754+ maybeAddRepo . call ( this , uri , folder , true ) ;
735755 }
736756
737757 if ( depth <= 0 || cancellation ?. isCancellationRequested ) return repositories ;
@@ -788,8 +808,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
788808 const rp = await this . findRepositoryUri ( Uri . file ( p ) , true ) ;
789809 if ( rp == null ) continue ;
790810
791- Logger . log ( scope , `found repository in '${ rp . fsPath } '` ) ;
792- repositories . push ( ...this . openRepository ( folder , rp , false , undefined , silent ) ) ;
811+ maybeAddRepo . call ( this , rp , folder , false ) ;
793812 }
794813
795814 return repositories ;
0 commit comments