From 4e1454ded6e2fcf6cb789c004756883c3ea5f77e Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Wed, 30 May 2012 02:07:25 +0200 Subject: Git API does not declare GitAPIException call() and related cleanups All commands should throw a GitAPIException so new exceptions can be added without breaking the builds of old code, i.e. anyone that calls a Git API should catch GitAPIException and not just the currently known exceptions. Now the only checked exceptions on Git API calls are GitException and subclasses of it. New checked exceptions that are subclasses of GitException may be added without breaking the API. Javadoc for GitAPIException is declared on GitCommand and inherited to subclasses. JGitInternalException is not explicitly documented anymore. Unfortunately this change itself breaks the API. The intention is that it shall be possible to add new checked subclasses of GitAPIException without breaking the API. Bug: 366914 EGit-Change-Id: I50380f13fc82c22d0036f47c7859cc3a77e767c5 Change-Id: I50380f13fc82c22d0036f47c7859cc3a77e767c5 Signed-off-by: Matthias Sohn --- .../eclipse/jgit/api/CommitAndLogCommandTests.java | 59 ++++++++-------------- 1 file changed, 20 insertions(+), 39 deletions(-) (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java index e6b6a096fa..ed32e27b0a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java @@ -50,15 +50,12 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; import java.io.PrintWriter; -import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; + +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; -import org.eclipse.jgit.api.errors.NoFilepatternException; -import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoMessageException; -import org.eclipse.jgit.api.errors.WrongRepositoryStateException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; -import org.eclipse.jgit.errors.UnmergedPathException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.PersonIdent; @@ -77,9 +74,8 @@ import org.junit.Test; */ public class CommitAndLogCommandTests extends RepositoryTestCase { @Test - public void testSomeCommits() throws NoHeadException, NoMessageException, - ConcurrentRefUpdateException, JGitInternalException, - WrongRepositoryStateException, IOException { + public void testSomeCommits() throws JGitInternalException, IOException, + GitAPIException { // do 4 commits Git git = new Git(db); @@ -115,9 +111,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testLogWithFilter() throws IOException, NoFilepatternException, - NoHeadException, NoMessageException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testLogWithFilter() throws IOException, JGitInternalException, + GitAPIException { Git git = new Git(db); @@ -170,9 +165,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { // try to do a commit without specifying a message. Should fail! @Test - public void testWrongParams() throws UnmergedPathException, - NoHeadException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testWrongParams() throws GitAPIException { Git git = new Git(db); try { git.commit().setAuthor(author).call(); @@ -185,10 +178,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { // try to work with Commands after command has been invoked. Should throw // exceptions @Test - public void testMultipleInvocations() throws NoHeadException, - ConcurrentRefUpdateException, NoMessageException, - UnmergedPathException, JGitInternalException, - WrongRepositoryStateException { + public void testMultipleInvocations() throws GitAPIException { Git git = new Git(db); CommitCommand commitCmd = git.commit(); commitCmd.setMessage("initial commit").call(); @@ -211,9 +201,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testMergeEmptyBranches() throws IOException, NoHeadException, - NoMessageException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testMergeEmptyBranches() throws IOException, + JGitInternalException, GitAPIException { Git git = new Git(db); git.commit().setMessage("initial commit").call(); RefUpdate r = db.updateRef("refs/heads/side"); @@ -235,10 +224,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testAddUnstagedChanges() throws IOException, NoHeadException, - NoMessageException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException, - NoFilepatternException { + public void testAddUnstagedChanges() throws IOException, + JGitInternalException, GitAPIException { File file = new File(db.getWorkTree(), "a.txt"); FileUtils.createNewFile(file); PrintWriter writer = new PrintWriter(file); @@ -268,9 +255,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testModeChange() throws IOException, NoFilepatternException, - NoHeadException, NoMessageException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testModeChange() throws IOException, GitAPIException { Git git = new Git(db); // create file @@ -298,10 +283,9 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testCommitRange() throws NoHeadException, NoMessageException, - UnmergedPathException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException, - IncorrectObjectTypeException, MissingObjectException { + public void testCommitRange() throws GitAPIException, + JGitInternalException, MissingObjectException, + IncorrectObjectTypeException { // do 4 commits and set the range to the second and fourth one Git git = new Git(db); git.commit().setMessage("first commit").call(); @@ -334,9 +318,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testCommitAmend() throws NoHeadException, NoMessageException, - ConcurrentRefUpdateException, JGitInternalException, - WrongRepositoryStateException, IOException { + public void testCommitAmend() throws JGitInternalException, IOException, + GitAPIException { Git git = new Git(db); git.commit().setMessage("first comit").call(); // typo git.commit().setAmend(true).setMessage("first commit").call(); @@ -357,10 +340,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testInsertChangeId() throws NoHeadException, - NoMessageException, - UnmergedPathException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testInsertChangeId() throws JGitInternalException, + GitAPIException { Git git = new Git(db); String messageHeader = "Some header line\n\nSome detail explanation\n"; String changeIdTemplate = "\nChange-Id: I" -- cgit v1.2.3