/**
* @param string $base The base branch name
* @param string $sourceBranch The source branch name
* @param string $commitMessage Commit message to use for the merge-commit
* @param bool $fastForward Perform merge using fast-forward (default false)
*
* @throws WorkingTreeIsNotReady
*
* @return null|string The merge-commit hash or null when fast-forward was used
*/
public function mergeBranch($base, $sourceBranch, $commitMessage, $fastForward = false)
{
$this->guardWorkingTreeReady();
$this->stashBranchName();
$this->checkout($base);
if ($fastForward) {
$this->processHelper->runCommand(['git', 'merge', '--ff', $sourceBranch]);
return;
}
$tmpName = $this->filesystemHelper->newTempFilename();
file_put_contents($tmpName, $commitMessage);
$this->processHelper->runCommands([['line' => ['git', 'merge', '--no-ff', '--no-commit', '--no-log', $sourceBranch], 'allow_failures' => false], ['line' => ['git', 'commit', '-F', $tmpName], 'allow_failures' => false]]);
return trim($this->processHelper->runCommand('git rev-parse HEAD'));
}