Search in sources :

Example 16 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project mdw-designer by CenturyLinkCloud.

the class ProjectInflator method createGitRepository.

public void createGitRepository(IProgressMonitor monitor) {
    try {
        File localDir = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile() + "/" + workflowProject.getName());
        Repository newRepo = null;
        if (workflowProject.getMdwVcsRepository().hasRemoteRepository()) {
            monitor.subTask("Cloning Git repository");
            VcsRepository gitRepo = workflowProject.getMdwVcsRepository();
            Git.cloneRepository().setURI(gitRepo.getRepositoryUrlWithCredentials()).setDirectory(localDir).call();
        } else {
            newRepo = new FileRepository(new File(localDir + "/.git"));
            newRepo.create();
        }
        // .gitignore
        Generator generator = new Generator(shell);
        JetAccess jet = getJet("source/.ignorejet", getProject().getSourceProject(), ".gitignore", null);
        generator.createFile(jet, monitor);
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Create Cloud Project", workflowProject);
    }
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) VcsRepository(com.centurylink.mdw.plugin.project.model.VcsRepository) JetAccess(com.centurylink.mdw.plugin.codegen.JetAccess) VcsRepository(com.centurylink.mdw.plugin.project.model.VcsRepository) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Generator(com.centurylink.mdw.plugin.codegen.Generator)

Example 17 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project Aspose.BarCode-for-Java by aspose-barcode.

the class GitHelper method syncRepository.

/**
 * @param localPath
 * @param remotePath
 * @throws Exception
 */
public static void syncRepository(String localPath, String remotePath) throws Exception {
    Repository localRepo;
    try {
        localRepo = new FileRepository(localPath + "/.git");
        Git git = new Git(localRepo);
        // Pull the changes
        try {
            git.pull().call();
        } catch (Exception exPull) {
            // throw it
            throw exPull;
        }
    } catch (Exception ex) {
        throw new Exception("Could not update Repository from Github. Error: " + ex.getMessage());
    }
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git)

Example 18 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project Aspose.BarCode-for-Java by aspose-barcode.

the class GitHelper method updateRepository.

/**
 * @param localPath
 * @param remotePath
 * @throws Exception
 */
public static void updateRepository(String localPath, String remotePath) throws Exception {
    Repository localRepo;
    try {
        localRepo = new FileRepository(localPath + "/.git");
        Git git = new Git(localRepo);
        // First try to clone the repository
        try {
            Git.cloneRepository().setURI(remotePath).setDirectory(new File(localPath)).call();
        } catch (Exception ex) {
            // If clone fails, try to pull the changes
            try {
                git.pull().call();
            } catch (Exception exPull) {
                // throw it
                throw exPull;
            }
        }
    } catch (Exception ex) {
        throw new Exception("Could not download Repository from Github. Error: " + ex.getMessage());
    }
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) File(java.io.File)

Example 19 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project Aspose.BarCode-for-Java by aspose-barcode.

the class GitHelper method updateRepository.

public static void updateRepository(String localPath, String remotePath) throws Exception {
    Repository localRepo;
    try {
        localRepo = new FileRepository(localPath + "/.git");
        Git git = new Git(localRepo);
        {
            AsposeConstants.println("Cloning Repository [" + remotePath + "]....");
        }
        // First try to clone the repository
        try {
            Git.cloneRepository().setURI(remotePath).setDirectory(new File(localPath)).call();
        } catch (Exception ex) {
            // If clone fails, try to pull the changes
            try {
                git.pull().call();
            } catch (Exception exPull) {
                // Pull also failed. Throw this exception to caller
                {
                    AsposeConstants.println("Pull also failed.");
                }
                // throw it
                throw exPull;
            }
        }
    } catch (Exception ex) {
        throw new Exception("Could not download Repository from Github. Error: " + ex.getMessage());
    }
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) File(java.io.File)

Example 20 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project Aspose.Cells-for-Java by aspose-cells.

the class GitHelper method syncRepository.

/**
 * @param localPath
 * @param remotePath
 * @throws Exception
 */
public static void syncRepository(String localPath, String remotePath) throws Exception {
    Repository localRepo;
    try {
        localRepo = new FileRepository(localPath + "/.git");
        Git git = new Git(localRepo);
        // Pull the changes
        try {
            git.pull().call();
        } catch (Exception exPull) {
            // throw it
            throw exPull;
        }
    } catch (Exception ex) {
        throw new Exception("Could not update Repository from Github. Error: " + ex.getMessage());
    }
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git)

Aggregations

FileRepository (org.eclipse.jgit.internal.storage.file.FileRepository)34 Repository (org.eclipse.jgit.lib.Repository)29 Git (org.eclipse.jgit.api.Git)18 File (java.io.File)16 TestRepository (org.eclipse.jgit.junit.TestRepository)6 IOException (java.io.IOException)5 Test (org.junit.Test)5 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 Before (org.junit.Before)4 GerritPersonIdentProvider (com.google.gerrit.server.GerritPersonIdentProvider)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)3 PersonIdent (org.eclipse.jgit.lib.PersonIdent)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 FileBasedAllProjectsConfigProvider (com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider)2 SitePaths (com.google.gerrit.server.config.SitePaths)2 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)2 ObjectReader (org.eclipse.jgit.lib.ObjectReader)2