Skip to content

Commit

Permalink
Merge pull request #549 from sstok/539-pull-request-merge-reports-wro…
Browse files Browse the repository at this point in the history
…ng-target-when-using-switch-option

Fix PullRequestMerge shows wrong target with switch
  • Loading branch information
cordoval committed Mar 1, 2016
2 parents 1dbb8a9 + 5021b79 commit 0ae54b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/Command/PullRequest/PullRequestMergeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
$gitConfigHelper->ensureRemoteExists($targetRemote, $targetRepository);
$gitConfigHelper->ensureRemoteExists($sourceRemote, $sourceRepository);

if ($input->getOption('switch')) {
$targetLabel = sprintf('New-target: %s/%s (was "%s")', $targetRemote, $input->getOption('switch'), $targetBranch);
} else {
$targetLabel = sprintf('Target: %s/%s', $targetRemote, $targetBranch);
}

$styleHelper->title(sprintf('Merging pull-request #%d - %s', $prNumber, $pr['title']));
$styleHelper->text(
[
sprintf('Source: %s/%s', $sourceRemote, $sourceBranch),
sprintf('Target: %s/%s', $targetRemote, $targetBranch),
$targetLabel,
]
);

Expand Down
20 changes: 18 additions & 2 deletions tests/Command/PullRequest/PullRequestMergeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class PullRequestMergeCommandTest extends CommandTestCase

const COMMAND_DISPLAY = <<<OET
This PR was merged into the base_ref branch.
OET;

const COMMAND_DISPLAY_TARGET = <<<OET
Target: gushphp/base_ref
OET;

const FAILURE_TYPE_DISPLAY = <<<OET
Expand All @@ -84,6 +88,10 @@ class PullRequestMergeCommandTest extends CommandTestCase

const COMMAND_SWITCH_BASE = <<<OET
This PR was submitted for the base_ref branch but it was merged into the %s branch instead (closes #10).
OET;

const COMMAND_SWITCH_BASE_TARGET = <<<OET
New-target: %s/%s (was "%s")
OET;

private $commits = [
Expand Down Expand Up @@ -128,7 +136,8 @@ function (HelperSet $helperSet) {
);

$display = $tester->getDisplay();
$this->assertCommandOutputMatches(self::COMMAND_DISPLAY, $display);

$this->assertCommandOutputMatches([self::COMMAND_DISPLAY, self::COMMAND_DISPLAY_TARGET], $display);
}

public function testMergePullRequestWithNoComments()
Expand Down Expand Up @@ -276,7 +285,14 @@ function (HelperSet $helperSet) {
);

$display = $tester->getDisplay();
$this->assertCommandOutputMatches(sprintf(self::COMMAND_SWITCH_BASE, 'develop'), $display);

$this->assertCommandOutputMatches(
[
sprintf(self::COMMAND_SWITCH_BASE_TARGET, 'gushphp', 'develop', 'base_ref'),
sprintf(self::COMMAND_SWITCH_BASE, 'develop')
],
$display
);
}

public function testMergePullRequestWithFastForward()
Expand Down

0 comments on commit 0ae54b1

Please sign in to comment.