Skip to content

Commit

Permalink
Merge pull request #342 from garden-io/fix-empty-repo-error
Browse files Browse the repository at this point in the history
fix(git): error when running before first commit is made in repo (#324)
  • Loading branch information
eysi09 authored Oct 27, 2018
2 parents 41acde5 + 7dd77ae commit 45255ca
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 45255ca

Please sign in to comment.