Skip to content

Commit

Permalink
fix(vcs): handle case when file is removed while listing VCS files
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored and thsig committed Apr 10, 2019
1 parent 0fcc7f2 commit 7aeec2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions garden-service/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,23 @@ export class GitHandler extends VcsHandler {

return Bluebird.map(filtered, async (f) => {
const resolvedPath = resolve(path, f.path)

if (!f.hash || modified.has(f.path)) {
const hash = (await git("hash-object", resolvedPath))[0]
// If we can't compute the hash, i.e. the file is gone, we filter it out below
let hash = ""
try {
hash = (await git("hash-object", resolvedPath))[0]
} catch (err) {
// 128 = File no longer exists
if (err.code !== 128) {
throw err
}
}
return { path: resolvedPath, hash }
} else {
return { path: resolvedPath, hash: f.hash }
}
})
}).filter(f => f.hash !== "")
}

// TODO Better auth handling
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export class Watcher {
const _this = this

return (path: string) => {
// Make sure Promise errors are handled appropriately.
listener(path)
.catch(err => {
console.log("catch", err)
_this.watcher.emit("error", err)
})
}
Expand Down

0 comments on commit 7aeec2f

Please sign in to comment.