Browse Source

GitHook: use default charset for output and error streams

External scripts most probably expect the default charset.

Change-Id: I318a5e1d9f536a95e70c06ffb5b6f408cd40f73a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v5.11.0.202102240950-m3
Matthias Sohn 3 years ago
parent
commit
f17f8e8ba9
1 changed files with 6 additions and 4 deletions
  1. 6
    4
      org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java

+ 6
- 4
org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java View File

*/ */
package org.eclipse.jgit.hooks; package org.eclipse.jgit.hooks;


import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;


import org.eclipse.jgit.api.errors.AbortedByHookException; import org.eclipse.jgit.api.errors.AbortedByHookException;
* *
* @throws org.eclipse.jgit.api.errors.AbortedByHookException * @throws org.eclipse.jgit.api.errors.AbortedByHookException
* If the underlying hook script exited with non-zero. * If the underlying hook script exited with non-zero.
* @throws IOException
* if an IO error occurred
*/ */
protected void doRun() throws AbortedByHookException {
protected void doRun() throws AbortedByHookException, IOException {
final ByteArrayOutputStream errorByteArray = new ByteArrayOutputStream(); final ByteArrayOutputStream errorByteArray = new ByteArrayOutputStream();
final TeeOutputStream stderrStream = new TeeOutputStream(errorByteArray, final TeeOutputStream stderrStream = new TeeOutputStream(errorByteArray,
getErrorStream()); getErrorStream());
getStdinArgs()); getStdinArgs());
if (result.isExecutedWithError()) { if (result.isExecutedWithError()) {
throw new AbortedByHookException( throw new AbortedByHookException(
new String(errorByteArray.toByteArray(), UTF_8),
new String(errorByteArray.toByteArray(),
Charset.defaultCharset().name()),
getHookName(), result.getExitCode()); getHookName(), result.getExitCode());
} }
} }

Loading…
Cancel
Save