Gush\Helper\GitHelper::mergeBranch PHP Method

mergeBranch() public method

public mergeBranch ( string $base, string $sourceBranch, string $commitMessage, boolean $fastForward = false ) : null | string
$base string The base branch name
$sourceBranch string The source branch name
$commitMessage string Commit message to use for the merge-commit
$fastForward boolean Perform merge using fast-forward (default false)
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 trim($this->processHelper->runCommand('git rev-parse HEAD'));
        }
        $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'));
    }

Usage Example

示例#1
0
 /**
  * @test
  */
 public function merges_remote_branch_fast_forward_in_clean_wc()
 {
     $base = 'master';
     $sourceBranch = 'amazing-feature';
     $processHelper = $this->prophesize('Gush\\Helper\\ProcessHelper');
     $this->unitGit = new GitHelper($processHelper->reveal(), $this->gitConfigHelper->reveal(), $this->filesystemHelper->reveal());
     $processHelper->runCommand('git status --porcelain --untracked-files=no')->willReturn("\n");
     $processHelper->runCommand('git rev-parse --abbrev-ref HEAD')->willReturn('master');
     $processHelper->runCommand(['git', 'checkout', 'master'])->shouldBeCalled();
     $processHelper->runCommand(['git', 'merge', '--ff', 'amazing-feature'])->shouldBeCalled();
     $this->assertNull($this->unitGit->mergeBranch($base, $sourceBranch, null, true));
 }