Search in sources :

Example 1 with Ref

use of org.eclipse.jgit.lib.Ref in project camel by apache.

the class GitTagConsumer method poll.

@Override
protected int poll() throws Exception {
    int count = 0;
    List<Ref> call = getGit().tagList().call();
    for (Ref ref : call) {
        if (!tagsConsumed.contains(ref.getName())) {
            Exchange e = getEndpoint().createExchange();
            e.getOut().setBody(ref);
            getProcessor().process(e);
            tagsConsumed.add(ref.getName());
            count++;
        }
    }
    return count;
}
Also used : Exchange(org.apache.camel.Exchange) Ref(org.eclipse.jgit.lib.Ref) GitEndpoint(org.apache.camel.component.git.GitEndpoint)

Example 2 with Ref

use of org.eclipse.jgit.lib.Ref in project camel by apache.

the class GitConsumerTest method branchConsumerTest.

@Test
public void branchConsumerTest() throws Exception {
    // Init
    MockEndpoint mockResultBranch = getMockEndpoint("mock:result-branch");
    mockResultBranch.expectedMessageCount(2);
    Git git = getGitTestRepository();
    File fileToAdd = new File(gitLocalRepo, filenameToAdd);
    fileToAdd.createNewFile();
    git.add().addFilepattern(filenameToAdd).call();
    File gitDir = new File(gitLocalRepo, ".git");
    assertEquals(gitDir.exists(), true);
    Status status = git.status().call();
    assertTrue(status.getAdded().contains(filenameToAdd));
    git.commit().setMessage(commitMessage).call();
    git.branchCreate().setName(branchTest).call();
    List<Ref> ref = git.branchList().call();
    boolean branchCreated = false;
    for (Ref refInternal : ref) {
        if (refInternal.getName().equals("refs/heads/" + branchTest)) {
            branchCreated = true;
        }
    }
    assertEquals(branchCreated, true);
    // Test
    mockResultBranch.assertIsSatisfied();
    // Check
    List<Exchange> exchanges = mockResultBranch.getExchanges();
    assertEquals("refs/heads/master", exchanges.get(0).getOut().getBody(ObjectIdRef.Unpeeled.class).getName());
    assertEquals("refs/heads/" + branchTest, exchanges.get(1).getOut().getBody(ObjectIdRef.Unpeeled.class).getName());
    git.close();
}
Also used : Status(org.eclipse.jgit.api.Status) Exchange(org.apache.camel.Exchange) ObjectIdRef(org.eclipse.jgit.lib.ObjectIdRef) Ref(org.eclipse.jgit.lib.Ref) ObjectIdRef(org.eclipse.jgit.lib.ObjectIdRef) Git(org.eclipse.jgit.api.Git) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) Test(org.junit.Test)

Example 3 with Ref

use of org.eclipse.jgit.lib.Ref in project camel by apache.

the class GitProducerTest method cherryPickTest.

@Test
public void cherryPickTest() throws Exception {
    // Init
    Git git = getGitTestRepository();
    File fileToAdd = new File(gitLocalRepo, filenameToAdd);
    fileToAdd.createNewFile();
    git.add().addFilepattern(filenameToAdd).call();
    File gitDir = new File(gitLocalRepo, ".git");
    assertEquals(gitDir.exists(), true);
    Status status = git.status().call();
    assertTrue(status.getAdded().contains(filenameToAdd));
    git.commit().setMessage(commitMessage).call();
    git.branchCreate().setName(branchTest).call();
    List<Ref> branches = git.branchList().call();
    Boolean branchExists = false;
    for (Ref reference : branches) {
        if (("refs/heads/" + branchTest).equals(reference.getName())) {
            branchExists = true;
        }
    }
    assertTrue(branchExists);
    String fileToAdd1Name = "filetest1test.txt";
    File fileToAdd1 = new File(gitLocalRepo, fileToAdd1Name);
    fileToAdd1.createNewFile();
    git.add().addFilepattern(fileToAdd1Name).call();
    status = git.status().call();
    assertTrue(status.getAdded().contains(fileToAdd1Name));
    git.commit().setMessage("Test second commit").call();
    Iterable<RevCommit> logs = git.log().call();
    validateGitLogs(git, "Test second commit", commitMessage);
    String id = logs.iterator().next().getName();
    // Test camel-git cherry-pick
    template.sendBodyAndHeader("direct:cherrypick", "", GitConstants.GIT_COMMIT_ID, id);
    // Check
    validateGitLogs(git, "Test second commit", commitMessage);
    git.close();
}
Also used : Status(org.eclipse.jgit.api.Status) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 4 with Ref

