@@ -151,10 +151,18 @@ export default class GithubPackage {
151151 }
152152
153153 async repositoryForProjectDirectory ( projectDirectory ) {
154- let repository = this . repositoriesByProjectDirectory . get ( projectDirectory ) ;
154+ const projectDirectoryPath = projectDirectory . getPath ( )
155+ let repository = this . repositoriesByProjectDirectory . get ( projectDirectoryPath ) ;
155156 if ( ! repository ) {
156157 repository = await Repository . open ( projectDirectory ) ;
157- if ( repository ) { this . repositoriesByProjectDirectory . set ( projectDirectory , repository ) ; }
158+ if ( this . repositoriesByProjectDirectory . has ( projectDirectoryPath ) ) {
159+ // Someone else found and set the repo in the cache while we were nabbing it.
160+ // Defer to that repo.
161+ repository . destroy ( ) ;
162+ repository = this . repositoriesByProjectDirectory . get ( projectDirectoryPath ) ;
163+ } else if ( repository ) {
164+ this . repositoriesByProjectDirectory . set ( projectDirectoryPath , repository ) ;
165+ }
158166 }
159167 return repository ;
160168 }
@@ -164,11 +172,11 @@ export default class GithubPackage {
164172 }
165173
166174 destroyRepositoriesForRemovedProjectFolders ( ) {
167- const projectDirectories = this . project . getDirectories ( ) ;
168- for ( const [ projectDirectory , repository ] of this . repositoriesByProjectDirectory ) {
169- if ( projectDirectories . indexOf ( projectDirectory ) === - 1 ) {
175+ const projectDirectoryPaths = this . project . getDirectories ( ) . map ( dir => dir . getPath ( ) ) ;
176+ for ( const [ projectDirectoryPath , repository ] of this . repositoriesByProjectDirectory ) {
177+ if ( projectDirectoryPaths . indexOf ( projectDirectoryPath ) === - 1 ) {
170178 repository . destroy ( ) ;
171- this . repositoriesByProjectDirectory . delete ( projectDirectory ) ;
179+ this . repositoriesByProjectDirectory . delete ( projectDirectoryPath ) ;
172180 }
173181 }
174182 }
0 commit comments