0

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.

Double M
  • 1,449
  • 1
  • 12
  • 29
  • execute git log – David Mar 12 '18 at 14:41
  • you cannot do this with git command line tool, it always works on the local repo. You need a "git server" (like *Hithub*, *stash*, *gerrit* or alike) that provide a web-API to list the commits (or have their own commit list page...). – Timothy Truckle Mar 12 '18 at 15:06
  • To show the history of a Git repository you need to clone it first. – Rüdiger Herrmann Mar 12 '18 at 15:11
  • @RüdigerHerrmann That's very disappointing, thanks anyway. Do you know of any other way to mirror a repo to cloud storage (AWS S3)? – Double M Mar 12 '18 at 15:47
  • @DoubleM isn't *Github* sort of a "cloud storrage"? You can pay there for a account with private repositories, but as you plan to put you repo on AWS you might not have any valuable "intelectual property" in there anyway... – Timothy Truckle Mar 12 '18 at 16:30
  • There is an article describing how to push to an S3 storage: http://blog.spearce.org/2008/07/using-jgit-to-publish-on-amazon-s3.html – Rüdiger Herrmann Mar 12 '18 at 16:41
  • @TimothyTruckle Well yes, however I need to aggregate data from different version control systems (git, svn...) and also direct file uploads in one place. S3 is what I chose as generic cloud storage. – Double M Mar 12 '18 at 18:05
  • @RüdigerHerrmann Thanks. This will still require me to clone to local and then push to S3 if the original repo is located outside S3 (which it always is). Anyway I appreciate your help, thanks again. – Double M Mar 12 '18 at 18:08

0 Answers0