1

My Existing Code

//clone repo
File localPath = File.createTempFile("TestGitRepository", "");
localPath.delete();
private Repository repo;
Git git = Git.cloneRepository()
                    .setCredentialsProvider(credentials)
                    .setURI(url)
                    .setBranch(branch)
                    .setDirectory(localPath)
                    .call();

                repo = git.getRepository();

//get commit by using cloned repo
 try (Git git = new Git(repo)) {
   Iterable<RevCommit> logs = git.log().call();
   for (RevCommit rev : logs) {
    System.out.println("Commit: " + rev + ", name: " + rev.getName() + ", id: " + rev.getId().getName());

        }
    } catch (Exception e) {
        System.out.println("Exception: {}"+e);
    }

Im able to get list of commits by cloning the repository, i want to avoid cloning of repository. Please share me some links if there is a way to do this and also suggest me additional library if needed.

Inayath
  • 99
  • 9
  • Possible duplicate of [JGit: How to get all commits of a branch? (Without changes to the working directory ...)](https://stackoverflow.com/questions/15822544/jgit-how-to-get-all-commits-of-a-branch-without-changes-to-the-working-direct) – Shashwat Apr 25 '19 at 07:00
  • Not possible. You need to at least fetch the remote branch you are interested in. https://stackoverflow.com/a/5959161/14955 https://superuser.com/a/341446 Maybe there is a way to do a really "thin" clone that does not include any file contents? – Thilo Apr 25 '19 at 07:01
  • Im getting error Exception in thread "main" org.eclipse.jgit.api.errors.NoHeadException: No HEAD exists and no explicit starting revision was specified at org.eclipse.jgit.api.LogCommand.call(LogCommand.java:150) at com.nirmata.environments.git.JGitRepositoryController.getCommits(JGitRepositoryController.java:127) at com.nirmata.environments.git.JGitRepositoryController.main(JGitRepositoryController.java:164) – Inayath Apr 25 '19 at 08:09

2 Answers2

0

Is has been 8 months for this question. In case anyone else is looking for the same answer.I'll show you how to get tag list with out clone it. In JGit you can use the lsRemoteRepository method

Git.lsRemoteRepository().setRemote(gitUrl).setTags(true).call()

Use this method you can get all the tags in remote responsitory

-2

here you can simply use the git command to get the git logs without having a git copy,

git log -- <git http url

for example git log -- git@github.com/twitter/bootstrap.git