Skip to content

Commit

Permalink
fix(core): include hidden files when using include filters
Browse files Browse the repository at this point in the history
Previously, hidden files would not be matched, unless glob patterns
were explicitly prefixed with a period. That was unexpected behavior in
various cases, so I'd qualify that as a bug.
  • Loading branch information
edvald authored and eysi09 committed Jan 23, 2020
1 parent 06ab770 commit 320eb63
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion garden-service/src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export async function listDirectory(path: string): Promise<string[]> {
* Given a list of `paths`, return a list of paths that match any of the given `patterns`
*/
export function matchGlobs(paths: string[], patterns: string[]): string[] {
return paths.filter((path) => some(patterns, (pattern) => minimatch(path, pattern)))
return paths.filter((path) => some(patterns, (pattern) => minimatch(path, pattern, { dot: true })))
}

/**
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Module
type: exec
name: hidden-files
11 changes: 11 additions & 0 deletions garden-service/test/unit/src/build-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ describe("BuildDir", () => {
expect(await pathExists(deleteMe)).to.be.false
})

it("should sync hidden files and directories (names starting with .)", async () => {
const graph = await garden.getConfigGraph(garden.log)
const module = await graph.getModule("hidden-files")

await garden.buildDir.syncFromSrc(module, garden.log)

const buildDir = await garden.buildDir.buildPath(module)
expect(await pathExists(join(buildDir, ".hidden-file"))).to.be.true
expect(await pathExists(join(buildDir, ".hidden-dir", "something"))).to.be.true
})

it("should sync symlinks that point within the module root", async () => {
const graph = await garden.getConfigGraph(garden.log)
const module = await graph.getModule("symlink-within-module")
Expand Down
8 changes: 8 additions & 0 deletions garden-service/test/unit/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ describe("GitHandler", () => {
expect(await handler.getFiles({ path: tmpPath, include: ["foo.*"], exclude: [], log })).to.eql([{ path, hash }])
})

it("should include hidden files that match the include filter, if specified", async () => {
const path = resolve(tmpPath, ".foo")
const hash = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
await createFile(path)

expect(await handler.getFiles({ path: tmpPath, include: ["*"], exclude: [], log })).to.eql([{ path, hash }])
})

it("should filter out files that match the exclude filter, if specified", async () => {
const path = resolve(tmpPath, "foo.txt")
await createFile(path)
Expand Down

0 comments on commit 320eb63

Please sign in to comment.