Search in sources :

Example 66 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gitiles by GerritCodeReview.

the class LogSoyData method renderStreaming.

public void renderStreaming(Paginator paginator, @Nullable String revision, Renderer renderer, Writer out, DateFormatter df) throws IOException {
    renderer.newRenderer("gitiles.logEntriesHeader").setData(toHeaderSoyData(paginator, revision)).render(out);
    out.flush();
    SoyTofu.Renderer entryRenderer = renderer.newRenderer("gitiles.logEntryWrapper");
    boolean renderedEntries = false;
    for (RevCommit c : paginator) {
        entryRenderer.setData(toEntrySoyData(paginator, c, df)).render(out);
        out.flush();
        renderedEntries = true;
    }
    if (!renderedEntries) {
        renderer.newRenderer("gitiles.emptyLog").render(out);
    }
    renderer.newRenderer("gitiles.logEntriesFooter").setData(toFooterSoyData(paginator, revision)).render(out);
}
Also used : SoyTofu(com.google.template.soy.tofu.SoyTofu) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 67 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project camel by apache.

the class GitCommitConsumer method poll.

@Override
protected int poll() throws Exception {
    int count = 0;
    Iterable<RevCommit> commits = getGit().log().all().call();
    for (RevCommit commit : commits) {
        if (!commitsConsumed.contains(commit.getId())) {
            Exchange e = getEndpoint().createExchange();
            e.getOut().setBody(commit);
            getProcessor().process(e);
            commitsConsumed.add(commit.getId());
            count++;
        }
    }
    return count;
}
Also used : Exchange(org.apache.camel.Exchange) GitEndpoint(org.apache.camel.component.git.GitEndpoint) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 68 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project camel by apache.

the class GitProducer method doCherryPick.

protected void doCherryPick(Exchange exchange, String operation) throws Exception {
    CherryPickResult result = null;
    String commitId = null;
    try {
        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_ID))) {
            commitId = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_ID, String.class);
        } else {
            throw new IllegalArgumentException("Commit id must be specified to execute " + operation);
        }
        RevWalk walk = new RevWalk(repo);
        ObjectId id = repo.resolve(commitId);
        RevCommit commit = walk.parseCommit(id);
        walk.dispose();
        if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
            git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
        }
        result = git.cherryPick().include(commit).call();
    } catch (Exception e) {
        LOG.error("There was an error in Git " + operation + " operation");
        throw e;
    }
    updateExchange(exchange, result);
}
Also used : CherryPickResult(org.eclipse.jgit.api.CherryPickResult) ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 69 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project camel by apache.

the class GitTestSupport method validateGitLogs.

protected void validateGitLogs(Git git, String... messages) throws GitAPIException {
    Iterable<RevCommit> logs = git.log().call();
    int count = 0;
    for (RevCommit rev : logs) {
        assertEquals(messages[count], rev.getShortMessage());
        count++;
    }
    assertEquals(messages.length, count);
}
Also used : RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 70 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project camel by apache.

the class GitConsumerTest method commitConsumerTest.

@Test
public void commitConsumerTest() throws Exception {
    // Init
    MockEndpoint mockResultCommit = getMockEndpoint("mock:result-commit");
    mockResultCommit.expectedMessageCount(2);
    Git git = getGitTestRepository();
    File gitDir = new File(gitLocalRepo, ".git");
    assertEquals(gitDir.exists(), true);
    File fileToAdd = new File(gitLocalRepo, filenameToAdd);
    fileToAdd.createNewFile();
    git.add().addFilepattern(filenameToAdd).call();
    Status status = git.status().call();
    assertTrue(status.getAdded().contains(filenameToAdd));
    git.commit().setMessage(commitMessage).call();
    File fileToAdd1 = new File(gitLocalRepo, filenameBranchToAdd);
    fileToAdd1.createNewFile();
    git.add().addFilepattern(filenameBranchToAdd).call();
    status = git.status().call();
    assertTrue(status.getAdded().contains(filenameBranchToAdd));
    git.commit().setMessage("Test test Commit").call();
    Iterable<RevCommit> logs = git.log().call();
    validateGitLogs(git, "Test test Commit", commitMessage);
    // Test
    mockResultCommit.assertIsSatisfied();
    // Check
    Exchange ex1 = mockResultCommit.getExchanges().get(0);
    Exchange ex2 = mockResultCommit.getExchanges().get(1);
    assertEquals(commitMessage, ex2.getOut().getBody(RevCommit.class).getShortMessage());
    assertEquals("Test test Commit", ex1.getOut().getBody(RevCommit.class).getShortMessage());
    git.close();
}
Also used : Status(org.eclipse.jgit.api.Status) Exchange(org.apache.camel.Exchange) Git(org.eclipse.jgit.api.Git) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

RevCommit (org.eclipse.jgit.revwalk.RevCommit)1302 Test (org.junit.Test)650 RevWalk (org.eclipse.jgit.revwalk.RevWalk)333 ObjectId (org.eclipse.jgit.lib.ObjectId)295 Repository (org.eclipse.jgit.lib.Repository)273 IOException (java.io.IOException)222 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)190 Ref (org.eclipse.jgit.lib.Ref)174 File (java.io.File)134 ArrayList (java.util.ArrayList)134 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)133 Git (org.eclipse.jgit.api.Git)133 PersonIdent (org.eclipse.jgit.lib.PersonIdent)105 Change (com.google.gerrit.entities.Change)87 TestRepository (org.eclipse.jgit.junit.TestRepository)72 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)70 ObjectReader (org.eclipse.jgit.lib.ObjectReader)64 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)61 List (java.util.List)61 HashMap (java.util.HashMap)57