Skip to content

Commit

Permalink
Merge pull request #13 from jscrally/fix_git_failure
Browse files Browse the repository at this point in the history
Makes failure more specific
  • Loading branch information
jeffmay authored Oct 18, 2018
2 parents 38e0e5a + 16cca87 commit 6f68500
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/scala/com/rallyhealth/sbt/versioning/GitDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,24 @@ class GitDriverImpl(dir: File) extends GitDriver {

require(isGitRepo(dir), "Must be in a git repository")

private class GitException(msg: String) extends Exception(msg)

private def isGitRepo(dir: File): Boolean = {
// this does NOT use runCommand() because that uses this method to check if the directory is a git directory
val outputLogger = new BufferingProcessLogger
// http://stackoverflow.com/a/16925062
val exitCode: Int = Process(s"""git rev-parse --is-inside-work-tree""", dir) ! outputLogger
exitCode match {
case 0 => outputLogger.stdout.mkString("").trim.toLowerCase == "true"
case _ => false
case 128 => false // https://stackoverflow.com/a/19441790
case unexpected =>
throw new GitException(
s"""Unexpected git exit status: $unexpected
|stderr:
|${outputLogger.stderr.mkString("\n")}
|stdout:
|${outputLogger.stdout.mkString("\n")}""".stripMargin
)
}
}

Expand Down

0 comments on commit 6f68500

Please sign in to comment.