Reputation: 1080
I am using EGit APIs to read remote repositories. My use case is to read all the commits of any public git repository. Is it possible with EGit?
Following is my code for reading all the repositories :
GitHubClient client = new GitHubClient();
client.setCredentials("[email protected]", "********");
RepositoryService service = new RepositoryService(client);
List<Repository> repositories = service.getRepositories();
for (int i = 0; i < repositories.size(); i++)
{
Repository get = repositories.get(i);
System.out.println("Repository Name: " + get.getName());
}
And to read the commits I use this:
CommitService commitService = new CommitService(client);
for (RepositoryCommit commit : commitService.getCommits(repository)) {
System.out.println(commit.getCommit().getMessage());
}
This lists only the repositories that belong to me. But let's say I want to read all the commits from a public repo like https://github.com/eclipse/jgit
Is it possible with EGit?
Upvotes: 0
Views: 225
Reputation: 20985
EGit is the Git integration for Eclipse. To access Git repositories programmatically, use JGit. Your code snippets refer to the GitHub API that is also provided by EGit to examine repositories hosted on GitHub.
To get access to the history of an arbitrary Git repository (not just those on GitHub), you'll need to first clone it. For example:
Git.cloneRepository()
.setURI( "https://github.com/eclipse/jgit.git" )
.setDirectory( "path/to/local/repo" )
.call();
A detailed explanation of how to clone repositories with JGit can be found here: http://www.codeaffine.com/2015/11/30/jgit-clone-repository/
Now you can use the LogCommand
to list the commits of the local repository. See here for an example: Retrieving Commit Message Log from Git Using JGit
Upvotes: 1