Skip to content

Commit

Permalink
Merge pull request #47 from bmarwell/#29_native_git_stderr
Browse files Browse the repository at this point in the history
[#29] output stdout, stderr on error.
  • Loading branch information
georgberky authored Aug 25, 2022
2 parents 8abb8af + d9bfbdb commit 5c06812
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,25 @@ open class NativeGitProvider(val localRepositoryDirectory: Path) : GitProvider {
if(returnValue != 0) {
throw ProcessException("Native git invocation failed. " +
"Command: ${command.joinToString(" ")}, " +
"return value was: $returnValue")
"return value was: $returnValue\n" +
"stdout was: ${result.second}\n" +
"stderr was: ${result.third}")
}

return result
return Pair(returnValue, result.second)
}

open fun run(vararg command: String): Pair<Int, String> {
open fun run(vararg command: String): Triple<Int, String, String> {

val process = ProcessBuilder(*command)
.directory(localRepositoryDirectory.toFile())
.start()

val returnValue = process.waitFor()
val processOutput = IOUtils.toString(process.inputStream)
return Pair(returnValue, processOutput)
val processOutput = IOUtils.toString(process.inputStream, StandardCharsets.UTF_8)
val processErr = IOUtils.toString(process.errorStream, StandardCharsets.UTF_8)

return Triple(returnValue, processOutput, processErr)
}

class ProcessException(message: String?) : RuntimeException(message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ internal class NativeGitProviderErrorHandlingTest {
@BeforeEach
internal fun setUp() {
gitProvider = object : NativeGitProvider(tempDir.toPath()) {
override fun run(vararg command: String): Pair<Int, String> {
return Pair(returnValue, processOutput)
override fun run(vararg command: String): Triple<Int, String, String> {
return Triple(returnValue, processOutput, "")
}
}
}
Expand Down

0 comments on commit 5c06812

Please sign in to comment.