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

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

Introduction

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

Prototype

public Git(Repository repo) 

Source Link

Document

Construct a new org.eclipse.jgit.api.Git object which can interact with the specified git repository.

Usage

From source file:facade.GitFacade.java

public static void commitRepo(Repository repository, String message) throws GitAPIException {
    Git git = new Git(repository);
    git.add().addFilepattern(".").call();
    git.commit().setAll(true).setMessage(message).call();

}

From source file:facade.GitFacade.java

public static String pushRepo(Repository repository, String username, String password) throws GitAPIException {
    Git git = new Git(repository);
    CredentialsProvider provider = new UsernamePasswordCredentialsProvider(username, password);
    PushCommand pushCommand = git.push();
    pushCommand.setCredentialsProvider(provider).setForce(true).setPushAll();

    Iterable<PushResult> result = pushCommand.call();

    if (!result.iterator().next().getMessages().isEmpty())
        return result.iterator().next().getMessages();
    else/* w  w w .  j a v  a  2  s.c om*/
        return "OK";

}

From source file:facade.GitFacade.java

public static String pullRepo(Repository repository) throws GitAPIException {
    Git git = new Git(repository);
    PullResult result = null;/*from www .ja v a2 s  .c  o m*/
    org.eclipse.jgit.api.PullCommand pullComand = git.pull();
    result = pullComand.call();
    MergeResult mergeResult = result.getMergeResult();

    return "Merge Status: " + mergeResult.getMergeStatus().toString();

}

From source file:fi.otavanopisto.changelogger.Changelogger.java

private static void prependLine(String line, String message) throws IOException, GitAPIException {
    FileRepositoryBuilder frBuilder = new FileRepositoryBuilder();
    Repository repository = frBuilder.setGitDir(new File("./.git")).readEnvironment().build();
    Git git = new Git(repository);

    git.reset().setMode(ResetCommand.ResetType.HARD).call();
    git.clean().call();//from w ww .jav  a 2s .  c o  m
    git.fetch().call();
    git.pull().call();

    File file = new File(CHANGELOG_FILE);
    List<String> lines = FileUtils.readLines(file, Charsets.UTF_8);
    lines.add(0, line);
    FileUtils.writeLines(file, lines);

    git.commit().setMessage(message).setAuthor("Changelogger", "changelogger@otavanopisto.fi").call();

    git.push().call();
}

From source file:fi.otavanopisto.santra.Santra.java

License:Open Source License

private void reload(String botName) throws IOException, GitAPIException {
    log.info("Starting bot reload");
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository = builder.setGitDir(new File(arguments.getBasePath() + "/.git")).readEnvironment()
            .build();/*from   w ww  . j av a  2 s.c  o  m*/
    log.info("Starting repository update");
    Git git = new Git(repository);
    git.reset().setMode(ResetCommand.ResetType.HARD).call();
    log.info("Reset complete");
    git.clean().call();
    log.info("Clean compete");
    git.fetch().call();
    log.info("Fetch complete");
    git.pull().call();
    log.info("Repository update finished");

    initBot(botName);
    log.info("Bot reloaded");
}

From source file:fr.brouillard.oss.jgitver.GitVersionCalculator.java

License:Apache License

/**
 * Calculates the version to use for the current git repository depending on the HEAD position.
 * //  w ww . j av  a2  s  .c  om
 * @return the calculated version object
 */
public Version getVersionObject() {
    metadatas = new MetadataHolder();

    try {
        this.repository = openRepository();
    } catch (Exception ex) {
        return Version.NOT_GIT_VERSION;
    }
    try (Git git = new Git(repository)) {
        VersionStrategy strategy;

        VersionNamingConfiguration vnc = new VersionNamingConfiguration(findTagVersionPattern,
                extractTagVersionPattern, Arrays.asList(nonQualifierBranches.split("\\s*,\\s*")));

        if (mavenLike) {
            strategy = new MavenVersionStrategy(vnc, repository, git, metadatas);
        } else {
            ConfigurableVersionStrategy cvs = new ConfigurableVersionStrategy(vnc, repository, git, metadatas);
            cvs.setAutoIncrementPatch(autoIncrementPatch);
            cvs.setUseDistance(useDistance);
            cvs.setUseDirty(useDirty);
            cvs.setUseGitCommitId(useGitCommitId);
            cvs.setGitCommitIdLength(gitCommitIdLength);
            strategy = cvs;
        }

        return buildVersion(git, strategy);
    }
}

From source file:fr.brouillard.oss.jgitver.strategy.configurable.defaults.Scenario10WithDefaultsTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * //from w  w  w  .j  a v  a2s. c om
 * @throws IOException if a disk error occurred
 */
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation());

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}

From source file:fr.brouillard.oss.jgitver.strategy.configurable.inc.Scenario1AutoIncTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * @throws IOException if a disk error occurred
 */// w  w  w. ja v  a 2  s .c o  m
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation())
            .setAutoIncrementPatch(true);

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}

From source file:fr.brouillard.oss.jgitver.strategy.configurable.others.Scenario5WithMasterAndIntBranchesNonQualifiedTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * /* w  w  w  .j  a v  a  2  s .  c o  m*/
 * @throws IOException if a disk error occurred
 */
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation())
            .setNonQualifierBranches("master,int");

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}

From source file:fr.brouillard.oss.jgitver.strategy.configurable.others.Scenario8WithLongFormatTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * //w w  w  . j ava2 s  . co m
 * @throws IOException if a disk error occurred
 */
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation());
    versionCalculator.setUseGitCommitId(true);
    versionCalculator.setUseLongFormat(true);
    versionCalculator.setGitCommitIdLength(8);
    versionCalculator.setUseDistance(true);

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}