diff options
author | Ned Twigg <ned.twigg@diffplug.com> | 2016-03-18 02:37:58 -0700 |
---|---|---|
committer | Ned Twigg <ned.twigg@diffplug.com> | 2017-10-01 00:07:26 -0400 |
commit | f333c7496b1352801dddc7dfe488efbcfd2ca4a8 (patch) | |
tree | 36a058769d156afe8004974a14cfa830157d0916 /org.eclipse.jgit.pgm.test/tst/org/eclipse | |
parent | a0a8a6a3e48d4f872e92dfed4ee6b40a5a177a42 (diff) | |
download | jgit-f333c7496b1352801dddc7dfe488efbcfd2ca4a8.tar.gz jgit-f333c7496b1352801dddc7dfe488efbcfd2ca4a8.zip |
Checkout now reports failures through exceptions.
Checkout sometimes throws an exception, and
other times it writes an error message to outw
and returns normally, even though the command
failed. This commit now reports all failures
through a die() exception.
Change-Id: I038a5d976d95020fea3faac68e9178f923c25b28
Signed-off-by: Ned Twigg <ned.twigg@diffplug.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse')
-rw-r--r-- | org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java index 4b86b6014e..a98dd1cf98 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java @@ -71,6 +71,23 @@ import org.junit.Assume; import org.junit.Test; public class CheckoutTest extends CLIRepositoryTestCase { + /** + * Executes specified git command (with arguments), captures exception and + * returns its message as an array of lines. Throws an AssertionError if no + * exception is thrown. + * + * @param command + * a valid git command line, e.g. "git branch -h" + * @return message contained within the exception + */ + private String[] executeExpectingException(String command) { + try { + execute(command); + throw new AssertionError("Expected Die"); + } catch (Exception e) { + return e.getMessage().split(System.lineSeparator()); + } + } @Test public void testCheckoutSelf() throws Exception { @@ -107,7 +124,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { public void testCheckoutNonExistingBranch() throws Exception { assertStringArrayEquals( "error: pathspec 'side' did not match any file(s) known to git.", - execute("git checkout side")); + executeExpectingException("git checkout side")); } @Test @@ -131,7 +148,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { public void testCheckoutUnresolvedHead() throws Exception { assertStringArrayEquals( "error: pathspec 'HEAD' did not match any file(s) known to git.", - execute("git checkout HEAD")); + executeExpectingException("git checkout HEAD")); } @Test @@ -159,7 +176,8 @@ public class CheckoutTest extends CLIRepositoryTestCase { writeTrashFile("a", "New Hello world a"); git.add().addFilepattern(".").call(); - String[] execute = execute("git checkout branch_1"); + String[] execute = executeExpectingException( + "git checkout branch_1"); assertEquals( "error: Your local changes to the following files would be overwritten by checkout:", execute[0]); |