use of org.eclipse.jgit.api.PullResult in project bndtools by bndtools.
the class GitOBRRepo method put.
@Override
public synchronized PutResult put(InputStream stream, PutOptions options) throws Exception {
init();
try {
repository.incrementOpen();
Git git = Git.wrap(repository);
// Pull remote repository
PullResult pullResult = git.pull().call();
// Check result
MergeResult mergeResult = pullResult.getMergeResult();
if (mergeResult != null && (mergeResult.getMergeStatus() == MergeStatus.CONFLICTING || mergeResult.getMergeStatus() == MergeStatus.FAILED)) {
// TODO: How to report failure
throw new RuntimeException(String.format("Failed to merge changes from %s", gitUri));
}
// TODO: Check if jar already exists, is it ok to overwrite in all repositories?
PutResult result = super.put(stream, options);
if (result.artifact != null) {
File newFile = new File(result.artifact);
// Add, Commit and Push
for (IRepositoryContentProvider provider : generatingProviders) {
if (!provider.supportsGeneration())
continue;
git.add().addFilepattern(getRelativePath(gitRootDir, newFile)).addFilepattern(getRelativePath(gitRootDir, new File(provider.getDefaultIndexName(pretty)))).call();
}
git.commit().setMessage("bndtools added bundle : " + getRelativePath(gitRootDir, newFile)).call();
git.push().setCredentialsProvider(CredentialsProvider.getDefault()).call();
// Re-read the index
reset();
init();
}
return result;
} finally {
if (repository != null) {
repository.close();
}
}
}
use of org.eclipse.jgit.api.PullResult in project camel by apache.
the class GitProducerTest method pullTest.
@Test
public void pullTest() throws Exception {
template.sendBody("direct:clone", "");
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
PullResult pr = template.requestBody("direct:pull", "", PullResult.class);
assertTrue(pr.isSuccessful());
}
use of org.eclipse.jgit.api.PullResult in project camel by apache.
the class GitProducer method doPull.
protected void doPull(Exchange exchange, String operation) throws Exception {
PullResult result = null;
try {
if (ObjectHelper.isEmpty(endpoint.getRemoteName())) {
throw new IllegalArgumentException("Remote name must be specified to execute " + operation);
}
if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
}
if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) {
UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword());
result = git.pull().setCredentialsProvider(credentials).setRemote(endpoint.getRemoteName()).call();
} else {
result = git.pull().setRemote(endpoint.getRemoteName()).call();
}
} catch (Exception e) {
LOG.error("There was an error in Git " + operation + " operation");
throw e;
}
updateExchange(exchange, result);
}
Aggregations