Search in sources :

Example 16 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class FabricGitFacade method writeBase64.

@Override
public CommitInfo writeBase64(final String branch, final String path, final String commitMessage, final String authorName, final String authorEmail, final String contents) {
    assertValid();
    final PersonIdent personIdent = new PersonIdent(authorName, authorEmail);
    return gitWriteOperation(personIdent, new GitOperation<CommitInfo>() {

        public CommitInfo call(Git git, GitContext context) throws Exception {
            checkoutBranch(git, branch);
            File rootDir = getRootGitDirectory(git);
            byte[] data = Base64.decode(contents);
            CommitInfo answer = doWrite(git, rootDir, branch, path, data, personIdent, commitMessage);
            context.commitMessage(commitMessage);
            return answer;
        }
    });
}
Also used : Git(org.eclipse.jgit.api.Git) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GitContext(io.fabric8.api.GitContext) File(java.io.File) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException)

Example 17 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class ContainerBuilder method synchronizeGitRepositories.

/**
 * ENTESB-6368: Ensures that local git repository is synchronized with fabric-wide git repository.
 */
protected void synchronizeGitRepositories() {
    GitService gitService = ServiceLocator.awaitService(GitService.class);
    GitDataStore gitDataStore = ServiceLocator.awaitService(GitDataStore.class);
    for (int i = 0; i < 10; i++) {
        try {
            LOG.info("Synchronizing Git repositories");
            Iterable<PushResult> results = gitDataStore.doPush(gitService.getGit(), new GitContext().requirePush());
            if (results.iterator().hasNext()) {
                return;
            }
            throw new Exception("No reference was pushed");
        } catch (Exception e) {
            LOG.warn("Synchronization of Git repositories failed: " + e.getMessage());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                throw new RuntimeException(ie);
            }
        }
    }
}
Also used : GitContext(io.fabric8.api.GitContext) GitService(io.fabric8.git.GitService) PushResult(org.eclipse.jgit.transport.PushResult) GitDataStore(io.fabric8.git.GitDataStore) FabricException(io.fabric8.api.FabricException)

Example 18 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class ContainerBuilder method synchronizeGitRepositories.

/**
 * ENTESB-6368: Ensures that local git repository is synchronized with fabric-wide git repository.
 */
protected void synchronizeGitRepositories() {
    GitService gitService = io.fabric8.api.gravia.ServiceLocator.awaitService(GitService.class);
    GitDataStore gitDataStore = io.fabric8.api.gravia.ServiceLocator.awaitService(GitDataStore.class);
    for (int i = 0; i < 10; i++) {
        try {
            LOG.info("Synchronizing Git repositories");
            Iterable<PushResult> results = gitDataStore.doPush(gitService.getGit(), new GitContext().requirePush());
            if (results.iterator().hasNext()) {
                return;
            }
            throw new Exception("No reference was pushed");
        } catch (Exception e) {
            LOG.warn("Synchronization of Git repositories failed: " + e.getMessage());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                throw new RuntimeException(ie);
            }
        }
    }
}
Also used : GitContext(io.fabric8.api.GitContext) GitService(io.fabric8.git.GitService) PushResult(org.eclipse.jgit.transport.PushResult) GitDataStore(io.fabric8.git.GitDataStore) FabricException(io.fabric8.api.FabricException)

Example 19 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class PushPullPolicyIT method noRemoteChangeWhenLocalBranchIsCheckedOutAndNotClean.

