Skip to content

Commit

Permalink
fix(vcs): error when handling files with spaces in the name
Browse files Browse the repository at this point in the history
Closes #797
  • Loading branch information
edvald authored and thsig committed Jun 6, 2019
1 parent 6693195 commit eeff4d4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions garden-service/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,19 @@ export class GitHandler extends VcsHandler {
}

const files = await Bluebird.map(lines, async (line) => {
const split = line.trim().split(" ")
const split = line.trim().split("\t")
if (split.length === 1) {
// File is untracked
return { path: split[0] }
} else {
return { path: split[2].split("\t")[1], hash: split[1] }
return { path: split[1], hash: split[0].split(" ")[1] }
}
})

const modifiedArr = ((await this.getModifiedFiles(git, path)) || [])
.map(modifiedRelPath => resolve(gitRoot, modifiedRelPath))
const modified = new Set(modifiedArr)

const filtered = files
.filter(f => !include || matchGlobs(f.path, include))
.filter(f => !ignored.includes(f.path))
Expand Down
37 changes: 37 additions & 0 deletions garden-service/test/unit/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,43 @@ describe("GitHandler", () => {
])
})

it("should work with tracked files with spaces in the name", async () => {
const filePath = join(tmpPath, "my file.txt")
await createFile(filePath)
await git("add", filePath)
await git("commit", "-m", "foo")
const hash = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"

expect(await handler.getFiles(tmpPath)).to.eql([
{ path: resolve(tmpPath, "my file.txt"), hash },
])
})

it("should work with tracked+modified files with spaces in the name", async () => {
const filePath = join(tmpPath, "my file.txt")
await createFile(filePath)
await git("add", filePath)
await git("commit", "-m", "foo")

await writeFile(filePath, "fooooo")

const hash = "099673697c6cbf5c1a96c445ef3eab123740c778"

expect(await handler.getFiles(tmpPath)).to.eql([
{ path: resolve(tmpPath, "my file.txt"), hash },
])
})

it("should work with untracked files with spaces in the name", async () => {
const filePath = join(tmpPath, "my file.txt")
await createFile(filePath)
const hash = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"

expect(await handler.getFiles(tmpPath)).to.eql([
{ path: resolve(tmpPath, "my file.txt"), hash },
])
})

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

0 comments on commit eeff4d4

Please sign in to comment.