Example usage for org.eclipse.jgit.revwalk RevCommit toString

List of usage examples for org.eclipse.jgit.revwalk RevCommit toString

Introduction

In this page you can find the example usage for org.eclipse.jgit.revwalk RevCommit toString.

Prototype

@Override
public String toString() 

Source Link

Usage

From source file:ezbake.deployer.publishers.openShift.RhcApplication.java

License:Apache License

/**
 * Updates the OpenShift application with the changes locally applied. (git commit, git Push)
 * This will cause the new app to be deployed to openshift.  After this the new version should be visible.
 *
 * @throws DeploymentException On any error deploying the application.
 *///from w  w  w  .  j av a  2 s  .  com
public void publishChanges() throws DeploymentException {

    try {
        RevCommit commit = gitRepo.commit().setMessage("RhcApplication: publishing newest version")
                .setAuthor(applicationDomain.getUser().getRhlogin(), applicationDomain.getUser().getRhlogin())
                .call();

        log.info("[" + getApplicationName() + "][GIT-COMMIT] committed changes to local git repo. "
                + commit.toString());
        PushCommand pushCommand = gitRepo.push();
        if (gitCredentialsProvider != null)
            pushCommand.setCredentialsProvider(gitCredentialsProvider);
        for (PushResult result : pushCommand.setForce(true).setTimeout(100000).call()) {
            if (!result.getMessages().isEmpty())
                log.info("[" + getApplicationName() + "][GIT-PUSH] " + result.getMessages());
            log.info("[" + getApplicationName() + "][GIT-PUSH] Successfully pushed application.");
        }
    } catch (GitAPIException e) {
        log.error("[" + getApplicationName() + "] Error adding updated files to deployment git repo", e);
        throw new DeploymentException(e.getMessage());
    }
}

From source file:org.eclipse.mylyn.internal.gerrit.core.remote.ReviewHarness.java

License:Open Source License

void checkoutPatchSet(int number) throws Exception {
    IReviewItemSet patchSet = getReview().getSets().get(0);
    ObjectId ref = git.getRepository().resolve(patchSet.getRevision());
    RevWalk walker = new RevWalk(git.getRepository());
    RevCommit targetCommit = walker.parseCommit(ref);

    //make sure to checkout the correct commit
    assertThat(targetCommit.toString(), is(commitId));

    git.checkout().setCreateBranch(true).setName("change" + "/" + getReview().getId() + "/" + number)
            .setStartPoint(targetCommit).call();
}

From source file:org.uberfire.java.nio.fs.jgit.JGitSquashingTest.java

License:Apache License

@Test
public void testSquash4Of5Commits() throws IOException, GitAPIException {

    final File parentFolder = createTempDirectory();
    logger.info(">> Parent Forlder for the Test: " + parentFolder.getAbsolutePath());
    final File gitFolder = new File(parentFolder, "my-local-repo.git");

    final Git origin = new CreateRepository(gitFolder).execute().get();

    new Commit(origin, "master", "salaboy", "salaboy@example.com", "commit 1!", null, null, false,
            new HashMap<String, File>() {
                {/*from www  . j a  v  a 2 s. c  om*/
                    put("path/to/file1.txt", tempFile("initial content file 1"));
                }
            }).execute();
    new Commit(origin, "master", "salaboy", "salaboy@example.com", "commit 2!", null, null, false,
            new HashMap<String, File>() {
                {
                    put("path/to/file2.txt", tempFile("initial content file 2"));
                }
            }).execute();
    Iterable<RevCommit> logs = ((GitImpl) origin)._log().setMaxCount(1).all().call();
    RevCommit secondCommit = logs.iterator().next();

    new Commit(origin, "master", "salaboy", "salaboy@example.com", "commit 3!", null, null, false,
            new HashMap<String, File>() {
                {
                    put("path/to/file1.txt", tempFile("new content file 1"));
                }
            }).execute();

    new Commit(origin, "master", "salaboy", "salaboy@example.com", "commit 4!", null, null, false,
            new HashMap<String, File>() {
                {
                    put("path/to/file2.txt", tempFile("new content file 2"));
                }
            }).execute();
    new Commit(origin, "master", "salaboy", "salaboy@example.com", "commit 5!", null, null, false,
            new HashMap<String, File>() {
                {
                    put("path/to/file3.txt", tempFile("initial content file 3"));
                }
            }).execute();
    logs = ((GitImpl) origin)._log().all().call();
    int commitsCount = 0;
    for (RevCommit commit : logs) {
        logger.info(">>> Origin Commit: " + commit.getFullMessage() + " - " + commit.toString());
        commitsCount++;
    }
    assertThat(commitsCount).isEqualTo(5);

    assertThat(origin.getPathInfo("master", "pathx/").getPathType()).isEqualTo(NOT_FOUND);
    assertThat(origin.getPathInfo("master", "path/to/file1.txt").getPathType()).isEqualTo(FILE);
    assertThat(origin.getPathInfo("master", "path/to/file2.txt").getPathType()).isEqualTo(FILE);
    assertThat(origin.getPathInfo("master", "path/to/file3.txt").getPathType()).isEqualTo(FILE);
    assertThat(origin.getPathInfo("master", "path/to").getPathType()).isEqualTo(DIRECTORY);

    logger.info("Squashing from " + secondCommit.getName() + "  to HEAD");
    new Squash((GitImpl) origin, "master", secondCommit.getName(), "squashed message").execute();

    commitsCount = 0;
    for (RevCommit commit : ((GitImpl) origin)._log().all().call()) {
        logger.info(">>> Final Commit: " + commit.getFullMessage() + " - " + commit.toString());
        commitsCount++;
    }
    assertThat(commitsCount).isEqualTo(2);
}

