Skip to content

Commit e6c8c7a

Browse files
authored
Merge pull request #154 from edgardmessias/improved_149
Improved solution of #149
2 parents 19b17bb + 830d4ae commit e6c8c7a

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

src/model.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import * as path from "path";
1212
import * as micromatch from "micromatch";
1313
import { Repository, RepositoryState } from "./repository";
1414
import { 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";
1622
import { sequentialize } from "./decorators";
1723

1824
export 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

Comments
 (0)