@Test
public void noRemoteChangeWhenLocalBranchIsCheckedOutAndNotClean() throws GitAPIException, IOException {
    local.checkout().setName("1.1").setCreateBranch(false).call();
    FileUtils.write(new File(dirLocal, "newFile.txt"), "~");
    FileUtils.write(new File(dirLocal, "fabric/profiles/default.profile/my.special.pid.properties"), "\n# new line", true);
    assertFalse(local.status().call().isClean());
    PullPushPolicy.PullPolicyResult result = policy.doPull(new GitContext(), CP, true);
    assertNull(result.getLastException());
    assertTrue(local.status().call().isClean());
    List<String> versions = new ArrayList<>(result.getVersions());
    // these are sorted (TreeSet)
    assertThat(versions.size(), equalTo(5));
    assertThat(versions.get(0), equalTo("1.0"));
    assertThat(versions.get(1), equalTo("1.0.1"));
    assertThat(versions.get(2), equalTo("1.1"));
    assertThat(versions.get(3), equalTo("1.2"));
    assertThat(versions.get(4), equalTo("master"));
    List<String> localUpdateVersions = new ArrayList<>(result.localUpdateVersions().keySet());
    assertThat(localUpdateVersions.size(), equalTo(0));
    assertFalse(result.remoteUpdateRequired());
    List<Ref> localBranches = local.branchList().call();
    assertThat(localBranches.size(), equalTo(5));
    assertNotNull(local.getRepository().getRef("1.1"));
}
Also used : Ref(org.eclipse.jgit.lib.Ref) GitContext(io.fabric8.api.GitContext) ArrayList(java.util.ArrayList) DefaultPullPushPolicy(io.fabric8.git.internal.DefaultPullPushPolicy) File(java.io.File) Test(org.junit.Test)

Example 20 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class PushPullPolicyIT method remoteRemovalOfSingleBranchWhenLocalBranchIsCheckedOutAndNotClean.

@Test
public void remoteRemovalOfSingleBranchWhenLocalBranchIsCheckedOutAndNotClean() throws GitAPIException, IOException {
    servlet.branchDelete().setForce(true).setBranchNames("1.1").call();
    local.checkout().setName("1.1").setCreateBranch(false).call();
    FileUtils.write(new File(dirLocal, "newFile.txt"), "~");
    FileUtils.write(new File(dirLocal, "fabric/profiles/default.profile/my.special.pid.properties"), "\n# new line", true);
    assertFalse(local.status().call().isClean());
    PullPushPolicy.PullPolicyResult result = policy.doPull(new GitContext(), CP, true);
    assertNull(result.getLastException());
    List<String> versions = new ArrayList<>(result.getVersions());
    // these are sorted (TreeSet)
    assertThat(versions.size(), equalTo(4));
    assertThat(versions.get(0), equalTo("1.0"));
    assertThat(versions.get(1), equalTo("1.0.1"));
    assertThat(versions.get(2), equalTo("1.2"));
    assertThat(versions.get(3), equalTo("master"));
    List<String> localUpdateVersions = new ArrayList<>(result.localUpdateVersions().keySet());
    assertThat(localUpdateVersions.size(), equalTo(1));
    assertThat(localUpdateVersions.get(0), equalTo("1.1"));
    assertFalse(result.remoteUpdateRequired());
    List<Ref> localBranches = local.branchList().call();
    assertThat(localBranches.size(), equalTo(4));
    assertNull(local.getRepository().getRef("1.1"));
}
Also used : Ref(org.eclipse.jgit.lib.Ref) GitContext(io.fabric8.api.GitContext) ArrayList(java.util.ArrayList) DefaultPullPushPolicy(io.fabric8.git.internal.DefaultPullPushPolicy) File(java.io.File) Test(org.junit.Test)

Aggregations

GitContext (io.fabric8.api.GitContext)41 Git (org.eclipse.jgit.api.Git)22 DefaultPullPushPolicy (io.fabric8.git.internal.DefaultPullPushPolicy)18 Test (org.junit.Test)18 LockHandle (io.fabric8.api.LockHandle)15 ArrayList (java.util.ArrayList)13 File (java.io.File)12 Ref (org.eclipse.jgit.lib.Ref)11 IOException (java.io.IOException)9 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 PushResult (org.eclipse.jgit.transport.PushResult)8 PersonIdent (org.eclipse.jgit.lib.PersonIdent)7 FabricException (io.fabric8.api.FabricException)5 Profile (io.fabric8.api.Profile)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 GitVersion (io.fabric8.api.commands.GitVersion)2 GitDataStore (io.fabric8.git.GitDataStore)2 GitService (io.fabric8.git.GitService)2 PushPolicyResult (io.fabric8.git.PullPushPolicy.PushPolicyResult)2 GitOperation (io.fabric8.git.internal.GitOperation)2