LsRemoteOperation implements Callable<ObjectId, IOException> { public ObjectId call() throws IOException { LsRemoteCommand ls = Git.wrap(gitRepo).lsRemote(); ls.setRemote(repo.getUri()); String branch = repo.getBranch(); Collection<Ref> refs; try { refs = ls.call(); } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } for (Ref ref : refs) if (branch.equals(ref.getName())) return ref.getObjectId(); return null; } LsRemoteOperation(BuildRepository repo, Repository gitRepo); ObjectId call();  }
@Test public void listEmptyRemote() throws Exception { Repository gitRepo = git.repo(); BuildRepository repo = new BuildRepository(gitRepo.getDirectory() .toURI().toString(), Constants.R_HEADS + Constants.MASTER, null); LsRemoteOperation op = new LsRemoteOperation(repo, gitRepo); assertNull(op.call()); }
@Test public void listRemote() throws Exception { Repository gitRepo = git.repo(); BuildRepository repo = new BuildRepository(gitRepo.getDirectory() .toURI().toString(), Constants.R_HEADS + Constants.MASTER, null); LsRemoteOperation op = new LsRemoteOperation(repo, gitRepo); RevCommit commit1 = git.add("file.txt", "a"); assertEquals(commit1, op.call()); RevCommit commit2 = git.add("file.txt", "b"); assertEquals(commit2, op.call()); }