Search in sources :

Example 1 with PullResult

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();
        }
    }
}
Also used : Git(org.eclipse.jgit.api.Git) MergeResult(org.eclipse.jgit.api.MergeResult) IRepositoryContentProvider(aQute.bnd.deployer.repository.api.IRepositoryContentProvider) File(java.io.File) PullResult(org.eclipse.jgit.api.PullResult)

Example 2 with PullResult

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());
}
Also used : File(java.io.File) PullResult(org.eclipse.jgit.api.PullResult) Test(org.junit.Test)

Example 3 with PullResult

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);
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) PullResult(org.eclipse.jgit.api.PullResult) IOException(java.io.IOException)

Aggregations

PullResult (org.eclipse.jgit.api.PullResult)3 File (java.io.File)2 IRepositoryContentProvider (aQute.bnd.deployer.repository.api.IRepositoryContentProvider)1 IOException (java.io.IOException)1 Git (org.eclipse.jgit.api.Git)1 MergeResult (org.eclipse.jgit.api.MergeResult)1 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)1 Test (org.junit.Test)1