Skip to content

Commit

Permalink
fix(git): error when running before first commit is made in repo (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored and eysi09 committed Oct 27, 2018
1 parent 41acde5 commit 7dd77ae
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions garden-service/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,31 @@ export class GitHandler extends VcsHandler {
]) || NEW_MODULE_VERSION
} catch (err) {
if (err.code === 128) {
// not in a repo root, return default version
// not in a repo root, use default version
commitHash = NEW_MODULE_VERSION
} else {
throw err
}
}

let latestDirty = 0
let modifiedFiles: string[] = []

const res = await git("diff-index", ["--name-only", "HEAD", path]) + "\n"
+ await git("ls-files", ["--other", "--exclude-standard", path])
try {
modifiedFiles = (await git("diff-index", ["--name-only", "HEAD", path])).split("\n")
} catch (err) {
if (err.code === 128) {
// no commit in repo, use default version
commitHash = NEW_MODULE_VERSION
} else {
throw err
}
}

const newFiles = (await git("ls-files", ["--other", "--exclude-standard", path])).split("\n")

const dirtyFiles: string[] = modifiedFiles.concat(newFiles).filter((f) => f.length > 0)

const dirtyFiles: string[] = res.split("\n").filter((f) => f.length > 0)
// for dirty trees, we append the last modified time of last modified or added file
if (dirtyFiles.length) {
const repoRoot = await git("rev-parse", ["--show-toplevel"])
Expand Down

0 comments on commit 7dd77ae

Please sign in to comment.