use of org.eclipse.jgit.lib.Ref in project camel by apache.

the class GitProducerTest method logBranchTest.

@Test
public void logBranchTest() throws Exception {
    // Init
    Git git = getGitTestRepository();
    File fileToAdd = new File(gitLocalRepo, filenameToAdd);
    fileToAdd.createNewFile();
    git.add().addFilepattern(filenameToAdd).call();
    File gitDir = new File(gitLocalRepo, ".git");
    assertEquals(gitDir.exists(), true);
    Status status = git.status().call();
    assertTrue(status.getAdded().contains(filenameToAdd));
    git.commit().setMessage(commitMessage).call();
    git.branchCreate().setName(branchTest).call();
    List<Ref> ref = git.branchList().call();
    boolean branchCreated = false;
    for (Ref refInternal : ref) {
        if (refInternal.getName().equals("refs/heads/" + branchTest)) {
            branchCreated = true;
        }
    }
    assertEquals(branchCreated, true);
    File fileToAddDifferent = new File(gitLocalRepo, filenameBranchToAdd);
    fileToAddDifferent.createNewFile();
    git.add().addFilepattern(filenameBranchToAdd).call();
    git.commit().setMessage(commitMessageAll).call();
    // Test camel-git log (with branches)
    Iterable<RevCommit> revCommits = template.requestBody("direct:log-branch", "", Iterable.class);
    // Check
    Iterator<RevCommit> gitLogs = git.log().call().iterator();
    for (RevCommit rev : revCommits) {
        RevCommit gitRevCommit = gitLogs.next();
        assertEquals(gitRevCommit.getName(), rev.getName());
        assertEquals(gitRevCommit.getShortMessage(), rev.getShortMessage());
    }
    git.close();
}
Also used : Status(org.eclipse.jgit.api.Status) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 5 with Ref

use of org.eclipse.jgit.lib.Ref in project camel by apache.

the class GitProducerTest method createBranchTest.

@Test
public void createBranchTest() throws Exception {
    // Init
    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();
    // Test camel-git create-branch
    template.sendBody("direct:create-branch", "");
    // Check
    List<Ref> ref = git.branchList().call();
    boolean branchCreated = false;
    for (Ref refInternal : ref) {
        if (refInternal.getName().equals("refs/heads/" + branchTest)) {
            branchCreated = true;
        }
    }
    assertEquals(branchCreated, true);
    git.close();
}
Also used : Status(org.eclipse.jgit.api.Status) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) File(java.io.File) Test(org.junit.Test)

Aggregations

Ref (org.eclipse.jgit.lib.Ref)137 IOException (java.io.IOException)55 RevCommit (org.eclipse.jgit.revwalk.RevCommit)45 ObjectId (org.eclipse.jgit.lib.ObjectId)38 RevWalk (org.eclipse.jgit.revwalk.RevWalk)37 Repository (org.eclipse.jgit.lib.Repository)35 Change (com.google.gerrit.reviewdb.client.Change)22 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)18 Git (org.eclipse.jgit.api.Git)18 File (java.io.File)16 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)12 OrmException (com.google.gwtorm.server.OrmException)12 Map (java.util.Map)12 PersonIdent (org.eclipse.jgit.lib.PersonIdent)12 Status (org.eclipse.jgit.api.Status)11 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)11 HashMap (java.util.HashMap)10 Account (com.google.gerrit.reviewdb.client.Account)9 Branch (com.google.gerrit.reviewdb.client.Branch)9