Example usage for org.eclipse.jgit.storage.file FileRepositoryBuilder FileRepositoryBuilder

List of usage examples for org.eclipse.jgit.storage.file FileRepositoryBuilder FileRepositoryBuilder

Introduction

In this page you can find the example usage for org.eclipse.jgit.storage.file FileRepositoryBuilder FileRepositoryBuilder.

Prototype

FileRepositoryBuilder

Source Link

Usage

From source file:org.oneandone.gitter.gitio.GitDirectory.java

License:Apache License

GitDirectory(Path dir, boolean patchScriptSize, ReportSetup reportSetup) throws IOException {
    this.dir = Objects.requireNonNull(dir);
    this.patchScriptSize = patchScriptSize;
    this.reportSetup = Objects.requireNonNull(reportSetup);

    Path gitDir = guessGitDir(dir);
    log.debug("Dir is {}, guessed is {}", dir, gitDir);
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    this.repository = builder.setGitDir(gitDir.toFile()).readEnvironment() // scan environment GIT_* variables
            .findGitDir() // scan up the file system tree
            .build();//from  w w  w .  j a va  2s.com
}

From source file:org.onexus.resource.manager.internal.providers.GitProjectProvider.java

License:Apache License

@Override
protected void importProject() {

    try {/*from   w  w  w .j  a va 2s.  co m*/

        File projectFolder = getProjectFolder();

        boolean cloneDone = true;

        if (!projectFolder.exists()) {
            projectFolder.mkdir();
            cloneDone = false;
        }

        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repository = builder.setWorkTree(projectFolder).readEnvironment().build();
        Git git = new Git(repository);

        if (cloneDone) {
            PullCommand pull = git.pull();
            pull.call();

        } else {
            CloneCommand clone = git.cloneRepository();
            clone.setBare(false);
            clone.setCloneAllBranches(true);
            clone.setDirectory(projectFolder).setURI(getProjectUrl().toString());
            clone.call();

            //TODO Checkout branch
        }

    } catch (Exception e) {
        LOGGER.error("Importing project '" + getProjectUrl() + "'", e);
        throw new InvalidParameterException("Error importing project. " + e.getMessage());
    }
}

From source file:org.openehr.designer.repository.git.GitArchetypeRepository.java

License:Open Source License

@PostConstruct
public void init() throws IOException, GitAPIException {
    File repoFolderFile = new File(gitRepoFolder);

    if (!repoFolderFile.exists()) {
        try {//from ww  w. j  a v  a  2 s  .c om
            LOG.info("Local git folder not found, cloning from remote");
            // clone from remote git
            CloneCommand clone = new CloneCommand();
            clone.setProgressMonitor(new TextProgressMonitor());
            clone.setURI(gitUrl);
            clone.setDirectory(new File(gitRepoFolder));
            clone.setBranch("master");
            git = clone.call();
        } catch (GitAPIException e) {
            FileSystemUtils.deleteRecursively(repoFolderFile);
            throw e;
        }
    } else {
        LOG.info("Local git folder found, pulling from remote");
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repository = builder.setWorkTree(repoFolderFile).readEnvironment().build();
        git = new Git(repository);
        update();
    }
    parseRepository();

}

From source file:org.openengsb.connector.git.internal.GitServiceImpl.java

License:Apache License

/**
 * Initializes the {@link FileRepository} or creates a new own if it does
 * not exist./*from w w  w  . ja  v  a2  s.  c  om*/
 */
private void initRepository() throws IOException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    builder.setWorkTree(localWorkspace);
    repository = builder.build();
    if (!new File(localWorkspace, ".git").isDirectory()) {
        repository.create();
        repository.getConfig().setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
        repository.getConfig().setString("remote", "origin", "url", remoteLocation);
        repository.getConfig().setString("branch", watchBranch, "remote", "origin");
        repository.getConfig().setString("branch", watchBranch, "merge", "refs/heads/" + watchBranch);
        repository.getConfig().save();
    }
}

From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java

License:Apache License

@Test(expected = ScmException.class)
public void tagEmptyRepoWithName_shouldThrowSCMException() throws Exception {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    localRepository = builder.setWorkTree(localDirectory).build();
    localRepository.create();/*from w ww .  ja v  a2 s.  c o  m*/
    service.tagRepo("newTag");
}

From source file:org.openengsb.connector.git.internal.RepositoryFixture.java

License:Apache License

private static FileRepository create(File directory) throws IOException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    FileRepository repository = builder.setWorkTree(directory).build();
    repository.create();//from   w  w  w .j  a va 2s  .  co  m
    return repository;
}

From source file:org.test.RewriteGitHistory.java

License:Apache License

/**
 * //from ww  w .ja v  a  2s  .  c  om
 */
public RewriteGitHistory(File gitRepositoryPath, ICommitFilter personIdentFilter, PersonIdent selfCommitIdent)
        throws IOException {
    super();
    this.commitFilter = personIdentFilter;
    this.selfCommitIdent = selfCommitIdent;

    FileRepositoryBuilder builder = new FileRepositoryBuilder();

    repository = builder.setGitDir(gitRepositoryPath).readEnvironment() // scan
            // environment
            // GIT_*
            // variables

            .build();

    git = new Git(repository);

}

From source file:org.tomitribe.lieutenant.git.Git.java

License:Apache License

private void initGit() {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    try {/*from   www .  j ava  2  s . c  o m*/
        Repository repository = builder.setGitDir(_gitDirectory.toFile()).readEnvironment() // scan environment GIT_* variables
                .setMustExist(true).build();
        this.git = new org.eclipse.jgit.api.Git(repository);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:org.uberfire.java.nio.fs.jgit.util.commands.CreateRepository.java

License:Apache License

public Optional<Git> execute() {
    try {//from w w w .  ja  va 2s.c  om
        final org.eclipse.jgit.api.Git _git = org.eclipse.jgit.api.Git.init().setBare(true)
                .setDirectory(repoDir).call();

        if (leaders != null) {
            new WriteConfiguration(_git.getRepository(), cfg -> {
                cfg.setInt("core", null, "repositoryformatversion", 1);
                cfg.setString("extensions", null, "refsStorage", "reftree");
            }).execute();
        }

        final Repository repo = new FileRepositoryBuilder().setGitDir(repoDir).build();

        final org.eclipse.jgit.api.Git git = new org.eclipse.jgit.api.Git(repo);

        if (hookDir != null) {
            final File repoHookDir = new File(repoDir, "hooks");

            try {
                FileUtils.copyDirectory(hookDir, repoHookDir);
            } catch (final Exception ex) {
                throw new RuntimeException(ex);
            }

            for (final File file : repoHookDir.listFiles()) {
                if (file != null && file.isFile()) {
                    file.setExecutable(true);
                }
            }
        }

        return Optional.of(new GitImpl(git, leaders));
    } catch (final Exception ex) {
        throw new IOException(ex);
    }
}

From source file:org.wso2.carbon.appfactory.repository.mgt.git.JGitAgent.java

License:Apache License

/**
 * Get local repository//from   w  w w  .j  a v a  2  s  .c o  m
 *
 * @param repositoryDir local repo directory
 * @return a repository matching this configuration.
 * @throws IOException if there is no git repo in the given {@code repositoryDir}
 */
private Repository getLocalRepository(File repositoryDir) throws IOException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    return builder.addCeilingDirectory(repositoryDir).setWorkTree(repositoryDir).findGitDir(repositoryDir)
            .setMustExist(true).build();
}