Search in sources :

Example 6 with GitOperation

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;
        }
    });
}
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 7 with GitOperation

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;
        }
    });
}
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 8 with GitOperation

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;
        }
    });
}
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 9 with GitOperation

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);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) PersonIdent(org.eclipse.jgit.lib.PersonIdent) PushPolicyResult(io.fabric8.git.PullPushPolicy.PushPolicyResult) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) FabricException(io.fabric8.api.FabricException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException)

Example 10 with GitOperation

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();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext) Profile(io.fabric8.api.Profile)

Aggregations

Git (org.eclipse.jgit.api.Git)22 GitContext (io.fabric8.api.GitContext)21 LockHandle (io.fabric8.api.LockHandle)14 IOException (java.io.IOException)8 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 File (java.io.File)7 PersonIdent (org.eclipse.jgit.lib.PersonIdent)7 FabricException (io.fabric8.api.FabricException)3 Profile (io.fabric8.api.Profile)3 GitVersion (io.fabric8.api.commands.GitVersion)2 GitOperation (io.fabric8.git.internal.GitOperation)2 MalformedURLException (java.net.MalformedURLException)2 KeeperException (org.apache.zookeeper.KeeperException)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 DataStoreTemplate (io.fabric8.api.DataStoreTemplate)1 ProfileRegistry (io.fabric8.api.ProfileRegistry)1 ProfileService (io.fabric8.api.ProfileService)1 Version (io.fabric8.api.Version)1 GitVersions (io.fabric8.api.commands.GitVersions)1 GitProxyService (io.fabric8.git.GitProxyService)1