Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vcs): no files were found when dotIgnoreFiles was set to empty list #1260

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise the fix doesn't work when there are no ignore files, since the count (1) is higher than the number of ignore files (0).

&& (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