Skip to content

Commit

Permalink
Fix subfolder Git detection (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshgupta137 authored Nov 4, 2020
1 parent 6a03d25 commit ced554b
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions lib/resource.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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();
}
});
}


Expand Down Expand Up @@ -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);
}


Expand Down

0 comments on commit ced554b

Please sign in to comment.