Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subfolder git detection #9

Merged
merged 2 commits into from
Nov 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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