Example usage for org.eclipse.jgit.api Git describe

List of usage examples for org.eclipse.jgit.api Git describe

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Git describe.

Prototype

public DescribeCommand describe() 

Source Link

Document

Return a command object to come up with a short name that describes a commit in terms of the nearest git tag.

Usage

From source file:com.dell.doradus.core.DoradusServer.java

License:Apache License

/**
 * Get Doradus Version from git repo if it exists; otherwise get it from the local doradus.ver file
 * @return version//from   www  . java2 s .  c  o  m
 */
public static String getDoradusVersion() {
    String version = null;
    try {
        //first read from the local git repository
        Git git = Git.open(new File("../.git"));
        String url = git.getRepository().getConfig().getString("remote", "origin", "url");
        instance().m_logger.info("Remote.origin.url: {}", url);
        if (!Utils.isEmpty(url) && url.contains("dell-oss/Doradus.git")) {
            DescribeCommand cmd = git.describe();
            version = cmd.call();
            instance().m_logger.info("Doradus version found from git repo: {}", version);
            writeVersionToVerFile(version);
        }
    } catch (Throwable e) {
        instance().m_logger.info("failed to read version from git repo");
    }
    //if not found, reading from local file
    if (Utils.isEmpty(version)) {
        try {
            version = getVersionFromVerFile();
            instance().m_logger.info("Doradus version found from doradus.ver file {}", version);
        } catch (IOException e1) {
            version = null;
        }
    }
    return version;
}

From source file:org.eclipse.emf.compare.doc.WikiTextToHTML.java

License:Open Source License

private String gitDescribe() {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    try {/*  w  w w .  jav  a 2  s  . c  om*/
        Repository repo = builder.setWorkTree(new File(".")).readEnvironment() // scan environment GIT_* variables
                .findGitDir() // scan up the file system tree
                .build();
        Git git = new Git(repo);
        DescribeCommand command = git.describe();
        return command.call();
    } catch (IOException e) {
        new RuntimeException(e);
    } catch (GitAPIException e) {
        new RuntimeException(e);
    }
    return "";
}