@Test public void branchChangedFiles_should_return_null_on_git_api_errors() throws GitAPIException { DiffCommand diffCommand = mock(DiffCommand.class); when(diffCommand.setShowNameAndStatusOnly(anyBoolean())).thenReturn(diffCommand); when(diffCommand.setOldTree(any())).thenReturn(diffCommand); when(diffCommand.call()).thenThrow(mock(GitAPIException.class)); Git git = mock(Git.class); when(git.diff()).thenReturn(diffCommand); GitScmProvider provider = new GitScmProvider(mockCommand()) { @Override Git newGit(Repository repo) { return git; } }; assertThat(provider.branchChangedFiles("branch", worktree)).isNull(); }
private DiffCommand getDiffCommand( String oldCommitId, String newCommitId ) throws Exception { return git.diff() .setOldTree( getTreeIterator( oldCommitId ) ) .setNewTree( getTreeIterator( newCommitId ) ); }
/** * Returns the diff between two commits. * * @return List that contains DiffEntry objects of the changes made between the previous and current commits. * @throws Exception */ private void getDiffs() throws Exception { OutputStream out = new ByteArrayOutputStream(); CanonicalTreeParser oldTree = getTree(prevCommit); CanonicalTreeParser newTree = getTree(curCommit); DiffCommand diff = git.diff().setOutputStream(out).setOldTree(oldTree).setNewTree(newTree); diffs = diff.call(); }