Given a remote location, I would like to list all commits of that repository without having to clone it, using JGit.
As far as I know, accessing commits is only possible by doing a RevWalk
. To obtain an object of this class, you need an object of Repository
. Now I tried creating a new, empty repository locally like so:
Git git = Git.init().setDirectory(localDir).call();
... and adding a remote location afterwards like so:
git.remoteAdd()
.setName("origin");
.setUri(new URIish(remoteLocationStr));
.call();
However, when I try to start the RevWalk
, it is empty.
try (RevWalk revWalk = new RevWalk(git.getRepository())) {
for( RevCommit commit : revWalk ) {
//... nothing to iterate here
}
}
I assume this is due to the fact that I never did a clone
, pull
or similar to actually update the local file system with the necessary information.
Is there any way to achieve this without having to clone the whole repository? Using fetch
perhaps? (any tricks allowed)
Use Case
I need to sync cloud storage with the contents of a git repository. After having cloned and uploaded all files of the repository, it is deleted from the machine that performed the upload. Unless hooks are available, I periodically check whether the latest commit happened after my latest upload. If so, I re-clone the repository and upload again.
If there is an entirely different, better approach of achieving this please let me know.