Example usage for org.eclipse.jgit.lib Repository getDirectory

List of usage examples for org.eclipse.jgit.lib Repository getDirectory

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository getDirectory.

Prototype


public File getDirectory() 

Source Link

Document

Get local metadata directory

Usage

From source file:org.apache.maven.scm.provider.git.jgit.command.JGitUtils.java

License:Apache License

/**
 * Does the Repository have any commits?
 *
 * @param repo//from www . j ava2  s  .  co m
 * @return false if there are no commits
 */
public static boolean hasCommits(Repository repo) {
    if (repo != null && repo.getDirectory().exists()) {
        return (new File(repo.getDirectory(), "objects").list().length > 2)
                || (new File(repo.getDirectory(), "objects/pack").list().length > 0);
    }
    return false;
}

From source file:org.apache.zeppelin.notebook.repo.GitNotebookRepo.java

License:Apache License

@Override
public void init(ZeppelinConfiguration conf) throws IOException {
    //TODO(zjffdu), it is weird that I can not call super.init directly here, as it would cause
    //AbstractMethodError
    this.conf = conf;
    setNotebookDirectory(conf.getNotebookDir());

    LOGGER.info("Opening a git repo at '{}'", this.rootNotebookFolder);
    Repository localRepo = new FileRepository(Joiner.on(File.separator).join(this.rootNotebookFolder, ".git"));
    if (!localRepo.getDirectory().exists()) {
        LOGGER.info("Git repo {} does not exist, creating a new one", localRepo.getDirectory());
        localRepo.create();//from w ww .  j  ava 2  s .  com
    }
    git = new Git(localRepo);
}

From source file:org.apache.zeppelin.notebook.repo.OldGitNotebookRepo.java

License:Apache License

@Override
public void init(ZeppelinConfiguration conf) throws IOException {
    //TODO(zjffdu), it is weird that I can not call super.init directly here, as it would cause
    //AbstractMethodError
    this.conf = conf;
    setNotebookDirectory(conf.getNotebookDir());

    localPath = getRootDir().getName().getPath();
    LOG.info("Opening a git repo at '{}'", localPath);
    Repository localRepo = new FileRepository(Joiner.on(File.separator).join(localPath, ".git"));
    if (!localRepo.getDirectory().exists()) {
        LOG.info("Git repo {} does not exist, creating a new one", localRepo.getDirectory());
        localRepo.create();/*from   w w  w. j  av a  2s.c  om*/
    }
    git = new Git(localRepo);
}

From source file:org.aysada.licensescollector.dependencies.impl.GitCodeBaseProvider.java

License:Open Source License

public File getLocalRepositoryRoot(String remoteUrl) {
    try {/*  www . j  av  a 2 s .c  o m*/
        File prjWs = getLocalWSFor(remoteUrl);
        if (prjWs.exists()) {
            Repository repo = Git.open(prjWs).getRepository();
            Git git = new Git(repo);
            git.fetch().call();
            git.close();
            LOGGER.info("Lcoal git repo for {} updated.", remoteUrl);
            return repo.getDirectory();
        } else {
            prjWs.mkdir();
            Git localRepo = Git.cloneRepository().setDirectory(prjWs).setURI(remoteUrl)
                    .setCloneAllBranches(false).call();
            File directory = localRepo.getRepository().getDirectory();
            localRepo.close();
            LOGGER.info("Cloned lcoal git repo for {}.", remoteUrl);
            return directory;
        }
    } catch (IOException | GitAPIException e) {
        LOGGER.error("Error working with git.", e);
    }
    return null;
}

From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitBranchDeployer.java

License:Open Source License

private void checkoutEnvironment(Repository repository, String site) {
    Git git = null;//  w  w w  .j a  va  2 s  .  c  o m
    try {
        Ref branchRef = repository.findRef(environment);
        git = new Git(repository);
        git.checkout().setCreateBranch(true).setName(environment)
                .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
                .setStartPoint("origin/" + environment).call();
        git.fetch().call();
        git.pull().call();
    } catch (RefNotFoundException e) {
        try {
            git.checkout().setOrphan(true).setName(environment).call();
            ProcessBuilder pb = new ProcessBuilder();
            pb.command("git", "rm", "-rf", ".");
            pb.directory(repository.getDirectory().getParentFile());
            Process p = pb.start();
            p.waitFor();

            git.commit().setMessage("initial content").setAllowEmpty(true).call();
        } catch (GitAPIException | InterruptedException | IOException e1) {
            logger.error("Error checking out environment store branch for site " + site + " environment "
                    + environment, e1);
        }
    } catch (IOException | GitAPIException e) {
        logger.error(
                "Error checking out environment store branch for site " + site + " environment " + environment,
                e);
    }
}

