public function squashCommits($base, $branchName, $ignoreMultipleAuthors = false)
{
$this->guardWorkingTreeReady();
$this->stashBranchName();
$this->checkout($branchName);
// Check if there are multiple authors, we only use the e-mail address
// As the name could have changed (eg. typo's and accents)
if (!$ignoreMultipleAuthors) {
$authors = array_unique(StringUtil::splitLines($this->processHelper->runCommand(['git', '--no-pager', 'log', '--oneline', '--no-color', '--format=%ae', $base . '..' . $branchName])));
if (count($authors) > 1) {
throw new CannotSquashMultipleAuthors();
}
}
// Get commits only in the branch but not in base (in reverse order)
// we can't use --max-count here because that is applied before the reversing!
//
// using git-log works better then finding the fork-point with git-merge-base
// because this protects against edge cases were there is no valid fork-point
$firstCommitHash = StringUtil::splitLines($this->processHelper->runCommand(['git', '--no-pager', 'log', '--oneline', '--no-color', '--format=%H', '--reverse', $base . '..' . $branchName]))[0];
// 0=author anything higher then 0 is the full body
$commitData = StringUtil::splitLines($this->processHelper->runCommand(['git', '--no-pager', 'show', '--format=%an <%ae>%n%s%n%n%b', '--no-color', '--no-patch', $firstCommitHash]));
$author = array_shift($commitData);
$message = implode("\n", $commitData);
$this->reset($base);
$this->commit($message, ['a', '-author' => $author]);
}