/**
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return null|int null or 0 if everything went fine, or an error code
*/
private function executeHistory(InputInterface $input, OutputInterface $output)
{
if (!is_dir($input->getOption('git-repository'))) {
throw new RuntimeException(sprintf('Working directory "%s" does not exist', $input->getOption('git-repository')));
}
$git = new Git($input->getOption('git-repository'));
if (!$git->isWorkingCopyClean()) {
throw new RuntimeException(sprintf('Working directory "%s" is not clean', $input->getOption('git-repository')));
}
$currentBranch = $git->getCurrentBranch();
$revisions = $git->getRevisions();
$printer = null;
$progressBar = null;
if ($input->getOption('log-csv')) {
$printer = new History($input->getOption('log-csv'));
}
if ($input->getOption('progress')) {
$progressBar = new ProgressBar($output, count($revisions));
$progressBar->start();
}
foreach ($revisions as $revision) {
$git->checkout($revision['sha1']);
$directories = [];
foreach ($input->getArgument('values') as $value) {
$directory = realpath($value);
if ($directory) {
$directories[] = $directory;
}
}
$_count = $this->count($directories, $input->getOption('exclude'), $this->handleCSVOption($input, 'names'), $this->handleCSVOption($input, 'names-exclude'), $input->getOption('count-tests'));
if ($_count) {
$_count['commit'] = $revision['sha1'];
$_count['date'] = $revision['date']->format(\DateTime::W3C);
if ($printer) {
$printer->printRow($_count);
}
}
if ($progressBar !== null) {
$progressBar->advance();
}
}
$git->checkout($currentBranch);
if ($progressBar !== null) {
$progressBar->finish();
$output->writeln('');
}
}