diff --git a/lib/resource.js b/lib/resource.js index 8cb9ea4..04c6670 100644 --- a/lib/resource.js +++ b/lib/resource.js @@ -1,7 +1,7 @@ "use strict"; const {basename} = require("path"); -const {CompositeDisposable, Disposable, Emitter} = require("atom"); +const {CompositeDisposable, Directory, Disposable, Emitter} = require("atom"); const {lstat, realpath, statify, normalisePath} = require("./utils.js"); const MappedDisposable = require("mapped-disposable"); const EntityType = require("./entity-type.js"); @@ -31,11 +31,12 @@ class Resource{ this.name = basename(path); this.consumeStats(stats); - const repo = this.getRepository(); - if(null !== repo){ - this.repo = repo; - this.watchRepo(); - } + this.getRepository().then(repo => { + if(null !== repo){ + this.repo = repo; + this.watchRepo(); + } + }); } @@ -189,24 +190,8 @@ class Resource{ * @return {GitRepository} */ getRepository(){ - const resourcePath = this.realPath || this.path; - - // Shouldn't happen, but #493 had other ideas. - if(!resourcePath) return null; - - const projects = atom.project.getPaths(); - const {length} = projects; - for(let i = 0; i < length; ++i){ - const projectPath = normalisePath(projects[i]); - - if(!projectPath) - continue; - - if(projectPath === resourcePath || 0 === resourcePath.indexOf(projectPath + "/")) - return atom.project.getRepositories()[i] || null; - } - - return null; + const directory = new Directory(this.realPath || this.path); + return atom.project.repositoryForDirectory(directory); }