Browse Source

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 <matthias.sohn@sap.com>
tags/v2.0.0.201206130900-r
Robin Rosenberg 12 years ago
parent
commit
4e1454ded6
63 changed files with 275 additions and 303 deletions
  1. 1
    1
      org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCloneTask.java
  2. 1
    1
      org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitInitTask.java
  3. 11
    8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java
  4. 1
    3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
  5. 3
    8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
  6. 6
    4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java
  7. 8
    4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
  8. 20
    39
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
  9. 5
    2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java
  10. 8
    3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java
  11. 7
    18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
  12. 2
    2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java
  13. 3
    1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
  14. 6
    26
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
  15. 4
    19
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java
  16. 5
    7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
  17. 5
    4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
  18. 7
    6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java
  19. 13
    7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleStatusTest.java
  20. 2
    1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java
  21. 6
    3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java
  22. 2
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
  23. 2
    5
      org.eclipse.jgit/src/org/eclipse/jgit/api/AddNoteCommand.java
  24. 2
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/BlameCommand.java
  25. 4
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
  26. 3
    2
      org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java
  27. 8
    10
      org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
  28. 11
    15
      org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
  29. 3
    2
      org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java
  30. 4
    2
      org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java
  31. 2
    4
      org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteTagCommand.java
  32. 4
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java
  33. 6
    7
      org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java
  34. 10
    0
      org.eclipse.jgit/src/org/eclipse/jgit/api/GitCommand.java
  35. 2
    3
      org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java
  36. 3
    6
      org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java
  37. 3
    3
      org.eclipse.jgit/src/org/eclipse/jgit/api/ListNotesCommand.java
  38. 2
    3
      org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java
  39. 7
    6
      org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
  40. 3
    5
      org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java
  41. 2
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
  42. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java
  43. 3
    6
      org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
  44. 9
    10
      org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
  45. 2
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/ReflogCommand.java
  46. 2
    5
      org.eclipse.jgit/src/org/eclipse/jgit/api/RemoveNoteCommand.java
  47. 3
    2
      org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java
  48. 2
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
  49. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java
  50. 3
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/RmCommand.java
  51. 2
    5
      org.eclipse.jgit/src/org/eclipse/jgit/api/ShowNoteCommand.java
  52. 3
    4
      org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java
  53. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
  54. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java
  55. 2
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java
  56. 10
    5
      org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java
  57. 2
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleAddCommand.java
  58. 2
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleInitCommand.java
  59. 2
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleStatusCommand.java
  60. 2
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java
  61. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java
  62. 3
    7
      org.eclipse.jgit/src/org/eclipse/jgit/api/TagCommand.java
  63. 11
    1
      org.eclipse.jgit/src/org/eclipse/jgit/api/errors/UnmergedPathsException.java

+ 1
- 1
org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCloneTask.java View File

try { try {
clone.setURI(uri).setDirectory(destination).setBranch(branch).setBare(bare); clone.setURI(uri).setDirectory(destination).setBranch(branch).setBare(bare);
clone.call(); clone.call();
} catch (RuntimeException e) {
} catch (Exception e) {
log("Could not clone repository: " + e, e, Project.MSG_ERR); log("Could not clone repository: " + e, e, Project.MSG_ERR);
throw new BuildException("Could not clone repository: " + e.getMessage(), e); throw new BuildException("Could not clone repository: " + e.getMessage(), e);
} }

+ 1
- 1
org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitInitTask.java View File

InitCommand init = Git.init(); InitCommand init = Git.init();
init.setBare(bare).setDirectory(destination); init.setBare(bare).setDirectory(destination);
init.call(); init.call();
} catch (JGitInternalException e) {
} catch (Exception e) {
throw new BuildException("Could not initialize repository", e); throw new BuildException("Could not initialize repository", e);
} }
} }

+ 11
- 8
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java View File

