Search in sources :

Example 16 with GitOperation

use of io.fabric8.git.internal.GitOperation in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method importProfiles.

@Override
public void importProfiles(final String versionId, final List<String> profileZipUrls) {
    IllegalStateAssertion.assertNotNull(versionId, "versionId");
    IllegalStateAssertion.assertNotNull(profileZipUrls, "profileZipUrls");
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        GitOperation<String> gitop = new GitOperation<String>() {

            public String call(Git git, GitContext context) throws Exception {
                // TODO(tdi): Is it correct to implicitly create the version?
                createOrCheckoutVersion(git, versionId);
                // checkoutRequiredProfileBranch(git, versionId, null);
                return doImportProfiles(git, context, profileZipUrls);
            }
        };
        executeWrite(gitop, versionId);
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext)

Example 17 with GitOperation

use of io.fabric8.git.internal.GitOperation 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 18 with GitOperation

use of io.fabric8.git.internal.GitOperation 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 19 with GitOperation

use of io.fabric8.git.internal.GitOperation 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 20 with GitOperation

use of io.fabric8.git.internal.GitOperation 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)

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