CliGitLog implements IGitLog { public List<Commit> log(File repositoryPath, GitLogOptions options, ScmLogEntryHandler<Commit> handler) throws JavaGitException, IOException { CheckUtilities.checkFileValidity(repositoryPath); GitLogParser parser = new GitLogParser(handler); List<String> command = buildCommand(repositoryPath, options); GitLogResponse response = (GitLogResponse) ProcessUtilities.runCommand(repositoryPath, command, parser); if (response.containsError()) { int line = response.getError(0).getLineNumber(); String error = response.getError(0).error(); throw new JavaGitException(420001, "Line " + line + ", " + error); } return response.getLog(); }  List<Commit> log(File repositoryPath, GitLogOptions options, ScmLogEntryHandler<Commit> handler); List<Commit> log(File repositoryPath, GitLogOptions options); List<Commit> log(File repositoryPath);  }
@Test public void testGitLogGettingLogs() throws IOException, JavaGitException { CliGitLog gitLog = new CliGitLog(); GitLogOptions options = new GitLogOptions(); options.setOptFileDetails(true); List<Commit> log = gitLog.log(repoDirectory, options); if(log.size()==0){ fail("Failed retrieve logs"); } }
@Test public void testGitLogSha() throws IOException, JavaGitException { CliGitLog gitLog = new CliGitLog(); GitLogOptions options = new GitLogOptions(); options.setOptFileDetails(true); List<Commit> log = gitLog.log(repoDirectory, options); for (int i=0 ;i< log.size() ; i++){ if(log.get(i).getSha().length()!=40){ fail("Failed Sha not correct"); } } }
@Test public void testGitLogSize() throws IOException, JavaGitException { CliGitLog gitLog = new CliGitLog(); GitLogOptions options = new GitLogOptions(); options.setOptFileDetails(true); List<Commit> log = gitLog.log(repoDirectory, options); if(log.size()==2){ return; } else{ fail("Failed Log size does not match"); } }
@Test public void testGitLogCommitLimiting() throws IOException, JavaGitException { CliGitLog gitLog = new CliGitLog(); GitLogOptions options = new GitLogOptions(); options.setOptLimitCommitMax(true, 1); options.setOptFileDetails(true); List<Commit> log = gitLog.log(repoDirectory, options); if(log.size()==1){ return; } else{ fail("Failed Log size does not match, commit limiting failed"); } }
@Test public void testGitLogCommitSkippingandFileName() throws IOException, JavaGitException { CliGitLog gitLog = new CliGitLog(); GitLogOptions options = new GitLogOptions(); options.setOptLimitCommitMax(true, 1); options.setOptFileDetails(true); options.setOptLimitCommitSkip(true, 1); List<Commit> log = gitLog.log(repoDirectory, options); if(log.size()==1){ return; } else{ fail("Failed Log size does not match, commit limiting failed, while skipping"); } if(log.get(0).getFiles().get(0).getName().contains("log.txt")){ } else{ fail("Failed Log file name does not match while skipping"); } }
@Test public void testGitLogCommitMessage() throws IOException, JavaGitException { CliGitLog gitLog = new CliGitLog(); GitLogOptions options = new GitLogOptions(); options.setOptLimitCommitMax(true, 1); options.setOptFileDetails(true); options.setOptLimitCommitSkip(true, 1); List<Commit> log = gitLog.log(repoDirectory, options); if(log.get(0).getMessage().contains("Making a first test commit")){ } else{ fail("Failed Log ,commit message does not match."); } }