use of io.fabric8.git.internal.GitOperation in project fabric8 by jboss-fuse.
the class FabricGitFacade method write.
@Override
public CommitInfo write(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 = contents.getBytes();
CommitInfo answer = doWrite(git, rootDir, branch, path, data, personIdent, commitMessage);
context.commitMessage(commitMessage);
return answer;
}
});
}
use of io.fabric8.git.internal.GitOperation in project fabric8 by jboss-fuse.
the class FabricGitFacade method revertTo.
@Override
public void revertTo(final String branch, final String objectId, final String blobPath, final String commitMessage, final String authorName, final String authorEmail) {
assertValid();
final PersonIdent personIdent = new PersonIdent(authorName, authorEmail);
gitWriteOperation(personIdent, new GitOperation<Void>() {
public Void call(Git git, GitContext context) throws Exception {
checkoutBranch(git, branch);
File rootDir = getRootGitDirectory(git);
Void answer = doRevert(git, rootDir, branch, objectId, blobPath, commitMessage, personIdent);
context.commitMessage(commitMessage);
return answer;
}
});
}
use of io.fabric8.git.internal.GitOperation 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.git.internal.GitOperation in project fabric8 by jboss-fuse.
the class DummyBatchingProgressMonitor method executeInternal.
private <T> T executeInternal(GitContext context, PersonIdent personIdent, GitOperation<T> operation) {
if (context.isRequirePull() || context.isRequireCommit()) {
assertWriteLock();
} else {
assertReadLock();
}
// [FABRIC-887] Must set the TCCL to the classloader that loaded GitDataStore as we need the classloader
// that could load this class, as jgit will load resources from classpath using the TCCL
// and that requires the TCCL to the classloader that could load GitDataStore as the resources
// jgit requires are in the same bundle as GitDataSource (eg embedded inside fabric-git)
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
ClassLoader gitcl = GitDataStoreImpl.class.getClassLoader();
Thread.currentThread().setContextClassLoader(gitcl);
LOGGER.trace("Setting ThreadContextClassLoader to {} instead of {}", gitcl, tccl);
Git git = getGit();
Repository repository = git.getRepository();
if (personIdent == null) {
personIdent = new PersonIdent(repository);
}
if (context.isRequirePull()) {
doPullInternal(context, getCredentialsProvider(), false, gitTimeout);
}
T result = operation.call(git, context);
if (context.isRequireCommit()) {
doCommit(git, context);
Object cacheKey = context.getCacheKey();
if (cacheKey == null || cacheKey.equals(GitHelpers.MASTER_BRANCH)) {
versionCache.invalidateAll();
} else {
versionCache.invalidate(cacheKey);
}
notificationRequired = true;
}
if (context.isRequirePush()) {
PushPolicyResult pushResult = doPushInternal(context, getCredentialsProvider());
if (!pushResult.getRejectedUpdates().isEmpty()) {
Exception gitex = pushResult.getLastException();
throw new IllegalStateException("Push rejected: " + pushResult.getRejectedUpdates().values(), gitex);
}
}
return result;
} catch (Exception e) {
throw FabricException.launderThrowable(e);
} finally {
LOGGER.trace("Restoring ThreadContextClassLoader to {}", tccl);
Thread.currentThread().setContextClassLoader(tccl);
}
}
use of io.fabric8.git.internal.GitOperation in project fabric8 by jboss-fuse.
the class DummyBatchingProgressMonitor method updateProfile.
@Override
public String updateProfile(GitContext context, final Profile profile, boolean force) {
IllegalStateAssertion.assertNotNull(profile, "profile");
LockHandle writeLock = aquireWriteLock();
try {
assertValid();
// Get the existing profile
final String versionId = profile.getVersion();
final String profileId = profile.getId();
final Profile lastProfile = getRequiredProfile(versionId, profileId);
if (force || !lastProfile.equals(profile)) {
GitOperation<String> gitop = new GitOperation<String>() {
public String call(Git git, GitContext context) throws Exception {
checkoutRequiredProfileBranch(git, context, versionId, profileId);
return createOrUpdateProfile(context, lastProfile, profile, new HashSet<String>());
}
};
return executeInternal(context, null, gitop);
} else {
LOGGER.debug("Skip unchanged profile update for: {}", profile);
return lastProfile.getId();
}
} finally {
writeLock.unlock();
}
}
Aggregations