Skip to content

Commit

Permalink
fix: bug matching files that are included in gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Mar 17, 2023
1 parent c4f1079 commit e4b9ee2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ lib/**/*
.idea/

**/*.txt
!src/__tests__/test1.txt
!src/__tests__/test.txt
!src/__tests__/source-files.txt
13 changes: 10 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function run(): Promise<void> {
}
}

filePatterns += `\n${DEFAULT_EXCLUDED_FILES.filter(p => !!p).join('\n')}`
filePatterns += `\n${DEFAULT_EXCLUDED_FILES.join('\n')}`

filePatterns = [...new Set(filePatterns.split('\n').filter(p => p !== ''))]
.map(pt => {
Expand Down Expand Up @@ -205,16 +205,23 @@ export async function run(): Promise<void> {
filePaths: [gitignorePath]
})
)
.concat(DEFAULT_EXCLUDED_FILES)
.filter(p => !!p)
.map(pt => {
const parts = pt.split(path.sep)
const negated = pt.startsWith('!')
const parts = pt.replace(/^!/, '').split(path.sep)

const absolutePath = path.resolve(path.join(workingDirectory, parts[0]))

return path.join(absolutePath, ...parts.slice(1))
return `${negated ? '!' : ''}${path.join(
absolutePath,
...parts.slice(1)
)}`
})
.join('\n')

core.debug(`gitignore file patterns: ${gitignoreFilePatterns}`)

const gitIgnoreGlobber = await glob.create(
gitignoreFilePatterns,
globOptions
Expand Down

0 comments on commit e4b9ee2

Please sign in to comment.