Search in sources :

Example 1 with WrongRepositoryStateException

use of org.eclipse.jgit.api.errors.WrongRepositoryStateException in project MGit by maks.

the class CommitChangesTask method commit.

public static void commit(Repo repo, boolean stageAll, boolean isAmend, String msg, String authorName, String authorEmail) throws Exception, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, GitAPIException, StopTaskException {
    Context context = SGitApplication.getContext();
    StoredConfig config = repo.getGit().getRepository().getConfig();
    String committerEmail = config.getString("user", null, "email");
    String committerName = config.getString("user", null, "name");
    if (committerName == null || committerName.equals("")) {
        committerName = Profile.getUsername(context);
    }
    if (committerEmail == null || committerEmail.equals("")) {
        committerEmail = Profile.getEmail(context);
    }
    if (committerName.isEmpty() || committerEmail.isEmpty()) {
        throw new Exception("Please set your name and email");
    }
    if (msg.isEmpty()) {
        throw new Exception("Please include a commit message");
    }
    CommitCommand cc = repo.getGit().commit().setCommitter(committerName, committerEmail).setAll(stageAll).setAmend(isAmend).setMessage(msg);
    if (authorName != null && authorEmail != null) {
        cc.setAuthor(authorName, authorEmail);
    }
    cc.call();
    repo.updateLatestCommitInfo();
}
Also used : Context(android.content.Context) StoredConfig(org.eclipse.jgit.lib.StoredConfig) CommitCommand(org.eclipse.jgit.api.CommitCommand) ConcurrentRefUpdateException(org.eclipse.jgit.api.errors.ConcurrentRefUpdateException) WrongRepositoryStateException(org.eclipse.jgit.api.errors.WrongRepositoryStateException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoHeadException(org.eclipse.jgit.api.errors.NoHeadException) StopTaskException(me.sheimi.sgit.exception.StopTaskException) UnmergedPathsException(org.eclipse.jgit.api.errors.UnmergedPathsException) NoMessageException(org.eclipse.jgit.api.errors.NoMessageException)

Example 2 with WrongRepositoryStateException

use of org.eclipse.jgit.api.errors.WrongRepositoryStateException in project egit by eclipse.

the class RebaseOperationTest method testExceptionWhenRestartingStoppedRebase.

@Test
public void testExceptionWhenRestartingStoppedRebase() throws Exception {
    IFile file = project.createFile("theFile.txt", "Hello, world".getBytes("UTF-8"));
    // first commit in master: add theFile.txt
    RevCommit first = testRepository.addAndCommit(project.project, new File(file.getLocationURI()), "Adding theFile.txt");
    testRepository.createBranch(MASTER, TOPIC);
    file.setContents(new ByteArrayInputStream("master".getBytes("UTF-8")), 0, null);
    // second commit in master: modify theFile.txt
    RevCommit second = git.commit().setAll(true).setMessage("Modify theFile.txt").call();
    assertEquals(first, second.getParent(0));
    // checkout topic
    testRepository.checkoutBranch(TOPIC);
    // set conflicting content in topic
    file.setContents(new ByteArrayInputStream("topic".getBytes("UTF-8")), 0, null);
    // topic commit: add second file
    RevCommit topicCommit = testRepository.addAndCommit(project.project, new File(file.getLocationURI()), "Changing theFile.txt again");
    // parent of topic commit should be first master commit before rebase
    assertEquals(first, topicCommit.getParent(0));
    // rebase topic onto master
    RebaseOperation op = new RebaseOperation(repository, repository.exactRef(MASTER));
    op.execute(null);
    RebaseResult res = op.getResult();
    assertEquals(RebaseResult.Status.STOPPED, res.getStatus());
    try {
        // let's try to start again, we should get a wrapped
        // WrongRepositoryStateException
        op = new RebaseOperation(repository, repository.exactRef(MASTER));
        op.execute(null);
        fail("Expected Exception not thrown");
    } catch (CoreException e) {
        Throwable cause = e.getCause();
        assertTrue(cause instanceof WrongRepositoryStateException);
    }
}
Also used : RebaseOperation(org.eclipse.egit.core.op.RebaseOperation) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) WrongRepositoryStateException(org.eclipse.jgit.api.errors.WrongRepositoryStateException) File(java.io.File) IFile(org.eclipse.core.resources.IFile) RebaseResult(org.eclipse.jgit.api.RebaseResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

WrongRepositoryStateException (org.eclipse.jgit.api.errors.WrongRepositoryStateException)2 Context (android.content.Context)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 StopTaskException (me.sheimi.sgit.exception.StopTaskException)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 RebaseOperation (org.eclipse.egit.core.op.RebaseOperation)1 CommitCommand (org.eclipse.jgit.api.CommitCommand)1 RebaseResult (org.eclipse.jgit.api.RebaseResult)1 ConcurrentRefUpdateException (org.eclipse.jgit.api.errors.ConcurrentRefUpdateException)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 NoHeadException (org.eclipse.jgit.api.errors.NoHeadException)1 NoMessageException (org.eclipse.jgit.api.errors.NoMessageException)1 UnmergedPathsException (org.eclipse.jgit.api.errors.UnmergedPathsException)1 StoredConfig (org.eclipse.jgit.lib.StoredConfig)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 Test (org.junit.Test)1