From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitBranchDeployer.java

License:Open Source License

private void applyPatch(Repository envStoreRepo, String site) {
    String tempPath = System.getProperty("java.io.tmpdir");
    if (tempPath == null) {
        tempPath = "temp";
    }/* w w w. j av a2 s.c  o  m*/
    Path patchPath = Paths.get(tempPath, "patch" + site + ".bin");
    Process p;
    try {
        ProcessBuilder pb = new ProcessBuilder();
        pb.command("git", "apply", patchPath.toAbsolutePath().normalize().toString());
        pb.directory(envStoreRepo.getDirectory().getParentFile());
        p = pb.start();
        p.waitFor();
    } catch (Exception e) {
        logger.error("Error applying patch for site: " + site, e);
    }
}

From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitBranchDeployer.java

License:Open Source License

private void createPatch(Repository repository, String site, String path) {
    StringBuffer output = new StringBuffer();

    String tempPath = System.getProperty("java.io.tmpdir");
    if (tempPath == null) {
        tempPath = "temp";
    }/*from   ww  w  .  jav a  2 s. co m*/
    Path patchPath = Paths.get(tempPath, "patch" + site + ".bin");

    String gitPath = getGitPath(path);
    Process p = null;
    File file = patchPath.toAbsolutePath().normalize().toFile();
    try {
        ProcessBuilder pb = new ProcessBuilder();
        pb.command("git", "diff", "--binary", environment, "master", "--", gitPath);

        pb.redirectOutput(file);
        pb.directory(repository.getDirectory().getParentFile());
        p = pb.start();
        p.waitFor();
    } catch (Exception e) {
        logger.error("Error while creating patch for site: " + site + " path: " + path, e);
    }
}

From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitDeployer.java

License:Open Source License

private void applyPatch(Repository envStoreRepo, String site) {
    String tempPath = System.getProperty("java.io.tmpdir");
    if (tempPath == null) {
        tempPath = "temp";
    }/*from  w  w w  . j av a 2 s .  co  m*/
    Path patchPath = Paths.get(tempPath, "patch" + site + ".bin");
    Process p;
    try {
        ProcessBuilder pb = new ProcessBuilder();
        pb.command("git", "apply", patchPath.toAbsolutePath().normalize().toString());
        pb.directory(envStoreRepo.getDirectory().getParentFile());
        p = pb.start();
        int code = p.waitFor();
        int code2 = p.exitValue();
        logger.debug("Apply patch exited with code: " + code + " " + code2);
    } catch (Exception e) {
        logger.error("Error applying patch for site: " + site, e);
    }
}

From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitDeployer.java

License:Open Source License

private void fetchFromRemote(String site, Repository repository) {
    Process p;/*w  w  w . j a v  a 2s  .  co  m*/
    try {
        ProcessBuilder pb = new ProcessBuilder();
        pb.command("git", "fetch", "work-area");
        pb.directory(repository.getDirectory().getParentFile());
        p = pb.start();
        int code = p.waitFor();
        int code2 = p.exitValue();
        logger.debug("Fetch exit with code: " + code + " " + code2);
    } catch (Exception e) {
        logger.error("Error while fetching from work-area  for site: " + site, e);
    }
}

From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitDeployer.java

License:Open Source License

private InputStream createPatch(Repository repository, String site, String path) {
    StringBuffer output = new StringBuffer();

    String tempPath = System.getProperty("java.io.tmpdir");
    if (tempPath == null) {
        tempPath = "temp";
    }/* www.  jav  a  2 s . com*/
    Path patchPath = Paths.get(tempPath, "patch" + site + ".bin");

    String gitPath = getGitPath(path);
    Process p = null;
    File file = patchPath.toAbsolutePath().normalize().toFile();
    try {
        ProcessBuilder pb = new ProcessBuilder();
        pb.command("git", "diff", "--binary", "HEAD", "FETCH_HEAD", "--", gitPath);

        pb.redirectOutput(file);
        pb.directory(repository.getDirectory().getParentFile());
        p = pb.start();

        int code = p.waitFor();
        int code2 = p.exitValue();
        logger.debug("Create patch exit with code: " + code + " " + code2);
    } catch (Exception e) {
        logger.error("Error while creating patch for site: " + site + " path: " + path, e);
    }
    return null;
}