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;
}
});
}
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);
}
}
}
}
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);
}
}
}
}
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"));
}
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"));
}
Aggregations