From source file:org.uberfire.java.nio.fs.jgit.JGitSquashingTest.java

License:Apache License

private List<RevCommit> getCommitsFromBranch(final GitImpl origin, String branch)
        throws GitAPIException, MissingObjectException, IncorrectObjectTypeException {
    List<RevCommit> commits = new ArrayList<>();
    final ObjectId id = new GetRef(origin.getRepository(), branch).execute().getObjectId();
    for (RevCommit commit : origin._log().add(id).call()) {
        logger.info(">>> " + branch + " Commits: " + commit.getFullMessage() + " - " + commit.toString());
        commits.add(commit);//from  w ww  .  ja va 2  s .c o m
    }
    return commits;
}

From source file:org.uberfire.java.nio.fs.jgit.JGitSquashingTest.java

License:Apache License

@Test
public void testSquashCommitsWithDifferentPaths() throws IOException, GitAPIException {

    final File parentFolder = createTempDirectory();
    logger.info(">> Parent Folder for the Test: " + parentFolder.getAbsolutePath());
    final File gitFolder = new File(parentFolder, "my-local-repo.git");

    final Git origin = new CreateRepository(gitFolder).execute().get();

    new Commit(origin, "master", "salaboy", "salaboy@example.com", "commit 1!", null, null, false,
            new HashMap<String, File>() {
                {//from   www  .j  a va  2s .c  om
                    put("file1.txt", tempFile("initial content file 1"));
                }
            }).execute();
    new Commit(origin, "master", "salaboy", "salaboy@example.com", "commit 2!", null, null, false,
            new HashMap<String, File>() {
                {
                    put("path/to/file2.txt", tempFile("initial content file 2"));
                }
            }).execute();
    Iterable<RevCommit> logs = ((GitImpl) origin)._log().setMaxCount(1).all().call();
    RevCommit secondCommit = logs.iterator().next();

    new Commit(origin, "master", "salaboy", "salaboy@example.com", "commit 3!", null, null, false,
            new HashMap<String, File>() {
                {
                    put("file1.txt", tempFile("new content file 1"));
                }
            }).execute();

    new Commit(origin, "master", "salaboy", "salaboy@example.com", "commit 4!", null, null, false,
            new HashMap<String, File>() {
                {
                    put("path/to/file2.txt", tempFile("new content file 2"));
                }
            }).execute();
    new Commit(origin, "master", "salaboy", "salaboy@example.com", "commit 5!", null, null, false,
            new HashMap<String, File>() {
                {
                    put("path/file3.txt", tempFile("initial content file 3"));
                }
            }).execute();

    for (RevCommit commit : ((GitImpl) origin)._log().all().call()) {
        logger.info(">>> Origin Commit: " + commit.getFullMessage() + " - " + commit.toString());
    }

    assertThat(origin.getPathInfo("master", "pathx/").getPathType()).isEqualTo(NOT_FOUND);
    assertThat(origin.getPathInfo("master", "file1.txt").getPathType()).isEqualTo(FILE);
    assertThat(origin.getPathInfo("master", "path/to/file2.txt").getPathType()).isEqualTo(FILE);
    assertThat(origin.getPathInfo("master", "path/file3.txt").getPathType()).isEqualTo(FILE);
    assertThat(origin.getPathInfo("master", "path/to").getPathType()).isEqualTo(DIRECTORY);

    logger.info("Squashing from " + secondCommit.getName() + "  to HEAD");
    new Squash((GitImpl) origin, "master", secondCommit.getName(), "squashed message").execute();

    int commitsCount = 0;
    for (RevCommit commit : ((GitImpl) origin)._log().all().call()) {
        logger.info(">>> Final Commit: " + commit.getFullMessage() + " - " + commit.toString());
        commitsCount++;
    }

    assertThat(commitsCount).isEqualTo(2);
}