@@ -12,7 +12,13 @@ import * as path from "path";
1212import * as micromatch from "micromatch" ;
1313import { Repository , RepositoryState } from "./repository" ;
1414import { Svn } from "./svn" ;
15- import { dispose , anyEvent , filterEvent , IDisposable } from "./util" ;
15+ import {
16+ dispose ,
17+ anyEvent ,
18+ filterEvent ,
19+ IDisposable ,
20+ isDescendant
21+ } from "./util" ;
1622import { sequentialize } from "./decorators" ;
1723
1824export interface ModelChangeEvent {
@@ -248,34 +254,17 @@ export class Model implements IDisposable {
248254 }
249255
250256 if ( hint instanceof Repository ) {
251- return this . openRepositories . filter ( r => r . repository === hint ) [ 0 ] ;
257+ return this . openRepositories . find ( r => r . repository === hint ) ;
252258 }
253259
254260 if ( typeof hint === "string" ) {
255261 hint = Uri . file ( hint ) ;
256262 }
257263
258264 if ( hint instanceof Uri ) {
259- for ( const liveRepository of this . openRepositories ) {
260- //if on different drive not need to check
261- if (
262- liveRepository . repository . workspaceRoot . split ( path . sep ) [ 0 ] !==
263- hint . fsPath . split ( path . sep ) [ 0 ]
264- ) {
265- return undefined ;
266- }
267-
268- const relativePath = path . relative (
269- liveRepository . repository . workspaceRoot ,
270- hint . fsPath
271- ) ;
272-
273- if ( ! / ^ \. \. / . test ( relativePath ) ) {
274- return liveRepository ;
275- }
276- }
277-
278- return undefined ;
265+ return this . openRepositories . find ( liveRepository =>
266+ isDescendant ( liveRepository . repository . workspaceRoot , hint . fsPath )
267+ ) ;
279268 }
280269
281270 for ( const liveRepository of this . openRepositories ) {
0 commit comments