Gush\Command\Branch\BranchMergeCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var GitHelper $gitHelper */
        $gitHelper = $this->getHelper('git');
        /** @var GitConfigHelper $gitConfigHelper */
        $gitConfigHelper = $this->getHelper('git_config');
        $targetOrg = $input->getOption('org');
        $targetRepo = $input->getOption('repo');
        $sourceOrg = $input->getOption('source-org');
        $sourceRepo = $input->getOption('source-repo');
        if (null === $sourceOrg) {
            $sourceOrg = $targetOrg;
        }
        if (null === $sourceRepo) {
            $sourceRepo = $targetRepo;
        }
        $gitConfigHelper->ensureRemoteExists($sourceOrg, $sourceRepo);
        $gitConfigHelper->ensureRemoteExists($targetOrg, $targetRepo);
        $squash = $input->getOption('squash') || $input->getOption('force-squash');
        $targetBranch = $input->getArgument('target_branch');
        $sourceBranch = $input->getArgument('source_branch');
        if ($input->getOption('fast-forward')) {
            $this->getHelper('gush_style')->note('Merging with fast-forward, merge message is not available.');
        }
        $this->validateWorkFlow($input, $sourceBranch, $targetBranch);
        $message = (string) $input->getOption('message');
        if ('' === $message) {
            $message = sprintf("Merge branch '%s' into %s", ($sourceOrg !== $targetOrg ? $sourceOrg . '/' : '') . $sourceBranch, $targetBranch);
        }
        try {
            $mergeOperation = $gitHelper->createRemoteMergeOperation();
            $mergeOperation->setSource($sourceOrg, $sourceBranch);
            $mergeOperation->setTarget($targetOrg, $targetBranch);
            $mergeOperation->squashCommits($squash, $input->getOption('force-squash'));
            $mergeOperation->setMergeMessage($message, !$input->getOption('no-log'));
            $mergeOperation->useFastForward($input->getOption('fast-forward'));
            $mergeOperation->performMerge();
            $mergeOperation->pushToRemote();
            $this->getHelper('gush_style')->success(sprintf('Branch "%s" has been merged into "%s".', $sourceOrg . '/' . $sourceBranch, $targetOrg . '/' . $targetBranch));
            return self::COMMAND_SUCCESS;
        } catch (CannotSquashMultipleAuthors $e) {
            $this->getHelper('gush_style')->error(['Unable to squash commits when there are multiple authors.', 'Use --force-squash to continue or ask the author to squash commits manually.']);
            $gitHelper->restoreStashedBranch();
            return self::COMMAND_FAILURE;
        }
    }