Skip to content

Commit

Permalink
#778 added an extra API so we can query the detail of a commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrachan committed Nov 27, 2013
1 parent c64fc03 commit b2d8d60
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
15 changes: 15 additions & 0 deletions hawtio-git/src/main/java/io/hawt/git/GitFacade.java
Expand Up @@ -402,6 +402,21 @@ public List<CommitTreeInfo> call() throws Exception {
}


@Override
public CommitInfo getCommitInfo(final String commitId) {
return gitOperation(getStashPersonIdent(), new Callable<CommitInfo>() {
@Override
public String toString() {
return "getCommitInfo(" + commitId + ")";
}

public CommitInfo call() throws Exception {
return doGetCommitInfo(git, commitId);
}
});
}


@Override
public void revertTo(final String branch, final String objectId, final String blobPath, final String commitMessage,
final String authorName, final String authorEmail) {
Expand Down
6 changes: 6 additions & 0 deletions hawtio-git/src/main/java/io/hawt/git/GitFacadeMXBean.java
Expand Up @@ -60,6 +60,11 @@ void remove(String branch, String path, String commitMessage,
*/
List<CommitTreeInfo> getCommitTree(String commitId);

/**
* Returns details about the commit, such as its message etc
*/
CommitInfo getCommitInfo(String commitId);

/**
* Get the contents of a blobPath for a given commit objectId
*/
Expand All @@ -81,6 +86,7 @@ void remove(String branch, String path, String commitMessage,
*/
String diff(String objectId, String baseObjectId, String blobPath);


/**
* Reverts the file to a previous value
*/
Expand Down
10 changes: 10 additions & 0 deletions hawtio-git/src/main/java/io/hawt/git/GitFacadeSupport.java
Expand Up @@ -187,6 +187,16 @@ protected List<CommitTreeInfo> doGetCommitTree(Git git, String commitId) {
return list;
}

protected CommitInfo doGetCommitInfo(Git git, String commitId) {
Repository repository = git.getRepository();
RevCommit commit = CommitUtils.getCommit(repository, commitId);
if (commit == null){
return null;
} else {
return createCommitInfo(commit);
}
}

protected abstract Iterable<PushResult> doPush(Git git) throws Exception;


Expand Down
19 changes: 11 additions & 8 deletions hawtio-git/src/test/java/io/hawt/git/GitBranchDiffTest.java
@@ -1,19 +1,12 @@
package io.hawt.git;

import io.hawt.util.Strings;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.ObjectName;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

Expand Down Expand Up @@ -107,7 +100,17 @@ public void testBranchesAndDiff() throws Exception {
for (CommitInfo commitInfo : history) {
System.out.println("Version: " + commitInfo);
}
assertCommitTree(history.get(0).getCommitHashText(), 2);
String diffId2 = history.get(0).getCommitHashText();
assertCommitTree(diffId2, 2);
assertCommitInfo(diffId2);
}

protected void assertCommitInfo(String commitId) {
CommitInfo info = git.getCommitInfo(commitId);
assertNotNull("commitInfo", info);
System.out.println("Commit info: " + info);
String shortMessage = info.getShortMessage();
assertNotNull("shortMessage", shortMessage);
}

protected void assertCommitTree(String commitId, int exectedSize) {
Expand Down

0 comments on commit b2d8d60

Please sign in to comment.