Search in sources :

Example 41 with GitContext

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

the class DummyBatchingProgressMonitor method getInitialVersions.

private List<String> getInitialVersions() {
    LockHandle readLock = aquireReadLock();
    try {
        GitOperation<List<String>> gitop = new GitOperation<List<String>>() {

            public List<String> call(Git git, GitContext context) throws Exception {
                Collection<String> branches = RepositoryUtils.getBranches(git.getRepository());
                List<String> answer = new ArrayList<String>();
                for (String branch : branches) {
                    String name = branch;
                    String prefix = "refs/heads/";
                    if (name.startsWith(prefix)) {
                        name = name.substring(prefix.length());
                        if (!name.equals(GitHelpers.MASTER_BRANCH) && !name.startsWith("patch-") && !name.startsWith("patches-") && !name.equals(HISTORY_BRANCH) && !name.equals(ADMIN_HISTORY_BRANCH)) {
                            answer.add(name);
                        }
                    }
                }
                versions.clear();
                versions.addAll(answer);
                if (answer.size() > 0) {
                    LOGGER.info("Initial versions cached");
                    initialVersionsAvailable.countDown();
                }
                return answer;
            }
        };
        return executeRead(gitop);
    } finally {
        readLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext)

Example 42 with GitContext

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

the class DummyBatchingProgressMonitor method createVersion.

@Override
public String createVersion(GitContext context, final String sourceId, final String targetId, final Map<String, String> attributes) {
    IllegalStateAssertion.assertNotNull(sourceId, "sourceId");
    IllegalStateAssertion.assertNotNull(targetId, "targetId");
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        LOGGER.debug("Create version: {} => {}", sourceId, targetId);
        GitOperation<String> gitop = new GitOperation<String>() {

            public String call(Git git, GitContext context) throws Exception {
                IllegalStateAssertion.assertNull(checkoutProfileBranch(git, context, targetId, null), "Version already exists: " + targetId);
                checkoutRequiredProfileBranch(git, context, sourceId, null);
                createOrCheckoutVersion(git, targetId);
                if (attributes != null) {
                    setVersionAttributes(git, context, targetId, attributes);
                }
                context.commitMessage("Create version: " + sourceId + " => " + targetId);
                return targetId;
            }
        };
        return executeInternal(context, null, gitop);
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext)

Example 43 with GitContext

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

the class FabricGitFacade method rename.

@Override
public void rename(final String branch, final String oldPath, final String newPath, final String commitMessage, final String authorName, final String authorEmail) {
    assertValid();
    final PersonIdent personIdent = new PersonIdent(authorName, authorEmail);
    gitWriteOperation(personIdent, new GitOperation<RevCommit>() {

        public RevCommit call(Git git, GitContext context) throws Exception {
            checkoutBranch(git, branch);
            File rootDir = getRootGitDirectory(git);
            RevCommit answer = doRename(git, rootDir, branch, oldPath, newPath, 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) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 44 with GitContext

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

the class FabricGitFacade method createDirectory.

@Override
public CommitInfo createDirectory(final String branch, final String path, final String commitMessage, final String authorName, final String authorEmail) {
    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);
            CommitInfo answer = doCreateDirectory(git, rootDir, branch, path, 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 45 with GitContext

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

the class FabricGitFacade method remove.

@Override
public void remove(final String branch, final String path, final String commitMessage, final String authorName, final String authorEmail) {
    assertValid();
    final PersonIdent personIdent = new PersonIdent(authorName, authorEmail);
    gitWriteOperation(personIdent, new GitOperation<RevCommit>() {

        public RevCommit call(Git git, GitContext context) throws Exception {
            checkoutBranch(git, branch);
            File rootDir = getRootGitDirectory(git);
            RevCommit answer = doRemove(git, rootDir, branch, path, 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) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

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