Skip to content

Commit

Permalink
Merge pull request #1260 from garden-io/fix-empty-dotignores
Browse files Browse the repository at this point in the history
fix(vcs): no files were found when dotIgnoreFiles was set to empty list
  • Loading branch information
eysi09 authored Oct 11, 2019
2 parents db365b2 + 1d475af commit 920302e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
33 changes: 22 additions & 11 deletions garden-service/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class GitHandler extends VcsHandler {

private gitCli(log: LogEntry, cwd: string): GitCli {
return async (...args: string[]) => {
log.silly(`Calling git with args '${args.join(" ")}`)
log.silly(`Calling git with args '${args.join(" ")}'`)
const { stdout } = await execa("git", args, { cwd, maxBuffer: 10 * 1024 * 1024 })
return stdout.split("\n").filter(line => line.length > 0)
}
Expand Down Expand Up @@ -113,11 +113,11 @@ export class GitHandler extends VcsHandler {
)

// List tracked but ignored files (we currently exclude those as well, so we need to query that specially)
const trackedButIgnored = new Set(flatten(
await Promise.all(this.ignoreFiles.map(f =>
git("ls-files", "--ignored", "--exclude-per-directory", f),
)),
))
const trackedButIgnored = new Set(
this.ignoreFiles.length === 0 ? [] : flatten(
await Promise.all(this.ignoreFiles.map(f => git("ls-files", "--ignored", "--exclude-per-directory", f))),
),
)

// List all submodule paths in the current repo
const submodulePaths = (await this.getSubmodules(gitRoot)).map(s => join(gitRoot, s.path))
Expand Down Expand Up @@ -166,16 +166,20 @@ export class GitHandler extends VcsHandler {
// We push to the output array when all ls-files commands "agree" that it should be included,
// and it passes through the include/exclude filters.
if (
paths[resolvedPath] === this.ignoreFiles.length
paths[resolvedPath] >= this.ignoreFiles.length
&& (matchPath(filePath, include, exclude) || submodulePaths.includes(resolvedPath))
) {
files.push({ path: resolvedPath, hash })
}
}

// We run ls-files for each ignore file and collect each return result line with `handleLine`
await Bluebird.map(this.ignoreFiles, async (f) => {
const args = ["ls-files", "-s", "--others", "--exclude", this.gardenDirPath, "--exclude-per-directory", f, path]
const lsFiles = async (ignoreFile?: string) => {
const args = ["ls-files", "-s", "--others", "--exclude", this.gardenDirPath]
if (ignoreFile) {
args.push("--exclude-per-directory", ignoreFile)
}
args.push(path)

const proc = execa("git", args, { cwd: path })

// Split the command output by line
Expand All @@ -191,7 +195,14 @@ export class GitHandler extends VcsHandler {
throw err
}
}
})
}

if (this.ignoreFiles.length === 0) {
await lsFiles()
} else {
// We run ls-files for each ignore file and collect each return result line with `handleLine`
await Bluebird.map(this.ignoreFiles, lsFiles)
}

// Resolve submodules
const withSubmodules = flatten(await Bluebird.map(files, async (f) => {
Expand Down
17 changes: 17 additions & 0 deletions garden-service/test/unit/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,23 @@ describe("GitHandler", () => {
expect(files).to.eql([])
})

it("should work without ignore files", async () => {
const path = resolve(tmpPath, "foo.txt")

await createFile(path)
await writeFile(path, "my change")
await git("add", ".")
await git("commit", "-m", "foo")

const hash = "6e1ab2d7d26c1c66f27fea8c136e13c914e3f137"

const _handler = new GitHandler(tmpPath, [])

expect(await _handler.getFiles({ path: tmpPath, log })).to.eql([
{ path, hash },
])
})

it("should correctly handle multiple ignore files", async () => {
const nameA = "foo.txt"
const nameB = "boo.txt"
Expand Down

0 comments on commit 920302e

Please sign in to comment.