本文整理汇总了Java中org.eclipse.jgit.lib.Repository.getBranch方法的典型用法代码示例。如果您正苦于以下问题:Java Repository.getBranch方法的具体用法?Java Repository.getBranch怎么用?Java Repository.getBranch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.lib.Repository
的用法示例。
在下文中一共展示了Repository.getBranch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GitTool
import org.eclipse.jgit.lib.Repository; //导入方法依赖的package包/类
public GitTool() {
File gitWorkDir = new File(".");
try {
Git git = Git.open(gitWorkDir);
Iterable<RevCommit> commits = git.log().all().call();
Repository repo = git.getRepository();
branch = repo.getBranch();
RevCommit latestCommit = commits.iterator().next();
name = latestCommit.getName();
message = latestCommit.getFullMessage();
} catch (Throwable e) {
name = "";
message = "";
branch = "";
}
}
示例2: getRepoMetadata
import org.eclipse.jgit.lib.Repository; //导入方法依赖的package包/类
/**
* Fetch all commit metadata from the repo
* @param repoDir repository directory
* @return list of commit metadata
* @throws IOException
* @throws GitAPIException
*/
public static List<CommitMetadata> getRepoMetadata(String repoDir) throws IOException, GitAPIException {
List<CommitMetadata> metadataList = new ArrayList<>();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(repoDir, ".git")).readEnvironment().findGitDir().build();
// Current branch may not be master. Instead of hard coding determine the current branch
String currentBranch = repository.getBranch();
Ref head = repository.getRef("refs/heads/" + currentBranch); // current branch may not be "master"
if (head == null) {
return metadataList;
}
Git git = new Git(repository);
RevWalk walk = new RevWalk(repository);
RevCommit commit = walk.parseCommit(head.getObjectId());
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(commit.getTree());
treeWalk.setRecursive(true);
while (treeWalk.next()) {
String filePath = treeWalk.getPathString();
Iterable<RevCommit> commitLog = git.log().add(repository.resolve(Constants.HEAD)).addPath(filePath).call();
for (RevCommit r : commitLog) {
CommitMetadata metadata = new CommitMetadata(r.getName());
metadata.setFilePath(filePath);
metadata.setFileName(FilenameUtils.getName(filePath));
metadata.setMessage(r.getShortMessage().trim());
// Difference between committer and author
// refer to: http://git-scm.com/book/ch2-3.html
PersonIdent committer = r.getCommitterIdent();
PersonIdent author = r.getAuthorIdent();
metadata.setAuthor(author.getName());
metadata.setAuthorEmail(author.getEmailAddress());
metadata.setCommitter(committer.getName());
metadata.setCommitterEmail(committer.getEmailAddress());
metadata.setCommitTime(committer.getWhen());
metadataList.add(metadata);
}
}
git.close();
return metadataList;
}