Skip to content

Commit

Permalink
Merge 7a4a886 into f226bcc
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Aug 4, 2022
2 parents f226bcc + 7a4a886 commit 7f56326
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1480,9 +1480,11 @@ protected function handleIndividualUpdates($data, $lockdata, $cdata, $one_pr_per
if (!$old_item_is_branch && !$new_item_is_branch && !$is_an_actual_upgrade) {
throw new NotUpdatedException('The new version is lower than the installed version');
}
$this->log(sprintf('Changing branch because of an unexpected update result. We expected the branch name to be %s but instead we are now switching to %s.', $branch_name, $new_branch_name));
$this->execCommand('git checkout -b ' . $new_branch_name, false);
$branch_name = $new_branch_name;
if ($branch_name !== $new_branch_name) {
$this->log(sprintf('Changing branch because of an unexpected update result. We expected the branch name to be %s but instead we are now switching to %s.', $branch_name, $new_branch_name));
$this->execCommand('git checkout -b ' . $new_branch_name, false);
$branch_name = $new_branch_name;
}
// Check if this new branch name has a pr up-to-date.
if (array_key_exists($branch_name, $prs_named)) {
if (!$default_base) {
Expand Down
24 changes: 24 additions & 0 deletions test/integration/BranchPrefixOnePerUnexpectedUpdateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace eiriksm\CosyComposerTest\integration;

/**
* Test for branch prefix with one_per option set.
*
* Plus if the dependency was updated to something else than we expect it. Then let's use the same expected branch then
* as well.
*/
class BranchPrefixOnePerUnexpectedUpdateTest extends ComposerUpdateIntegrationBase
{
protected $packageForUpdateOutput = 'psr/log';
protected $packageVersionForFromUpdateOutput = '1.0.0';
protected $packageVersionForToUpdateOutput = '1.1.3';
protected $composerAssetFiles = 'composerbranch.one_per';
protected $checkPrUrl = true;

public function testBranchPrefixUsedAndOnePer()
{
$this->runtestExpectedOutput();
self::assertEquals('my_prefixviolinistpsrlog', $this->prParams["head"]);
}
}

0 comments on commit 7f56326

Please sign in to comment.