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

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

Introduction

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

Prototype

public static RevCommit parse(byte[] raw) 

Source Link

Document

Parse a commit from its canonical format.

Usage

From source file:com.github.koraktor.mavanagaiata.git.jgit.JGitCommitTest.java

License:Open Source License

@Test
public void test() {
    RevCommit rawCommit = RevCommit.parse(("tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n"
            + "author John Doe <john.doe@example.com> 1162580880 +0000\n"
            + "committer Sebastian Staudt <koraktor@gmail.com> 1275131880 +0200\n" + "\n" + "Commit subject")
                    .getBytes());//from  w ww.  j  a v  a 2s. c om
    Date authorDate = new Date(1162580880000L);
    Date committerDate = new Date(1275131880000L);

    JGitCommit commit = new JGitCommit(rawCommit);
    JGitCommit commit2 = new JGitCommit(rawCommit);

    assertThat(commit.getAuthorDate(), is(equalTo(authorDate)));
    assertThat(commit.getAuthorEmailAddress(), is(equalTo("john.doe@example.com")));
    assertThat(commit.getAuthorName(), is(equalTo("John Doe")));
    assertThat(commit.getAuthorTimeZone(), is(TimeZone.getTimeZone("GMT+0000")));
    assertThat(commit.getCommitterDate(), is(equalTo(committerDate)));
    assertThat(commit.getCommitterEmailAddress(), is(equalTo("koraktor@gmail.com")));
    assertThat(commit.getCommitterName(), is(equalTo("Sebastian Staudt")));
    assertThat(commit.getCommitterTimeZone(), is(TimeZone.getTimeZone("GMT+0200")));
    assertThat(commit.getId(), is(equalTo("db1930d9def14aa4a0d8f7a3e0395e4a2c15855a")));
    assertThat(commit.getMessageSubject(), is(equalTo("Commit subject")));
    assertThat(commit.hashCode(), is(equalTo(rawCommit.getId().hashCode())));
    assertThat(commit, is(equalTo(commit2)));
    assertThat(commit.equals(authorDate), is(false));
}

From source file:com.github.koraktor.mavanagaiata.git.jgit.JGitRepositoryTest.java

License:Open Source License

private RevCommit createCommit() {
    String commitData = String.format(
            "tree %040x\n" + "parent %040x\n" + "author Sebastian Staudt <koraktor@gmail.com> %d +0100\n"
                    + "committer Sebastian Staudt <koraktor@gmail.com> %d +0100\n\n" + "%s",
            new Random().nextLong(), new Random().nextLong(), new Date().getTime(), new Date().getTime(),
            "Commit subject");
    return RevCommit.parse(commitData.getBytes());
}

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

License:Apache License

public RevCommit execute() throws IOException {
    try (final ObjectReader reader = repo.newObjectReader()) {
        return RevCommit.parse(reader.open(objectId).getBytes());
    }//w  w w. j  a  v a 2 s.  c o m
}