summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/src
diff options
context:
space:
mode:
authorAndrey Loskutov <loskutov@gmx.de>2015-12-28 23:27:09 +0100
committerAndrey Loskutov <loskutov@gmx.de>2015-12-29 14:35:08 +0100
commitc59d86c0a79f913a8d6a62f2aa37dddcb1e2142c (patch)
tree0e62abd15736414c355968ac20f8a27d18fa8d1a /org.eclipse.jgit.pgm.test/src
parent4b7839cafd3561bbeca6ed6dabce3d9039ab8288 (diff)
downloadjgit-c59d86c0a79f913a8d6a62f2aa37dddcb1e2142c.tar.gz
jgit-c59d86c0a79f913a8d6a62f2aa37dddcb1e2142c.zip
Don't treat command termination due '-h' option as a fatal error
Signal early command termination due '-h' or '--help' option via TerminatedByHelpException. This allows tests using CLIGitCommand differentiate between unexpected command parsing errors and expected command cancellation "on help" (which also allows validation of expected/unexpected help messages). Additional side-effect: jgit supports now git style of handling help option: any unexpected command line options before help are reported as errors, but after help ignored. Bug: 484951 Change-Id: If45c41c0d32895ab6822a7ff9d851877dcef5771 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/src')
-rw-r--r--org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java31
1 files changed, 29 insertions, 2 deletions
diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
index bf15fed812..7d2cbca729 100644
--- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
+++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
@@ -50,6 +50,7 @@ import java.util.List;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.pgm.TextBuiltin.TerminatedByHelpException;
import org.eclipse.jgit.pgm.internal.CLIText;
import org.eclipse.jgit.pgm.opt.CmdLineParser;
import org.eclipse.jgit.pgm.opt.SubcommandHandler;
@@ -120,12 +121,15 @@ public class CLIGitCommand {
System.arraycopy(args, 1, argv, 0, args.length - 1);
CLIGitCommand bean = new CLIGitCommand();
- final CmdLineParser clp = new CmdLineParser(bean);
+ final CmdLineParser clp = new TestCmdLineParser(bean);
clp.parseArgument(argv);
final TextBuiltin cmd = bean.getSubcommand();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
cmd.outs = baos;
+ ByteArrayOutputStream errs = new ByteArrayOutputStream();
+ cmd.errs = errs;
+ boolean seenHelp = TextBuiltin.containsHelp(argv);
if (cmd.requiresRepository())
cmd.init(db, null);
else
@@ -133,9 +137,22 @@ public class CLIGitCommand {
try {
cmd.execute(bean.getArguments().toArray(
new String[bean.getArguments().size()]));
+ } catch (TerminatedByHelpException e) {
+ seenHelp = true;
+ // this is not a failure, command execution should just not happen
} finally {
- if (cmd.outw != null)
+ if (cmd.outw != null) {
cmd.outw.flush();
+ }
+ if (cmd.errw != null) {
+ cmd.errw.flush();
+ }
+ if (seenHelp) {
+ return errs.toByteArray();
+ } else if (errs.size() > 0) {
+ // forward the errors to the standard err
+ System.err.print(errs.toString());
+ }
}
return baos.toByteArray();
}
@@ -195,4 +212,14 @@ public class CLIGitCommand {
return list.toArray(new String[list.size()]);
}
+ static class TestCmdLineParser extends CmdLineParser {
+ public TestCmdLineParser(Object bean) {
+ super(bean);
+ }
+
+ @Override
+ protected boolean containsHelp(String... args) {
+ return false;
+ }
+ }
}