Search in sources :

Example 31 with FileRepositoryBuilder

use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project fabric8 by fabric8io.

the class GitUtils method findRepository.

/**
 * Returns the git repository for the current folder or null if none can be found
 */
public static Repository findRepository(File baseDir) throws IOException {
    File gitFolder = io.fabric8.utils.GitHelpers.findGitFolder(baseDir);
    if (gitFolder == null) {
        // No git repository found
        return null;
    }
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository = builder.readEnvironment().setGitDir(gitFolder).build();
    return repository;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) File(java.io.File) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder)

Example 32 with FileRepositoryBuilder

use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project winery by eclipse.

the class GitBasedRepository method getGit.

private Git getGit() throws IOException, GitAPIException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository gitRepo = builder.setWorkTree(this.repository.getRepositoryRoot().toFile()).setMustExist(false).build();
    String repoUrl = configuration.getRepositoryUrl();
    String branch = configuration.getBranch();
    Git git;
    if (!Files.exists(this.repository.getRepositoryRoot().resolve(".git"))) {
        if (repoUrl != null && !repoUrl.isEmpty()) {
            git = cloneRepository(repoUrl, branch);
        } else {
            gitRepo.create();
            git = new Git(gitRepo);
        }
    } else {
        git = new Git(gitRepo);
    }
    return git;
}
Also used : IWrappingRepository(org.eclipse.winery.repository.backend.IWrappingRepository) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder)

Aggregations

FileRepositoryBuilder (org.eclipse.jgit.storage.file.FileRepositoryBuilder)32 Repository (org.eclipse.jgit.lib.Repository)30 File (java.io.File)25 Git (org.eclipse.jgit.api.Git)12 IOException (java.io.IOException)8 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)6 ObjectId (org.eclipse.jgit.lib.ObjectId)4 Path (java.nio.file.Path)3 CloneCommand (org.eclipse.jgit.api.CloneCommand)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 Ref (org.eclipse.jgit.lib.Ref)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)3 URIish (org.eclipse.jgit.transport.URIish)3 RefLogEntry (com.gitblit.models.RefLogEntry)2 Reader (java.io.Reader)2 PersonIdent (org.eclipse.jgit.lib.PersonIdent)2 TaskAction (org.gradle.api.tasks.TaskAction)2 Test (org.junit.Test)2 GHRepository (org.kohsuke.github.GHRepository)2