Skip to content

Commit

Permalink
Support all possible patterns for git
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed Sep 28, 2019
1 parent a662e98 commit d1f070f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 9 additions & 7 deletions src/index.js
Expand Up @@ -9,7 +9,8 @@ const {
getOptions,
getScm,
getRanges,
getPathInHostNodeModules
getPathInHostNodeModules,
createMatcher
} = require('./utils')

const DEFAULT_IGNORE = [
Expand Down Expand Up @@ -96,10 +97,10 @@ async function run (cwd, config) {

// They ignore files relative to current directory
const filters = [
// Ignore .prettierignore entries
createIgnorer(cwd),
// Ignore unsupported extensions
isSupportedExtension
isSupportedExtension,
// Ignore .prettierignore entries
createIgnorer(cwd)
]

const runFilters = path => filters.reduce((a, b) => a && b(path), true)
Expand Down Expand Up @@ -154,15 +155,16 @@ async function run (cwd, config) {

root = scm.dir

// Ignore non-matched patterns
filters.push(createMatcher(path.relative(root, cwd), config.patterns))

const revision = scm.getRevision(config.since || 'HEAD')

if (!revision) {
return new Error(`Cannot find ${scm.name()} revision ${config.since}`)
}

files = scm
.getChanges(revision, config.patterns)
.filter(p => runFilters(p.filepath))
files = scm.getChanges(revision).filter(p => runFilters(p.filepath))
} else {
patterns = patterns.concat(DEFAULT_IGNORE)

Expand Down
7 changes: 4 additions & 3 deletions src/utils.js
Expand Up @@ -38,9 +38,10 @@ function createMatcher (relative, patterns) {
return () => true
}

return file =>
multimatch(path.relative(relative, file), patterns, { dot: true }).length >
0
return file => {
const relativepath = path.relative(relative, file)
return multimatch(relativepath, patterns, { dot: true }).length > 0
}
}

const defaultOptions = {
Expand Down

0 comments on commit d1f070f

Please sign in to comment.