diff --git a/lib/load-paths-handler.js b/lib/load-paths-handler.js index 0f8acadf..eb09ec54 100644 --- a/lib/load-paths-handler.js +++ b/lib/load-paths-handler.js @@ -6,6 +6,8 @@ const path = require('path') const {GitRepository} = require('atom') const {Minimatch} = require('minimatch') +const childProcess = require('child_process') + const PathsChunkSize = 100 const emittedPaths = new Set() @@ -27,6 +29,12 @@ class PathLoader { } load (done) { + if (this.repo && !this.traverseSymlinkDirectories) { + this.loadFromGit().then(done) + + return + } + this.loadPath(this.rootPath, true, () => { this.flushPaths() if (this.repo != null) this.repo.destroy() @@ -34,6 +42,33 @@ class PathLoader { }) } + async loadFromGit () { + return new Promise((resolve) => { + const args = ['ls-files', '--cached', '--exclude-standard', '--others', '-z'] + + for (let ignoredName of this.ignoredNames) { + args.push('--exclude', ignoredName.pattern) + } + + let output = '' + + // TODO: do this via a call to GitRepository (needs to be implemented). + const result = childProcess.spawn('git', args, {cwd: this.rootPath}) + result.stdout.on('data', chunk => { + const files = (output + chunk).split('\0') + output = files.pop() + + for (const file of files) { + this.pathLoaded(file) + } + }) + result.on('close', () => { + this.flushPaths() + resolve() + }) + }) + } + isIgnored (loadedPath) { const relativePath = path.relative(this.rootPath, loadedPath) if (this.repo && this.repo.isPathIgnored(relativePath)) { @@ -54,7 +89,8 @@ class PathLoader { if (this.paths.length === PathsChunkSize) { this.flushPaths() } - done() + + done && done() } flushPaths () {