diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2012-12-30 20:57:27 +0100 |
---|---|---|
committer | Robin Rosenberg <robin.rosenberg@dewire.com> | 2013-01-07 01:05:10 +0100 |
commit | 9e36b173a5fc2bab683416c5c0b7d9d4008d7f99 (patch) | |
tree | 1c398c431742a633614402975f8a631378a4fb2d /org.eclipse.jgit.pgm/src | |
parent | c2d1183e39174336605509642b6f60157b9e2c3a (diff) | |
download | jgit-9e36b173a5fc2bab683416c5c0b7d9d4008d7f99.tar.gz jgit-9e36b173a5fc2bab683416c5c0b7d9d4008d7f99.zip |
pgm: Attempt to detect a broken pipe and exit silently
When piping output to another program, the other pipe may exit
before we are done. An example is "jgit log|head". The result is
that errno get set to EPIPE. Unfortunately Java does not have
specific exception for this so we have to look at the exception
message and hope that the number of variants are small.
The detection here seem to work on Windows, Linux and OS X and it
seems the message is usually not localized.
Change-Id: Id6968ea7a53ae27ba5496303f1a479e41e41fdcc
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index 0d72e639a8..69d7d350cf 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -124,6 +124,18 @@ public class Main { err.printStackTrace(); System.exit(128); } catch (Exception err) { + // Try to detect errno == EPIPE and exit normally if that happens + // There may be issues with operating system versions and locale, + // but we can probably assume that these messages will not be thrown + // under other circumstances. + if (err.getClass() == IOException.class) { + // Linux, OS X + if (err.getMessage().equals("Broken pipe")) //$NON-NLS-1$ + System.exit(0); + // Windows + if (err.getMessage().equals("The pipe is being closed")) //$NON-NLS-1$ + System.exit(0); + } if (!showStackTrace && err.getCause() != null && err instanceof TransportException) System.err.println(MessageFormat.format(CLIText.get().fatalError, err.getCause().getMessage())); |