import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheBuilder;
public class AddCommandTest extends RepositoryTestCase { public class AddCommandTest extends RepositoryTestCase {


@Test @Test
public void testAddNothing() {
public void testAddNothing() throws GitAPIException {
Git git = new Git(db); Git git = new Git(db);


try { try {
} }


@Test @Test
public void testAddNonExistingSingleFile() throws NoFilepatternException {
public void testAddNonExistingSingleFile() throws GitAPIException {
Git git = new Git(db); Git git = new Git(db);


DirCache dc = git.add().addFilepattern("a.txt").call(); DirCache dc = git.add().addFilepattern("a.txt").call();
} }


@Test @Test
public void testAddExistingSingleFile() throws IOException, NoFilepatternException {
public void testAddExistingSingleFile() throws IOException, GitAPIException {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file); FileUtils.createNewFile(file);
PrintWriter writer = new PrintWriter(file); PrintWriter writer = new PrintWriter(file);


@Test @Test
public void testAddExistingSingleSmallFileWithNewLine() throws IOException, public void testAddExistingSingleSmallFileWithNewLine() throws IOException,
NoFilepatternException {
GitAPIException {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file); FileUtils.createNewFile(file);
PrintWriter writer = new PrintWriter(file); PrintWriter writer = new PrintWriter(file);


@Test @Test
public void testAddExistingSingleMediumSizeFileWithNewLine() public void testAddExistingSingleMediumSizeFileWithNewLine()
throws IOException, NoFilepatternException {
throws IOException, GitAPIException {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file); FileUtils.createNewFile(file);
StringBuilder data = new StringBuilder(); StringBuilder data = new StringBuilder();


@Test @Test
public void testAddExistingSingleBinaryFile() throws IOException, public void testAddExistingSingleBinaryFile() throws IOException,
NoFilepatternException {
GitAPIException {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file); FileUtils.createNewFile(file);
PrintWriter writer = new PrintWriter(file); PrintWriter writer = new PrintWriter(file);
} }


@Test @Test
public void testAddExistingSingleFileInSubDir() throws IOException, NoFilepatternException {
public void testAddExistingSingleFileInSubDir() throws IOException,
GitAPIException {
FileUtils.mkdir(new File(db.getWorkTree(), "sub")); FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
File file = new File(db.getWorkTree(), "sub/a.txt"); File file = new File(db.getWorkTree(), "sub/a.txt");
FileUtils.createNewFile(file); FileUtils.createNewFile(file);
} }


@Test @Test
public void testAddExistingSingleFileTwice() throws IOException, NoFilepatternException {
public void testAddExistingSingleFileTwice() throws IOException,
GitAPIException {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file); FileUtils.createNewFile(file);
PrintWriter writer = new PrintWriter(file); PrintWriter writer = new PrintWriter(file);

+ 1
- 3
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java View File



public Ref createBranch(Git actGit, String name, boolean force, public Ref createBranch(Git actGit, String name, boolean force,
String startPoint, SetupUpstreamMode mode) String startPoint, SetupUpstreamMode mode)
throws JGitInternalException, RefAlreadyExistsException,
RefNotFoundException,
InvalidRefNameException {
throws JGitInternalException, GitAPIException {
CreateBranchCommand cmd = actGit.branchCreate(); CreateBranchCommand cmd = actGit.branchCreate();
cmd.setName(name); cmd.setName(name);
cmd.setForce(force); cmd.setForce(force);

+ 3
- 8
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java View File

import java.io.IOException; import java.io.IOException;


import org.eclipse.jgit.api.CheckoutResult.Status; import org.eclipse.jgit.api.CheckoutResult.Status;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.api.errors.RefNotFoundException; import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.dircache.DirCacheEntry;
} }


@Test @Test
public void testCheckoutToNonExistingBranch() throws JGitInternalException,
RefAlreadyExistsException, InvalidRefNameException,
CheckoutConflictException {
public void testCheckoutToNonExistingBranch() throws GitAPIException {
try { try {
git.checkout().setName("badbranch").call(); git.checkout().setName("badbranch").call();
fail("Should have failed"); fail("Should have failed");


@Test @Test
public void testDetachedHeadOnCheckout() throws JGitInternalException, public void testDetachedHeadOnCheckout() throws JGitInternalException,
RefAlreadyExistsException, RefNotFoundException,
InvalidRefNameException, IOException, CheckoutConflictException {
IOException, GitAPIException {
CheckoutCommand co = git.checkout(); CheckoutCommand co = git.checkout();
co.setName("master").call(); co.setName("master").call();



+ 6
- 4
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java View File



import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


import java.io.IOException;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Before; import org.junit.Before;
} }


@Test @Test
public void testClean() throws NoWorkTreeException, IOException {
public void testClean() throws NoWorkTreeException, GitAPIException {
// create status // create status
StatusCommand command = git.status(); StatusCommand command = git.status();
Status status = command.call(); Status status = command.call();
} }


@Test @Test
public void testCleanWithPaths() throws NoWorkTreeException, IOException {
public void testCleanWithPaths() throws NoWorkTreeException,
GitAPIException {
// create status // create status
StatusCommand command = git.status(); StatusCommand command = git.status();
Status status = command.call(); Status status = command.call();
} }


@Test @Test
public void testCleanWithDryRun() throws NoWorkTreeException, IOException {
public void testCleanWithDryRun() throws NoWorkTreeException,
GitAPIException {
// create status // create status
StatusCommand command = git.status(); StatusCommand command = git.status();
Status status = command.call(); Status status = command.call();

+ 8
- 4
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java View File

import java.util.Map; import java.util.Map;


import org.eclipse.jgit.api.ListBranchCommand.ListMode; import org.eclipse.jgit.api.ListBranchCommand.ListMode;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.ConfigConstants;
} }


@Test @Test
public void testCloneRepository() throws IOException {
public void testCloneRepository() throws IOException,
JGitInternalException, GitAPIException {
File directory = createTempDirectory("testCloneRepository"); File directory = createTempDirectory("testCloneRepository");
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setDirectory(directory); command.setDirectory(directory);
} }


@Test @Test
public void testCloneRepositoryWithBranch() throws IOException {
public void testCloneRepositoryWithBranch() throws IOException,
JGitInternalException, GitAPIException {
File directory = createTempDirectory("testCloneRepositoryWithBranch"); File directory = createTempDirectory("testCloneRepositoryWithBranch");
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setBranch("refs/heads/master"); command.setBranch("refs/heads/master");
} }


@Test @Test
public void testCloneRepositoryOnlyOneBranch() throws IOException {
public void testCloneRepositoryOnlyOneBranch() throws IOException,
JGitInternalException, GitAPIException {
File directory = createTempDirectory("testCloneRepositoryWithBranch"); File directory = createTempDirectory("testCloneRepositoryWithBranch");
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setBranch("refs/heads/master"); command.setBranch("refs/heads/master");


@Test @Test
public void testCloneRepositoryWhenDestinationDirectoryExistsAndIsNotEmpty() public void testCloneRepositoryWhenDestinationDirectoryExistsAndIsNotEmpty()
throws IOException {
throws IOException, JGitInternalException, GitAPIException {
String dirName = "testCloneTargetDirectoryNotEmpty"; String dirName = "testCloneTargetDirectoryNotEmpty";
File directory = createTempDirectory(dirName); File directory = createTempDirectory(dirName);
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();

+ 20
- 39
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java View File

import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; 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.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.NoMessageException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
*/ */
public class CommitAndLogCommandTests extends RepositoryTestCase { public class CommitAndLogCommandTests extends RepositoryTestCase {
@Test @Test
public void testSomeCommits() throws NoHeadException, NoMessageException,
ConcurrentRefUpdateException, JGitInternalException,
WrongRepositoryStateException, IOException {
public void testSomeCommits() throws JGitInternalException, IOException,
GitAPIException {


// do 4 commits // do 4 commits
Git git = new Git(db); Git git = new Git(db);
} }


@Test @Test
public void testLogWithFilter() throws IOException, NoFilepatternException,
NoHeadException, NoMessageException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException {
public void testLogWithFilter() throws IOException, JGitInternalException,
GitAPIException {


Git git = new Git(db); Git git = new Git(db);




// try to do a commit without specifying a message. Should fail! // try to do a commit without specifying a message. Should fail!
@Test @Test
public void testWrongParams() throws UnmergedPathException,
NoHeadException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException {
public void testWrongParams() throws GitAPIException {
Git git = new Git(db); Git git = new Git(db);
try { try {
git.commit().setAuthor(author).call(); git.commit().setAuthor(author).call();
// try to work with Commands after command has been invoked. Should throw // try to work with Commands after command has been invoked. Should throw
// exceptions // exceptions
@Test @Test
public void testMultipleInvocations() throws NoHeadException,
ConcurrentRefUpdateException, NoMessageException,
UnmergedPathException, JGitInternalException,
WrongRepositoryStateException {
public void testMultipleInvocations() throws GitAPIException {
Git git = new Git(db); Git git = new Git(db);
CommitCommand commitCmd = git.commit(); CommitCommand commitCmd = git.commit();
commitCmd.setMessage("initial commit").call(); commitCmd.setMessage("initial commit").call();
} }


@Test @Test
public void testMergeEmptyBranches() throws IOException, NoHeadException,
NoMessageException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException {
public void testMergeEmptyBranches() throws IOException,
JGitInternalException, GitAPIException {
Git git = new Git(db); Git git = new Git(db);
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
RefUpdate r = db.updateRef("refs/heads/side"); RefUpdate r = db.updateRef("refs/heads/side");
} }


@Test @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"); File file = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(file); FileUtils.createNewFile(file);
PrintWriter writer = new PrintWriter(file); PrintWriter writer = new PrintWriter(file);
} }


@Test @Test
public void testModeChange() throws IOException, NoFilepatternException,
NoHeadException, NoMessageException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException {
public void testModeChange() throws IOException, GitAPIException {
Git git = new Git(db); Git git = new Git(db);


// create file // create file
} }


@Test @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 // do 4 commits and set the range to the second and fourth one
Git git = new Git(db); Git git = new Git(db);
git.commit().setMessage("first commit").call(); git.commit().setMessage("first commit").call();
} }


@Test @Test
public void testCommitAmend() throws NoHeadException, NoMessageException,
ConcurrentRefUpdateException, JGitInternalException,
WrongRepositoryStateException, IOException {
public void testCommitAmend() throws JGitInternalException, IOException,
GitAPIException {
Git git = new Git(db); Git git = new Git(db);
git.commit().setMessage("first comit").call(); // typo git.commit().setMessage("first comit").call(); // typo
git.commit().setAmend(true).setMessage("first commit").call(); git.commit().setAmend(true).setMessage("first commit").call();
} }


@Test @Test
public void testInsertChangeId() throws NoHeadException,
NoMessageException,
UnmergedPathException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException {
public void testInsertChangeId() throws JGitInternalException,
GitAPIException {
Git git = new Git(db); Git git = new Git(db);
String messageHeader = "Some header line\n\nSome detail explanation\n"; String messageHeader = "Some header line\n\nSome detail explanation\n";
String changeIdTemplate = "\nChange-Id: I" String changeIdTemplate = "\nChange-Id: I"

+ 5
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java View File

import java.io.IOException; import java.io.IOException;


import org.eclipse.jgit.api.ListBranchCommand.ListMode; import org.eclipse.jgit.api.ListBranchCommand.ListMode;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
} }


@Test @Test
public void testWrap() {
public void testWrap() throws JGitInternalException, GitAPIException {
Git git = Git.wrap(db); Git git = Git.wrap(db);
assertEquals(1, git.branchList().call().size()); assertEquals(1, git.branchList().call().size());


} }


@Test @Test
public void testOpen() throws IOException {
public void testOpen() throws IOException, JGitInternalException,
GitAPIException {
Git git = Git.open(db.getDirectory()); Git git = Git.open(db.getDirectory());
assertEquals(1, git.branchList().call().size()); assertEquals(1, git.branchList().call().size());



+ 8
- 3
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java View File

import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Before; import org.junit.Before;
} }


@Test @Test
public void testInitRepository() throws IOException {
public void testInitRepository() throws IOException, JGitInternalException,
GitAPIException {
File directory = createTempDirectory("testInitRepository"); File directory = createTempDirectory("testInitRepository");
InitCommand command = new InitCommand(); InitCommand command = new InitCommand();
command.setDirectory(directory); command.setDirectory(directory);
} }


@Test @Test
public void testInitNonEmptyRepository() throws IOException {
public void testInitNonEmptyRepository() throws IOException,
JGitInternalException, GitAPIException {
File directory = createTempDirectory("testInitRepository2"); File directory = createTempDirectory("testInitRepository2");
File someFile = new File(directory, "someFile"); File someFile = new File(directory, "someFile");
someFile.createNewFile(); someFile.createNewFile();
} }


@Test @Test
public void testInitBareRepository() throws IOException {
public void testInitBareRepository() throws IOException,
JGitInternalException, GitAPIException {
File directory = createTempDirectory("testInitBareRepository"); File directory = createTempDirectory("testInitBareRepository");
InitCommand command = new InitCommand(); InitCommand command = new InitCommand();
command.setDirectory(directory); command.setDirectory(directory);

+ 7
- 18
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java View File

import java.io.PrintWriter; import java.io.PrintWriter;


import org.eclipse.jgit.api.ResetCommand.ResetType; import org.eclipse.jgit.api.ResetCommand.ResetType;
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.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.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.errors.AmbiguousObjectException; import org.eclipse.jgit.errors.AmbiguousObjectException;


private DirCacheEntry prestage; private DirCacheEntry prestage;


public void setupRepository() throws IOException, NoFilepatternException,
NoHeadException, NoMessageException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException {
public void setupRepository() throws IOException, JGitInternalException,
GitAPIException {


// create initial commit // create initial commit
git = new Git(db); git = new Git(db);


@Test @Test
public void testHardReset() throws JGitInternalException, public void testHardReset() throws JGitInternalException,
AmbiguousObjectException, IOException, NoFilepatternException,
NoHeadException, NoMessageException, ConcurrentRefUpdateException,
WrongRepositoryStateException {
AmbiguousObjectException, IOException, GitAPIException {
setupRepository(); setupRepository();
ObjectId prevHead = db.resolve(Constants.HEAD); ObjectId prevHead = db.resolve(Constants.HEAD);
git.reset().setMode(ResetType.HARD).setRef(initialCommit.getName()) git.reset().setMode(ResetType.HARD).setRef(initialCommit.getName())


@Test @Test
public void testResetToNonexistingHEAD() throws JGitInternalException, public void testResetToNonexistingHEAD() throws JGitInternalException,
AmbiguousObjectException, IOException {
AmbiguousObjectException, IOException, GitAPIException {


// create a file in the working tree of a fresh repo // create a file in the working tree of a fresh repo
git = new Git(db); git = new Git(db);


@Test @Test
public void testSoftReset() throws JGitInternalException, public void testSoftReset() throws JGitInternalException,
AmbiguousObjectException, IOException, NoFilepatternException,
NoHeadException, NoMessageException, ConcurrentRefUpdateException,
WrongRepositoryStateException {
AmbiguousObjectException, IOException, GitAPIException {
setupRepository(); setupRepository();
ObjectId prevHead = db.resolve(Constants.HEAD); ObjectId prevHead = db.resolve(Constants.HEAD);
git.reset().setMode(ResetType.SOFT).setRef(initialCommit.getName()) git.reset().setMode(ResetType.SOFT).setRef(initialCommit.getName())


@Test @Test
public void testMixedReset() throws JGitInternalException, public void testMixedReset() throws JGitInternalException,
AmbiguousObjectException, IOException, NoFilepatternException,
NoHeadException, NoMessageException, ConcurrentRefUpdateException,
WrongRepositoryStateException {
AmbiguousObjectException, IOException, GitAPIException {
setupRepository(); setupRepository();
ObjectId prevHead = db.resolve(Constants.HEAD); ObjectId prevHead = db.resolve(Constants.HEAD);
git.reset().setMode(ResetType.MIXED).setRef(initialCommit.getName()) git.reset().setMode(ResetType.MIXED).setRef(initialCommit.getName())

+ 2
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java View File



import java.io.IOException; import java.io.IOException;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;


@Test @Test
public void testRemove() throws JGitInternalException, public void testRemove() throws JGitInternalException,
NoFilepatternException, IllegalStateException, IOException {
IllegalStateException, IOException, GitAPIException {
assertEquals("[test.txt, mode:100644, content:Hello world]", assertEquals("[test.txt, mode:100644, content:Hello world]",
indexState(CONTENT)); indexState(CONTENT));
RmCommand command = git.rm(); RmCommand command = git.rm();

+ 3
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java View File



import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Test; import org.junit.Test;


public class StatusCommandTest extends RepositoryTestCase { public class StatusCommandTest extends RepositoryTestCase {


@Test @Test
public void testEmptyStatus() throws IOException {
public void testEmptyStatus() throws NoWorkTreeException,
GitAPIException {
Git git = new Git(db); Git git = new Git(db);


Status stat = git.status().call(); Status stat = git.status().call();

+ 6
- 26
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java View File

import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidTagNameException; import org.eclipse.jgit.api.errors.InvalidTagNameException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
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.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
public class TagCommandTest extends RepositoryTestCase { public class TagCommandTest extends RepositoryTestCase {


@Test @Test
public void testTaggingOnHead() throws NoHeadException, NoMessageException,
ConcurrentRefUpdateException, JGitInternalException,
WrongRepositoryStateException, InvalidTagNameException,
MissingObjectException, IncorrectObjectTypeException, IOException {
public void testTaggingOnHead() throws GitAPIException, IOException {
Git git = new Git(db); Git git = new Git(db);
RevCommit commit = git.commit().setMessage("initial commit").call(); RevCommit commit = git.commit().setMessage("initial commit").call();
Ref tagRef = git.tag().setName("tag").call(); Ref tagRef = git.tag().setName("tag").call();
} }


@Test @Test
public void testTagging() throws NoHeadException, NoMessageException,
UnmergedPathException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException,
InvalidTagNameException {
public void testTagging() throws GitAPIException, JGitInternalException {
Git git = new Git(db); Git git = new Git(db);
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
RevCommit commit = git.commit().setMessage("second commit").call(); RevCommit commit = git.commit().setMessage("second commit").call();
} }


@Test @Test
public void testEmptyTagName() throws NoHeadException, NoMessageException,
UnmergedPathException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException {
public void testEmptyTagName() throws GitAPIException {
Git git = new Git(db); Git git = new Git(db);
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
try { try {
} }


@Test @Test
public void testInvalidTagName() throws NoHeadException,
NoMessageException, UnmergedPathException,
ConcurrentRefUpdateException, JGitInternalException,
WrongRepositoryStateException {
public void testInvalidTagName() throws GitAPIException {
Git git = new Git(db); Git git = new Git(db);
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
try { try {
} }


@Test @Test
public void testFailureOnSignedTags() throws NoHeadException,
NoMessageException, UnmergedPathException,
ConcurrentRefUpdateException, JGitInternalException,
WrongRepositoryStateException, InvalidTagNameException {
public void testFailureOnSignedTags() throws GitAPIException {
Git git = new Git(db); Git git = new Git(db);
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
try { try {

+ 4
- 19
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java View File

import java.util.Arrays; import java.util.Arrays;


import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.dircache.InvalidPathException; import org.eclipse.jgit.dircache.InvalidPathException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.util.SystemReader; import org.eclipse.jgit.util.SystemReader;
* perform the actual test on the second checkout * perform the actual test on the second checkout
* @param path * @param path
* to the blob, one or more levels * to the blob, one or more levels
* @throws GitAPIException
* @throws IOException * @throws IOException
* @throws RefAlreadyExistsException
* @throws RefNotFoundException
* @throws InvalidRefNameException
* @throws MissingObjectException
* @throws IncorrectObjectTypeException
* @throws CheckoutConflictException
* @throws JGitInternalException
*/ */
private void testMaliciousPath(boolean good, boolean secondCheckout, String... path)
throws IOException, RefAlreadyExistsException,
RefNotFoundException, InvalidRefNameException,
MissingObjectException, IncorrectObjectTypeException,
JGitInternalException, CheckoutConflictException {
private void testMaliciousPath(boolean good, boolean secondCheckout,
String... path) throws GitAPIException, IOException {
Git git = new Git(db); Git git = new Git(db);
ObjectInserter newObjectInserter; ObjectInserter newObjectInserter;
newObjectInserter = git.getRepository().newObjectInserter(); newObjectInserter = git.getRepository().newObjectInserter();

+ 5
- 7
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java View File

import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.MergeResult; import org.eclipse.jgit.api.MergeResult;
import org.eclipse.jgit.api.MergeResult.MergeStatus; import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
} }


@Test @Test
public void testModified() throws IOException, NoFilepatternException {
public void testModified() throws IOException, GitAPIException {


writeTrashFile("file2", "file2"); writeTrashFile("file2", "file2");
writeTrashFile("dir/file3", "dir/file3"); writeTrashFile("dir/file3", "dir/file3");
} }


@Test @Test
public void testUnchangedSimple() throws IOException,
NoFilepatternException {
public void testUnchangedSimple() throws IOException, GitAPIException {
writeTrashFile("a.b", "a.b"); writeTrashFile("a.b", "a.b");
writeTrashFile("a.c", "a.c"); writeTrashFile("a.c", "a.c");
writeTrashFile("a=c", "a=c"); writeTrashFile("a=c", "a=c");
* used by Git. * used by Git.
* *
* @throws IOException * @throws IOException
* @throws NoFilepatternException
* @throws GitAPIException
*/ */
@Test @Test
public void testUnchangedComplex() throws IOException,
NoFilepatternException {
public void testUnchangedComplex() throws IOException, GitAPIException {
Git git = new Git(db); Git git = new Git(db);
writeTrashFile("a.b", "a.b"); writeTrashFile("a.b", "a.b");
writeTrashFile("a.c", "a.c"); writeTrashFile("a.c", "a.c");

+ 5
- 4
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java View File

import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.Status; import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.SubmoduleAddCommand; import org.eclipse.jgit.api.SubmoduleAddCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor;
public class SubmoduleAddTest extends RepositoryTestCase { public class SubmoduleAddTest extends RepositoryTestCase {


@Test @Test
public void commandWithNullPath() {
public void commandWithNullPath() throws GitAPIException {
try { try {
new SubmoduleAddCommand(db).setURI("uri").call(); new SubmoduleAddCommand(db).setURI("uri").call();
fail("Exception not thrown"); fail("Exception not thrown");
} }


@Test @Test
public void commandWithEmptyPath() {
public void commandWithEmptyPath() throws GitAPIException {
try { try {
new SubmoduleAddCommand(db).setPath("").setURI("uri").call(); new SubmoduleAddCommand(db).setPath("").setURI("uri").call();
fail("Exception not thrown"); fail("Exception not thrown");
} }


@Test @Test
public void commandWithNullUri() {
public void commandWithNullUri() throws GitAPIException {
try { try {
new SubmoduleAddCommand(db).setPath("sub").call(); new SubmoduleAddCommand(db).setPath("sub").call();
fail("Exception not thrown"); fail("Exception not thrown");
} }


@Test @Test
public void commandWithEmptyUri() {
public void commandWithEmptyUri() throws GitAPIException {
try { try {
new SubmoduleAddCommand(db).setPath("sub").setURI("").call(); new SubmoduleAddCommand(db).setPath("sub").setURI("").call();
fail("Exception not thrown"); fail("Exception not thrown");

+ 7
- 6
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java View File

import java.util.Collection; import java.util.Collection;


import org.eclipse.jgit.api.SubmoduleInitCommand; import org.eclipse.jgit.api.SubmoduleInitCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor;
public class SubmoduleInitTest extends RepositoryTestCase { public class SubmoduleInitTest extends RepositoryTestCase {


@Test @Test
public void repositoryWithNoSubmodules() {
public void repositoryWithNoSubmodules() throws GitAPIException {
SubmoduleInitCommand command = new SubmoduleInitCommand(db); SubmoduleInitCommand command = new SubmoduleInitCommand(db);
Collection<String> modules = command.call(); Collection<String> modules = command.call();
assertNotNull(modules); assertNotNull(modules);


@Test @Test
public void repositoryWithUninitializedModule() throws IOException, public void repositoryWithUninitializedModule() throws IOException,
ConfigInvalidException {
ConfigInvalidException, GitAPIException {
final String path = addSubmoduleToIndex(); final String path = addSubmoduleToIndex();


SubmoduleWalk generator = SubmoduleWalk.forIndex(db); SubmoduleWalk generator = SubmoduleWalk.forIndex(db);


@Test @Test
public void resolveOneLevelHigherRelativeUrl() throws IOException, public void resolveOneLevelHigherRelativeUrl() throws IOException,
ConfigInvalidException {
ConfigInvalidException, GitAPIException {
final String path = addSubmoduleToIndex(); final String path = addSubmoduleToIndex();


String base = "git://server/repo.git"; String base = "git://server/repo.git";


@Test @Test
public void resolveTwoLevelHigherRelativeUrl() throws IOException, public void resolveTwoLevelHigherRelativeUrl() throws IOException,
ConfigInvalidException {
ConfigInvalidException, GitAPIException {
final String path = addSubmoduleToIndex(); final String path = addSubmoduleToIndex();


String base = "git://server/repo.git"; String base = "git://server/repo.git";


@Test @Test
public void resolveWorkingDirectoryRelativeUrl() throws IOException, public void resolveWorkingDirectoryRelativeUrl() throws IOException,
ConfigInvalidException {
GitAPIException, ConfigInvalidException {
final String path = addSubmoduleToIndex(); final String path = addSubmoduleToIndex();


String base = db.getWorkTree().getAbsolutePath(); String base = db.getWorkTree().getAbsolutePath();


@Test @Test
public void resolveInvalidParentUrl() throws IOException, public void resolveInvalidParentUrl() throws IOException,
ConfigInvalidException {
ConfigInvalidException, GitAPIException {
final String path = addSubmoduleToIndex(); final String path = addSubmoduleToIndex();


String base = "no_slash"; String base = "no_slash";

+ 13
- 7
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleStatusTest.java View File



import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.SubmoduleStatusCommand; import org.eclipse.jgit.api.SubmoduleStatusCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
public class SubmoduleStatusTest extends RepositoryTestCase { public class SubmoduleStatusTest extends RepositoryTestCase {


@Test @Test
public void repositoryWithNoSubmodules() {
public void repositoryWithNoSubmodules() throws GitAPIException {
SubmoduleStatusCommand command = new SubmoduleStatusCommand(db); SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
Map<String, SubmoduleStatus> statuses = command.call(); Map<String, SubmoduleStatus> statuses = command.call();
assertNotNull(statuses); assertNotNull(statuses);
} }


@Test @Test
public void repositoryWithMissingSubmodule() throws IOException {
public void repositoryWithMissingSubmodule() throws IOException,
GitAPIException {
final ObjectId id = ObjectId final ObjectId id = ObjectId
.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
final String path = "sub"; final String path = "sub";
} }


@Test @Test
public void repositoryWithUninitializedSubmodule() throws IOException {
public void repositoryWithUninitializedSubmodule() throws IOException,
GitAPIException {
final ObjectId id = ObjectId final ObjectId id = ObjectId
.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
final String path = "sub"; final String path = "sub";
} }


@Test @Test
public void repositoryWithNoHeadInSubmodule() throws IOException {
public void repositoryWithNoHeadInSubmodule() throws IOException,
GitAPIException {
final ObjectId id = ObjectId final ObjectId id = ObjectId
.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
final String path = "sub"; final String path = "sub";
} }


@Test @Test
public void repositoryWithNoSubmoduleRepository() throws IOException {
public void repositoryWithNoSubmoduleRepository() throws IOException,
GitAPIException {
final ObjectId id = ObjectId final ObjectId id = ObjectId
.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
final String path = "sub"; final String path = "sub";
} }


@Test @Test
public void repositoryWithInitializedSubmodule() throws IOException {
public void repositoryWithInitializedSubmodule() throws IOException,
GitAPIException {
final ObjectId id = ObjectId final ObjectId id = ObjectId
.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
final String path = "sub"; final String path = "sub";


@Test @Test
public void repositoryWithDifferentRevCheckedOutSubmodule() public void repositoryWithDifferentRevCheckedOutSubmodule()
throws IOException {
throws IOException, GitAPIException {
final ObjectId id = ObjectId final ObjectId id = ObjectId
.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
final String path = "sub"; final String path = "sub";

+ 2
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java View File



import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.SubmoduleSyncCommand; import org.eclipse.jgit.api.SubmoduleSyncCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
public class SubmoduleSyncTest extends RepositoryTestCase { public class SubmoduleSyncTest extends RepositoryTestCase {


@Test @Test
public void repositoryWithNoSubmodules() {
public void repositoryWithNoSubmodules() throws GitAPIException {
SubmoduleSyncCommand command = new SubmoduleSyncCommand(db); SubmoduleSyncCommand command = new SubmoduleSyncCommand(db);
Map<String, String> modules = command.call(); Map<String, String> modules = command.call();
assertNotNull(modules); assertNotNull(modules);

+ 6
- 3
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java View File



import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.SubmoduleUpdateCommand; import org.eclipse.jgit.api.SubmoduleUpdateCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
public class SubmoduleUpdateTest extends RepositoryTestCase { public class SubmoduleUpdateTest extends RepositoryTestCase {


@Test @Test
public void repositoryWithNoSubmodules() {
public void repositoryWithNoSubmodules() throws GitAPIException {
SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db); SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db);
Collection<String> modules = command.call(); Collection<String> modules = command.call();
assertNotNull(modules); assertNotNull(modules);
} }


@Test @Test
public void repositoryWithUnconfiguredSubmodule() throws IOException {
public void repositoryWithUnconfiguredSubmodule() throws IOException,
GitAPIException {
final ObjectId id = ObjectId final ObjectId id = ObjectId
.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
final String path = "sub"; final String path = "sub";
} }


@Test @Test
public void repositoryWithInitializedSubmodule() throws IOException {
public void repositoryWithInitializedSubmodule() throws IOException,
GitAPIException {
final ObjectId id = ObjectId final ObjectId id = ObjectId
.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
final String path = "sub"; final String path = "sub";

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java View File

import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
* *
* @return the DirCache after Add * @return the DirCache after Add
*/ */
public DirCache call() throws NoFilepatternException {
public DirCache call() throws GitAPIException, NoFilepatternException {


if (filepatterns.isEmpty()) if (filepatterns.isEmpty())
throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired); throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired);

+ 2
- 5
org.eclipse.jgit/src/org/eclipse/jgit/api/AddNoteCommand.java View File



import java.io.IOException; import java.io.IOException;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.CommitBuilder; import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
super(repo); super(repo);
} }


/**
* @throws JGitInternalException
* upon internal failure
*/
public Note call() throws JGitInternalException {
public Note call() throws GitAPIException {
checkCallable(); checkCallable();
RevWalk walk = new RevWalk(repo); RevWalk walk = new RevWalk(repo);
ObjectInserter inserter = repo.newObjectInserter(); ObjectInserter inserter = repo.newObjectInserter();

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/BlameCommand.java View File

import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.blame.BlameGenerator; import org.eclipse.jgit.blame.BlameGenerator;
import org.eclipse.jgit.blame.BlameResult; import org.eclipse.jgit.blame.BlameResult;
* *
* @return list of lines * @return list of lines
*/ */
public BlameResult call() throws JGitInternalException {
public BlameResult call() throws GitAPIException {
checkCallable(); checkCallable();
BlameGenerator gen = new BlameGenerator(repo, path); BlameGenerator gen = new BlameGenerator(repo, path);
try { try {

+ 4
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java View File



import org.eclipse.jgit.api.CheckoutResult.Status; import org.eclipse.jgit.api.CheckoutResult.Status;
import org.eclipse.jgit.api.errors.CheckoutConflictException; import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRefNameException; import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException; import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
* @throws InvalidRefNameException * @throws InvalidRefNameException
* if the provided name is <code>null</code> or otherwise * if the provided name is <code>null</code> or otherwise
* invalid * invalid
* @throws CheckoutConflictException
* if the checkout results in a conflict
* @return the newly created branch * @return the newly created branch
*/ */
public Ref call() throws JGitInternalException, RefAlreadyExistsException,
public Ref call() throws GitAPIException, RefAlreadyExistsException,
RefNotFoundException, InvalidRefNameException, RefNotFoundException, InvalidRefNameException,
CheckoutConflictException { CheckoutConflictException {
checkCallable(); checkCallable();

+ 3
- 2
org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java View File

import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;
* *
* @return a set of strings representing each file cleaned. * @return a set of strings representing each file cleaned.
*/ */
public Set<String> call() {
public Set<String> call() throws GitAPIException {
Set<String> files = new TreeSet<String>(); Set<String> files = new TreeSet<String>();
try { try {
StatusCommand command = new StatusCommand(repo); StatusCommand command = new StatusCommand(repo);


/** /**
* If dryRun is set, the paths in question will not actually be deleted. * If dryRun is set, the paths in question will not actually be deleted.
*
*
* @param dryRun * @param dryRun
* whether to do a dry run or not * whether to do a dry run or not
* @return {@code this} * @return {@code this}

+ 8
- 10
org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java View File

import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
/** /**
* Executes the {@code Clone} command. * Executes the {@code Clone} command.
* *
* @throws JGitInternalException
* if the repository can't be created
* @return the newly created {@code Git} object with associated repository * @return the newly created {@code Git} object with associated repository
*/ */
public Git call() throws JGitInternalException {
public Git call() throws GitAPIException {
try { try {
URIish u = new URIish(uri); URIish u = new URIish(uri);
Repository repository = init(u); Repository repository = init(u);
} }
} }


private Repository init(URIish u) {
private Repository init(URIish u) throws GitAPIException {
InitCommand command = Git.init(); InitCommand command = Git.init();
command.setBare(bare); command.setBare(bare);
if (directory == null) if (directory == null)
} }


private FetchResult fetch(Repository clonedRepo, URIish u) private FetchResult fetch(Repository clonedRepo, URIish u)
throws URISyntaxException,
JGitInternalException,
InvalidRemoteException, IOException {
throws URISyntaxException, IOException, GitAPIException {
// create the remote config and save it // create the remote config and save it
RemoteConfig config = new RemoteConfig(clonedRepo.getConfig(), remote); RemoteConfig config = new RemoteConfig(clonedRepo.getConfig(), remote);
config.addURI(u); config.addURI(u);
} }


private void checkout(Repository clonedRepo, FetchResult result) private void checkout(Repository clonedRepo, FetchResult result)
throws JGitInternalException,
MissingObjectException, IncorrectObjectTypeException, IOException {
throws MissingObjectException, IncorrectObjectTypeException,
IOException, GitAPIException {


Ref head = result.getAdvertisedRef(branch); Ref head = result.getAdvertisedRef(branch);
if (branch.equals(Constants.HEAD)) { if (branch.equals(Constants.HEAD)) {
} }
} }


private void cloneSubmodules(Repository clonedRepo) throws IOException {
private void cloneSubmodules(Repository clonedRepo) throws IOException,
GitAPIException {
SubmoduleInitCommand init = new SubmoduleInitCommand(clonedRepo); SubmoduleInitCommand init = new SubmoduleInitCommand(clonedRepo);
if (init.call().isEmpty()) if (init.call().isEmpty())
return; return;

+ 11
- 15
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java View File

import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; 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.JGitInternalException;
import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.NoMessageException; import org.eclipse.jgit.api.errors.NoMessageException;
import org.eclipse.jgit.api.errors.UnmergedPathsException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException; import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheBuilder;
* when called on a git repo without a HEAD reference * when called on a git repo without a HEAD reference
* @throws NoMessageException * @throws NoMessageException
* when called without specifying a commit message * when called without specifying a commit message
* @throws UnmergedPathException
* @throws UnmergedPathsException
* when the current index contained unmerged paths (conflicts) * when the current index contained unmerged paths (conflicts)
* @throws ConcurrentRefUpdateException
* when HEAD or branch ref is updated concurrently by someone
* else
* @throws WrongRepositoryStateException * @throws WrongRepositoryStateException
* when repository is not in the right state for committing * when repository is not in the right state for committing
* @throws JGitInternalException
* a low-level exception of JGit has occurred. The original
* exception can be retrieved by calling
* {@link Exception#getCause()}. Expect only
* {@code IOException's} to be wrapped. Subclasses of
* {@link IOException} (e.g. {@link UnmergedPathException}) are
* typically not wrapped here but thrown as original exception
*/ */
public RevCommit call() throws NoHeadException, NoMessageException,
UnmergedPathException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException {
public RevCommit call() throws GitAPIException, NoHeadException,
NoMessageException, UnmergedPathsException,
ConcurrentRefUpdateException,
WrongRepositoryStateException {
checkCallable(); checkCallable();


RepositoryState state = repo.getRepositoryState(); RepositoryState state = repo.getRepositoryState();
index.unlock(); index.unlock();
} }
} catch (UnmergedPathException e) { } catch (UnmergedPathException e) {
// since UnmergedPathException is a subclass of IOException
// which should not be wrapped by a JGitInternalException we
// have to catch and re-throw it here
throw e;
throw new UnmergedPathsException(e);
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException( throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfCommitCommand, e); JGitText.get().exceptionCaughtDuringExecutionOfCommitCommand, e);

+ 3
- 2
org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java View File

import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRefNameException; import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException; import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;


* invalid * invalid
* @return the newly created branch * @return the newly created branch
*/ */
public Ref call() throws JGitInternalException, RefAlreadyExistsException,
public Ref call() throws GitAPIException, RefAlreadyExistsException,
RefNotFoundException, InvalidRefNameException { RefNotFoundException, InvalidRefNameException {
checkCallable(); checkCallable();
processOptions(); processOptions();

+ 4
- 2
org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java View File

import java.util.Set; import java.util.Set;


import org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException; import org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NotMergedException; import org.eclipse.jgit.api.errors.NotMergedException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;


* @throws NotMergedException * @throws NotMergedException
* when trying to delete a branch which has not been merged into * when trying to delete a branch which has not been merged into
* the currently checked out branch without force * the currently checked out branch without force
* @throws CannotDeleteCurrentBranchException
* @return the list with the (full) names of the deleted branches * @return the list with the (full) names of the deleted branches
*/ */
public List<String> call() throws JGitInternalException,
public List<String> call() throws GitAPIException,
NotMergedException, CannotDeleteCurrentBranchException { NotMergedException, CannotDeleteCurrentBranchException {
checkCallable(); checkCallable();
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<String>();

+ 2
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteTagCommand.java View File

import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
} }


/** /**
* @throws JGitInternalException
* when trying to delete a tag that doesn't exist
*
* @return the list with the full names of the deleted tags * @return the list with the full names of the deleted tags
*/ */
public List<String> call() throws JGitInternalException {
public List<String> call() throws GitAPIException {
checkCallable(); checkCallable();
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<String>();
if (tags.isEmpty()) if (tags.isEmpty())

+ 4
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java View File

import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.diff.DiffFormatter;
* *
* @return a DiffEntry for each path which is different * @return a DiffEntry for each path which is different
*/ */
public List<DiffEntry> call() throws GitAPIException, IOException {
public List<DiffEntry> call() throws GitAPIException {
final DiffFormatter diffFmt; final DiffFormatter diffFmt;
if (out != null && !showNameAndStatusOnly) if (out != null && !showNameAndStatusOnly)
diffFmt = new DiffFormatter(new BufferedOutputStream(out)); diffFmt = new DiffFormatter(new BufferedOutputStream(out));
diffFmt.flush(); diffFmt.flush();
return result; return result;
} }
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
} finally { } finally {
diffFmt.release(); diffFmt.release();
} }

+ 6
- 7
org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java View File

import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.errors.NoRemoteRepositoryException;
* result * result
* @throws InvalidRemoteException * @throws InvalidRemoteException
* when called with an invalid remote uri * when called with an invalid remote uri
* @throws JGitInternalException
* a low-level exception of JGit has occurred. The original
* exception can be retrieved by calling
* {@link Exception#getCause()}.
* @throws org.eclipse.jgit.api.errors.TransportException
* when an error occurs during transport
*/ */
public FetchResult call() throws JGitInternalException,
InvalidRemoteException {
public FetchResult call() throws GitAPIException, InvalidRemoteException,
org.eclipse.jgit.api.errors.TransportException {
checkCallable(); checkCallable();


try { try {
throw new InvalidRemoteException(MessageFormat.format( throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote), e); JGitText.get().invalidRemote, remote), e);
} catch (TransportException e) { } catch (TransportException e) {
throw new JGitInternalException(
throw new org.eclipse.jgit.api.errors.TransportException(
JGitText.get().exceptionCaughtDuringExecutionOfFetchCommand, JGitText.get().exceptionCaughtDuringExecutionOfFetchCommand,
e); e);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {

+ 10
- 0
org.eclipse.jgit/src/org/eclipse/jgit/api/GitCommand.java View File

import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;


JGitText.get().commandWasCalledInTheWrongState JGitText.get().commandWasCalledInTheWrongState
, this.getClass().getName())); , this.getClass().getName()));
} }

/**
* Executes the command
*
* @return T a result. Each command has its own return type
* @throws GitAPIException
* or subclass thereof when an error occurs
*/
public abstract T call() throws GitAPIException;
} }

+ 2
- 3
org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java View File

import java.io.IOException; import java.io.IOException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
/** /**
* Executes the {@code Init} command. * Executes the {@code Init} command.
* *
* @throws JGitInternalException
* if the repository can't be created
* @return the newly created {@code Git} object with associated repository * @return the newly created {@code Git} object with associated repository
*/ */
public Git call() throws JGitInternalException {
public Git call() throws GitAPIException {
try { try {
RepositoryBuilder builder = new RepositoryBuilder(); RepositoryBuilder builder = new RepositoryBuilder();
if (bare) if (bare)

+ 3
- 6
org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java View File

import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.HashMap;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
super(repo); super(repo);
} }


/**
* @throws JGitInternalException
* upon internal failure
*/
public List<Ref> call() throws JGitInternalException {
public List<Ref> call() throws GitAPIException {
checkCallable(); checkCallable();
Map<String, Ref> refList; Map<String, Ref> refList;
try { try {

+ 3
- 3
org.eclipse.jgit/src/org/eclipse/jgit/api/ListNotesCommand.java View File

import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
} }


/** /**
* @throws JGitInternalException
* upon internal failure
* @return the requested notes
*/ */
public List<Note> call() throws JGitInternalException {
public List<Note> call() throws GitAPIException {
checkCallable(); checkCallable();
List<Note> notes = new ArrayList<Note>(); List<Note> notes = new ArrayList<Note>();
RevWalk walk = new RevWalk(repo); RevWalk walk = new RevWalk(repo);

+ 2
- 3
org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java View File

import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
} }


/** /**
* @throws JGitInternalException
* upon internal failure
* @return the tags available * @return the tags available
*/ */
public List<Ref> call() throws JGitInternalException {
public List<Ref> call() throws GitAPIException {
checkCallable(); checkCallable();
Map<String, Ref> refList; Map<String, Ref> refList;
List<Ref> tags = new ArrayList<Ref>(); List<Ref> tags = new ArrayList<Ref>();

+ 7
- 6
org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java View File

import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.IncorrectObjectTypeException;
* method twice on an instance. * method twice on an instance.
* *
* @return an iteration over RevCommits * @return an iteration over RevCommits
* @throws NoHeadException
* of the references ref cannot be resolved
*/ */
public Iterable<RevCommit> call() throws NoHeadException,
JGitInternalException {
public Iterable<RevCommit> call() throws GitAPIException, NoHeadException {
checkCallable(); checkCallable();
if (pathFilters.size() > 0) if (pathFilters.size() > 0)
walk.setTreeFilter(AndTreeFilter.create( walk.setTreeFilter(AndTreeFilter.create(
* typically not wrapped here but thrown as original exception * typically not wrapped here but thrown as original exception
*/ */
public LogCommand add(AnyObjectId start) throws MissingObjectException, public LogCommand add(AnyObjectId start) throws MissingObjectException,
IncorrectObjectTypeException, JGitInternalException {
IncorrectObjectTypeException {
return add(true, start); return add(true, start);
} }


* typically not wrapped here but thrown as original exception * typically not wrapped here but thrown as original exception
*/ */
public LogCommand not(AnyObjectId start) throws MissingObjectException, public LogCommand not(AnyObjectId start) throws MissingObjectException,
IncorrectObjectTypeException, JGitInternalException {
IncorrectObjectTypeException {
return add(false, start); return add(false, start);
} }


* typically not wrapped here but thrown as original exception * typically not wrapped here but thrown as original exception
*/ */
public LogCommand addRange(AnyObjectId since, AnyObjectId until) public LogCommand addRange(AnyObjectId since, AnyObjectId until)
throws MissingObjectException, IncorrectObjectTypeException,
JGitInternalException {
throws MissingObjectException, IncorrectObjectTypeException {
return not(since).add(until); return not(since).add(until);
} }



+ 3
- 5
org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java View File

* @return a collection of references in the remote repository * @return a collection of references in the remote repository
* @throws InvalidRemoteException * @throws InvalidRemoteException
* when called with an invalid remote uri * when called with an invalid remote uri
* @throws JGitInternalException
* a low-level exception of JGit has occurred. The original
* exception can be retrieved by calling
* {@link Exception#getCause()}.
* @throws org.eclipse.jgit.api.errors.TransportException
* for errors that occurs during transport
*/ */
public Collection<Ref> call() throws GitAPIException, public Collection<Ref> call() throws GitAPIException,
JGitInternalException {
org.eclipse.jgit.api.errors.TransportException {
checkCallable(); checkCallable();


Transport transport = null; Transport transport = null;

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java View File

import org.eclipse.jgit.api.MergeResult.MergeStatus; import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.CheckoutConflictException; import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidMergeHeadsException; import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoHeadException;
* *
* @return the result of the merge * @return the result of the merge
*/ */
public MergeResult call() throws NoHeadException,
public MergeResult call() throws GitAPIException, NoHeadException,
ConcurrentRefUpdateException, CheckoutConflictException, ConcurrentRefUpdateException, CheckoutConflictException,
InvalidMergeHeadsException, WrongRepositoryStateException, NoMessageException { InvalidMergeHeadsException, WrongRepositoryStateException, NoMessageException {
checkCallable(); checkCallable();

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java View File

* *
* @return the result of the pull * @return the result of the pull
*/ */
public PullResult call() throws WrongRepositoryStateException,
public PullResult call() throws GitAPIException, WrongRepositoryStateException,
InvalidConfigurationException, DetachedHeadException, InvalidConfigurationException, DetachedHeadException,
InvalidRemoteException, CanceledException, RefNotFoundException, InvalidRemoteException, CanceledException, RefNotFoundException,
NoHeadException { NoHeadException {

+ 3
- 6
org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java View File

import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.NotSupportedException;
* @return an iteration over {@link PushResult} objects * @return an iteration over {@link PushResult} objects
* @throws InvalidRemoteException * @throws InvalidRemoteException
* when called with an invalid remote uri * when called with an invalid remote uri
* @throws JGitInternalException
* a low-level exception of JGit has occurred. The original
* exception can be retrieved by calling
* {@link Exception#getCause()}.
*/ */
public Iterable<PushResult> call() throws JGitInternalException,
public Iterable<PushResult> call() throws GitAPIException,
InvalidRemoteException { InvalidRemoteException {
checkCallable(); checkCallable();


* @throws JGitInternalException * @throws JGitInternalException
* the reference name cannot be resolved. * the reference name cannot be resolved.
*/ */
public PushCommand add(String nameOrSpec) throws JGitInternalException {
public PushCommand add(String nameOrSpec) {
if (0 <= nameOrSpec.indexOf(':')) { if (0 <= nameOrSpec.indexOf(':')) {
refSpecs.add(new RefSpec(nameOrSpec)); refSpecs.add(new RefSpec(nameOrSpec));
} else { } else {

+ 9
- 10
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java View File

* *
* @return an object describing the result of this command * @return an object describing the result of this command
*/ */
public RebaseResult call() throws NoHeadException, RefNotFoundException,
JGitInternalException, GitAPIException {
public RebaseResult call() throws GitAPIException, NoHeadException,
RefNotFoundException {
RevCommit newHead = null; RevCommit newHead = null;
boolean lastStepWasForward = false; boolean lastStepWasForward = false;
checkCallable(); checkCallable();
} }
} }


private RevCommit checkoutCurrentHead() throws IOException,
NoHeadException, JGitInternalException {
private RevCommit checkoutCurrentHead() throws IOException, NoHeadException {
ObjectId headTree = repo.resolve(Constants.HEAD + "^{tree}"); ObjectId headTree = repo.resolve(Constants.HEAD + "^{tree}");
if (headTree == null) if (headTree == null)
throw new NoHeadException( throw new NoHeadException(
} }
} }


private RebaseResult initFilesAndRewind() throws RefNotFoundException,
IOException, NoHeadException, JGitInternalException {
private RebaseResult initFilesAndRewind() throws IOException,
GitAPIException {
// we need to store everything into files so that we can implement // we need to store everything into files so that we can implement
// --skip, --continue, and --abort // --skip, --continue, and --abort


* *
* @param newCommit * @param newCommit
* @return the new head, or null * @return the new head, or null
* @throws RefNotFoundException
* @throws IOException * @throws IOException
* @throws GitAPIException
*/ */
public RevCommit tryFastForward(RevCommit newCommit)
throws RefNotFoundException, IOException {
public RevCommit tryFastForward(RevCommit newCommit) throws IOException,
GitAPIException {
Ref head = repo.getRef(Constants.HEAD); Ref head = repo.getRef(Constants.HEAD);
if (head == null || head.getObjectId() == null) if (head == null || head.getObjectId() == null)
throw new RefNotFoundException(MessageFormat.format( throw new RefNotFoundException(MessageFormat.format(
} }


private RevCommit tryFastForward(String headName, RevCommit oldCommit, private RevCommit tryFastForward(String headName, RevCommit oldCommit,
RevCommit newCommit) throws IOException, JGitInternalException {
RevCommit newCommit) throws IOException, GitAPIException {
boolean tryRebase = false; boolean tryRebase = false;
for (RevCommit parentCommit : newCommit.getParents()) for (RevCommit parentCommit : newCommit.getParents())
if (parentCommit.equals(oldCommit)) if (parentCommit.equals(oldCommit))

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/ReflogCommand.java View File

import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Collection; import java.util.Collection;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRefNameException; import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
return this; return this;
} }


public Collection<ReflogEntry> call() throws Exception {
public Collection<ReflogEntry> call() throws GitAPIException {
checkCallable(); checkCallable();


try { try {

+ 2
- 5
org.eclipse.jgit/src/org/eclipse/jgit/api/RemoveNoteCommand.java View File



import java.io.IOException; import java.io.IOException;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.CommitBuilder; import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
super(repo); super(repo);
} }


/**
* @throws JGitInternalException
* upon internal failure
*/
public Note call() throws JGitInternalException {
public Note call() throws GitAPIException {
checkCallable(); checkCallable();
RevWalk walk = new RevWalk(repo); RevWalk walk = new RevWalk(repo);
ObjectInserter inserter = repo.newObjectInserter(); ObjectInserter inserter = repo.newObjectInserter();

+ 3
- 2
org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java View File

import java.util.Arrays; import java.util.Arrays;


import org.eclipse.jgit.api.errors.DetachedHeadException; import org.eclipse.jgit.api.errors.DetachedHeadException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRefNameException; import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException; import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefRename; import org.eclipse.jgit.lib.RefRename;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.lib.RefUpdate.Result;


/** /**
* Used to rename branches. * Used to rename branches.
* if rename is tried without specifying the old name and HEAD * if rename is tried without specifying the old name and HEAD
* is detached * is detached
*/ */
public Ref call() throws RefNotFoundException, InvalidRefNameException,
public Ref call() throws GitAPIException, RefNotFoundException, InvalidRefNameException,
RefAlreadyExistsException, DetachedHeadException { RefAlreadyExistsException, DetachedHeadException {
checkCallable(); checkCallable();



+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java View File

import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheCheckout; import org.eclipse.jgit.dircache.DirCacheCheckout;
* *
* @return the Ref after reset * @return the Ref after reset
*/ */
public Ref call() throws IOException {
public Ref call() throws GitAPIException {
checkCallable(); checkCallable();


Ref r; Ref r;

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java View File



import org.eclipse.jgit.api.MergeResult.MergeStatus; import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.MultipleParentsNotAllowedException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.MultipleParentsNotAllowedException;
import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.dircache.DirCacheCheckout; import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;

+ 3
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/RmCommand.java View File

import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
* *
* @return the DirCache after Rm * @return the DirCache after Rm
*/ */
public DirCache call() throws NoFilepatternException {
public DirCache call() throws GitAPIException,
NoFilepatternException {


if (filepatterns.isEmpty()) if (filepatterns.isEmpty())
throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired); throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired);

+ 2
- 5
org.eclipse.jgit/src/org/eclipse/jgit/api/ShowNoteCommand.java View File



import java.io.IOException; import java.io.IOException;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
super(repo); super(repo);
} }


/**
* @throws JGitInternalException
* upon internal failure
*/
public Note call() throws JGitInternalException {
public Note call() throws GitAPIException {
checkCallable(); checkCallable();
RevWalk walk = new RevWalk(repo); RevWalk walk = new RevWalk(repo);
NoteMap map = NoteMap.newEmptyMap(); NoteMap map = NoteMap.newEmptyMap();

+ 3
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java View File

return false; return false;
} }


private ObjectId getHeadTree() throws JGitInternalException,
GitAPIException {
private ObjectId getHeadTree() throws GitAPIException {
final ObjectId headTree; final ObjectId headTree;
try { try {
headTree = repo.resolve(Constants.HEAD + "^{tree}"); headTree = repo.resolve(Constants.HEAD + "^{tree}");
return headTree; return headTree;
} }


private ObjectId getStashId() throws JGitInternalException, GitAPIException {
private ObjectId getStashId() throws GitAPIException {
final String revision = stashRef != null ? stashRef : DEFAULT_REF; final String revision = stashRef != null ? stashRef : DEFAULT_REF;
final ObjectId stashId; final ObjectId stashId;
try { try {
* *
* @return id of stashed commit that was applied * @return id of stashed commit that was applied
*/ */
public ObjectId call() throws GitAPIException, JGitInternalException {
public ObjectId call() throws GitAPIException {
checkCallable(); checkCallable();


if (repo.getRepositoryState() != RepositoryState.SAFE) if (repo.getRepositoryState() != RepositoryState.SAFE)

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java View File

* *
* @return stashed commit or null if no changes to stash * @return stashed commit or null if no changes to stash
*/ */
public RevCommit call() throws GitAPIException, JGitInternalException {
public RevCommit call() throws GitAPIException {
checkCallable(); checkCallable();


Ref head = getHead(); Ref head = getHead();

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java View File

* *
* @return commit id of stash reference or null if no more stashed changes * @return commit id of stash reference or null if no more stashed changes
*/ */
public ObjectId call() throws GitAPIException, JGitInternalException {
public ObjectId call() throws GitAPIException {
checkCallable(); checkCallable();


Ref stashRef = getRef(); Ref stashRef = getRef();

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java View File

import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRefNameException; import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
super(repo); super(repo);
} }


public Collection<RevCommit> call() throws Exception {
public Collection<RevCommit> call() throws GitAPIException {
checkCallable(); checkCallable();


try { try {

+ 10
- 5
org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java View File



import java.io.IOException; import java.io.IOException;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.IndexDiff; import org.eclipse.jgit.lib.IndexDiff;
* @return a {@link Status} object telling about each path where working * @return a {@link Status} object telling about each path where working
* tree, index or HEAD differ from each other. * tree, index or HEAD differ from each other.
*/ */
public Status call() throws IOException, NoWorkTreeException {
public Status call() throws GitAPIException, NoWorkTreeException {
if (workingTreeIt == null) if (workingTreeIt == null)
workingTreeIt = new FileTreeIterator(repo); workingTreeIt = new FileTreeIterator(repo);


IndexDiff diff = new IndexDiff(repo, Constants.HEAD, workingTreeIt);
diff.diff();

return new Status(diff);
try {
IndexDiff diff = new IndexDiff(repo, Constants.HEAD, workingTreeIt);
diff.diff();
return new Status(diff);
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
}
} }


/** /**

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleAddCommand.java View File

import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
return SubmoduleWalk.forIndex(repo).setFilter(filter).next(); return SubmoduleWalk.forIndex(repo).setFilter(filter).next();
} }


public Repository call() throws JGitInternalException {
public Repository call() throws GitAPIException {
checkCallable(); checkCallable();
if (path == null || path.length() == 0) if (path == null || path.length() == 0)
throw new IllegalArgumentException(JGitText.get().pathNotConfigured); throw new IllegalArgumentException(JGitText.get().pathNotConfigured);

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleInitCommand.java View File

import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.ConfigConstants;
return this; return this;
} }


public Collection<String> call() throws JGitInternalException {
public Collection<String> call() throws GitAPIException {
checkCallable(); checkCallable();


try { try {

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleStatusCommand.java View File

import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
return this; return this;
} }


public Map<String, SubmoduleStatus> call() throws JGitInternalException {
public Map<String, SubmoduleStatus> call() throws GitAPIException {
checkCallable(); checkCallable();


try { try {

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java View File

import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;


import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.ConfigConstants;
return null; return null;
} }


public Map<String, String> call() throws JGitInternalException {
public Map<String, String> call() throws GitAPIException {
checkCallable(); checkCallable();


try { try {

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java View File

return this; return this;
} }


public Collection<String> call() throws JGitInternalException {
public Collection<String> call() throws GitAPIException {
checkCallable(); checkCallable();


try { try {

+ 3
- 7
org.eclipse.jgit/src/org/eclipse/jgit/api/TagCommand.java View File

import java.text.MessageFormat; import java.text.MessageFormat;


import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidTagNameException; import org.eclipse.jgit.api.errors.InvalidTagNameException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoHeadException;
* @return a {@link Ref} a ref pointing to a tag * @return a {@link Ref} a ref pointing to a tag
* @throws NoHeadException * @throws NoHeadException
* when called on a git repo without a HEAD reference * when called on a git repo without a HEAD reference
* @throws JGitInternalException
* a low-level exception of JGit has occurred. The original
* exception can be retrieved by calling
* {@link Exception#getCause()}. Expect only
* {@code IOException's} to be wrapped.
* @since 2.0 * @since 2.0
*/ */
public Ref call() throws JGitInternalException,
ConcurrentRefUpdateException, InvalidTagNameException, NoHeadException {
public Ref call() throws GitAPIException, ConcurrentRefUpdateException,
InvalidTagNameException, NoHeadException {
checkCallable(); checkCallable();


RepositoryState state = repo.getRepositoryState(); RepositoryState state = repo.getRepositoryState();

+ 11
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/errors/UnmergedPathsException.java View File

* The default constructor with a default message * The default constructor with a default message
*/ */
public UnmergedPathsException() { public UnmergedPathsException() {
super(JGitText.get().unmergedPaths);
this(null);
}

/**
* The default constructor with a default message
*
* @param cause
* original exception
*/
public UnmergedPathsException(Throwable cause) {
super(JGitText.get().unmergedPaths, cause);
} }
} }

Loading…
Cancel
Save