Skip to content

Commit 3a3d883

Browse files
authored
Merge pull request #66 from GrantBirki/better-gitignore-support
Better gitignore support
2 parents d7814b9 + 65c3073 commit 3a3d883

File tree

8 files changed

+689
-210
lines changed

8 files changed

+689
-210
lines changed

__tests__/fixtures/exclude/exclude.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ dog.txt
1717
!dog.txt
1818

1919
# test with a regex pattern match
20-
/^.*cars.*\.txt$/
20+
*cars*.txt

__tests__/functions/exclude.test.js

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as core from '@actions/core'
22
import {Exclude} from '../../src/functions/exclude'
33

4-
const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {})
54
const warningMock = jest.spyOn(core, 'warning').mockImplementation(() => {})
65

76
var exclude
87
beforeEach(() => {
98
jest.clearAllMocks()
9+
jest.spyOn(core, 'debug').mockImplementation(() => {})
1010
process.env.INPUT_EXCLUDE_FILE = '__tests__/fixtures/exclude/exclude.txt'
1111
process.env.INPUT_GIT_IGNORE_PATH = '.gitignore'
1212
process.env.INPUT_USE_GITIGNORE = 'true'
@@ -15,60 +15,26 @@ beforeEach(() => {
1515

1616
test('successfully excludes a file', () => {
1717
expect(exclude.isExcluded('exclude-me.json')).toBe(true)
18-
expect(debugMock).toHaveBeenCalledWith(
19-
`file exactly matches exclude pattern: exclude-me.json`
20-
)
2118
})
2219

2320
test('successfully excludes a with a glob match', () => {
2421
expect(exclude.isExcluded('src/dev/app/nope.exclude')).toBe(true)
25-
expect(debugMock).toHaveBeenCalledWith(
26-
`file matches exclude glob pattern: *.exclude`
27-
)
28-
})
29-
30-
test('successfully does not exclude a negate pattern match', () => {
31-
expect(exclude.isExcluded('cat.txt')).toBe(false)
32-
expect(debugMock).toHaveBeenCalledWith(
33-
`file matches exclude negation pattern: !cat.txt`
34-
)
35-
})
36-
37-
test('successfully excludes a file where the negate pattern matches after', () => {
38-
expect(exclude.isExcluded('dog.txt')).toBe(true)
39-
expect(debugMock).toHaveBeenCalledWith(
40-
`file exactly matches exclude pattern: dog.txt`
41-
)
4222
})
4323

4424
test('successfully excludes with a regex pattern match', () => {
4525
expect(exclude.isExcluded('src/app/cars-and-a-bus.txt')).toBe(true)
46-
expect(debugMock).toHaveBeenCalledWith(
47-
`file matches exclude regex pattern: /^.*cars.*\\.txt$/`
48-
)
4926
})
5027

5128
test('successfully excludes a file in a dir one level down', () => {
52-
expect(exclude.isExcluded('./evil-base-dir/exclude-me.json')).toBe(true)
53-
expect(debugMock).toHaveBeenCalledWith(
54-
`file is in exclude directory: evil-base-dir/`
55-
)
29+
expect(exclude.isExcluded('evil-base-dir/exclude-me.json')).toBe(true)
5630
})
5731

5832
test('successfully excludes a file in a dir two levels down', () => {
59-
expect(exclude.isExcluded('./evil-base-dir/sub-dir/exclude-me.json')).toBe(
60-
true
61-
)
62-
expect(debugMock).toHaveBeenCalledWith(
63-
`file is in exclude directory: evil-base-dir/`
64-
)
33+
expect(exclude.isExcluded('evil-base-dir/sub-dir/exclude-me.json')).toBe(true)
6534
})
6635

6736
test('successfully checks a file and finds that it is not excluded', () => {
6837
expect(exclude.isExcluded('exclude-me-nope.json')).toBe(false)
69-
expect(debugMock).toHaveBeenCalledWith(
70-
`file 'exclude-me-nope.json' did not match any exclude patterns`
71-
)
7238
})
7339

7440
test('does not exclude any files when no exclude file is used', () => {
@@ -82,7 +48,6 @@ test('excludes a file that is not tracked by git', () => {
8248
process.env.INPUT_EXCLUDE_FILE = ''
8349
const exclude = new Exclude()
8450
expect(exclude.isExcluded('tmp/test.json')).toBe(true)
85-
expect(debugMock).toHaveBeenCalledWith(`file is in exclude directory: tmp/`)
8651
})
8752

8853
test('fails to read the .gitignore file', () => {

0 commit comments

Comments
 (0)