Skip to content

Commit

Permalink
fix: process all the gitignore files in the root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 27, 2021
1 parent 022bfe8 commit 054f353
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions lib/paths-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { EventEmitter } from "events"
import minimatch from "minimatch"
import { Directory, File } from "atom"
import { dirname } from "path"
import { union } from "./utils"
import { globifyPath, globifyDirectory, globifyGitIgnoreFile } from "globify-gitignore"
import glob from "fast-glob"
Expand Down Expand Up @@ -434,18 +435,28 @@ export default class PathsCache extends EventEmitter {
}

/**
* Returns the glob pattern of a gitignore of a directory
* @param {string} directoryPath
* Returns the glob pattern of all gitignore files in a directory
* @param {string} rootDirectory
* @param {string[]} ignoredPatternsGlob
* @returns {Promise<Array<string>>} an array of glob patterns
* @private
*/
async _getGitIgnoreGlob(directoryPath) {
async _getAllGitIgnoreGlob(rootDirectory, ignoredPatternsGlob) {
if (this.config.excludeVcsIgnoredPaths) {
try {
return await globifyGitIgnoreFile(directoryPath)
} catch (err) {
// .gitignore does not exist for this directory, ignoring
}
// get gitignore files
const gitignoreFiles = await glob(
["**/.gitignore", ...ignoredPatternsGlob],
// glob options
{
dot: true,
cwd: rootDirectory,
onlyFiles: true,
absolute: true,
}
)
return (
await Promise.all(gitignoreFiles.map((gitignoreFile) => _getDirectoryGitIgnoreGlob(dirname(gitignoreFile))))
).flat()
}
return []
}
Expand All @@ -456,8 +467,8 @@ export default class PathsCache extends EventEmitter {
* @returns {Promise<string[]>}
*/
async _getAllIgnoredGlob(directoryPath) {
const gitignoreGlob = await this._getGitIgnoreGlob(directoryPath)
const ignoredPatternsGlob = await this._getIgnoredPatternsGlob(directoryPath)
const gitignoreGlob = await this._getAllGitIgnoreGlob(directoryPath, ignoredPatternsGlob)
return [...gitignoreGlob, ...ignoredPatternsGlob]
}

Expand Down Expand Up @@ -558,3 +569,18 @@ export default class PathsCache extends EventEmitter {
return Promise.all(directories.map((dir) => this._cachePathsForDirectoryWithAtom(projectDirectory, dir)))
}
}

/**
* Returns the glob pattern of a gitignore of a directory
* @param {string} directoryPath
* @returns {Promise<Array<string>>} an array of glob patterns
* @private
*/
function _getDirectoryGitIgnoreGlob(directoryPath) {
try {
return globifyGitIgnoreFile(directoryPath)
} catch (err) {
// .gitignore does not exist for this directory, ignoring
return []
}
}

0 comments on commit 054f353

Please sign in to comment.