RepositoryStateOperation implements FileCallable<SCMRevisionState> { public SCMRevisionState invoke(File file, VirtualChannel channel) throws IOException, InterruptedException { final BuildRepositoryState state = new BuildRepositoryState(); for (BuildRepository repo : repos) { Repository gitRepo = new FileRepositoryOperation(repo).invoke(file, channel); if (gitRepo == null) continue; state.put(repo, CommitUtils.getLatest(gitRepo)); } return !state.isEmpty() ? state : SCMRevisionState.NONE; } RepositoryStateOperation(Collection<BuildRepository> repos); SCMRevisionState invoke(File file, VirtualChannel channel);  }
@Test public void emptyRepositories() throws Exception { RepositoryStateOperation op = new RepositoryStateOperation( Collections.<BuildRepository> emptyList()); assertEquals(SCMRevisionState.NONE, op.invoke(null, null)); }
@Test public void nonExistentRepository() throws Exception { BuildRepository repo = new BuildRepository("a", "b", null); RepositoryStateOperation op = new RepositoryStateOperation( Collections.singletonList(repo)); assertEquals(SCMRevisionState.NONE, op.invoke(git.tempDirectory(), null)); }
@Test public void oneRepository() throws Exception { RevCommit commit = git.add("file.txt", "a"); BuildRepository repo = new BuildRepository("a", "b", null); RepositoryStateOperation op = new RepositoryStateOperation( Collections.singletonList(repo)); SCMRevisionState state = op.invoke(git.repo().getDirectory(), null); assertNotNull(state); assertTrue(state instanceof BuildRepositoryState); assertEquals(commit, ((BuildRepositoryState) state).get(repo)); }