From fb5056c2c5e96b815abe568af588157083c66197 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Sun, 3 Jan 2016 16:15:34 +0100 Subject: branch command: print help if requested, even if arguments are wrong git branch -d -h reports an error (because of missing -d option value) but does not print the help as expected. To fix this, CmdLineParser must catch, print but do not propagate exceptions if help is requested. Bug: 484951 Change-Id: I51265ebe295f22da540792c6a1980b8bdb295a02 Signed-off-by: Andrey Loskutov --- .../tst/org/eclipse/jgit/pgm/BranchTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit') diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java index 74506bc944..f1a53d7dcc 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java @@ -53,6 +53,7 @@ import org.eclipse.jgit.api.Git; import org.eclipse.jgit.lib.CLIRepositoryTestCase; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.RefUpdate; +import org.eclipse.jgit.pgm.internal.CLIText; import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Before; import org.junit.Test; @@ -65,6 +66,15 @@ public class BranchTest extends CLIRepositoryTestCase { new Git(db).commit().setMessage("initial commit").call(); } + @Test + public void testHelpAfterDelete() throws Exception { + String err = toString(executeUnchecked("git branch -d")); + String help = toString(executeUnchecked("git branch -h")); + String errAndHelp = toString(executeUnchecked("git branch -d -h")); + assertEquals(CLIText.fatalError(CLIText.get().branchNameRequired), err); + assertEquals(toString(err, help), errAndHelp); + } + @Test public void testList() throws Exception { assertEquals("* master", toString(execute("git branch"))); -- cgit v1.2.3