use of org.eclipse.jgit.api.Git in project camel by apache.
the class AbstractGitConsumer method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
this.repo = getLocalRepository();
this.git = new Git(repo);
}
use of org.eclipse.jgit.api.Git 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();
}
use of org.eclipse.jgit.api.Git 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();
}
use of org.eclipse.jgit.api.Git in project camel by apache.
the class GitProducerTest method commitAllDifferentBranchTest.
@Test
public void commitAllDifferentBranchTest() 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();
validateGitLogs(git, commitMessage);
git.checkout().setCreateBranch(true).setName(branchTest).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
File fileToAdd1 = new File(gitLocalRepo, filenameBranchToAdd);
fileToAdd1.createNewFile();
// Test camel-git add and commit (different branches)
template.send("direct:add-on-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, filenameBranchToAdd);
}
});
template.send("direct:commit-all-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessageAll);
}
});
// Check
validateGitLogs(git, commitMessageAll, commitMessage);
git.close();
}
use of org.eclipse.jgit.api.Git in project camel by apache.
the class GitProducerTest method commitTestAllowEmptyFalse.
@Test(expected = CamelExecutionException.class)
public void commitTestAllowEmptyFalse() 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 commit (with allowEmpty set to false)
Map<String, Object> headers = new HashMap<>();
headers.put(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
template.requestBodyAndHeaders("direct:commit-not-allow-empty", "", headers);
// Check : An exception should have been raised
}
Aggregations