Skip to content

Commit

Permalink
Ensure git cherry pick parser handler file renames (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdekker committed Aug 1, 2023
1 parent bba0dd0 commit 20d7cc6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Service/Git/CherryPick/GitCherryPickParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public function parse(string $output): CherryPickResult
return new CherryPickResult(true);
}

$result = preg_match_all('/CONFLICT\s+\(\S+\):\s+(\S+)/', $output, $matches);
if ($result === false || $result === 0) {
// no conflicts found
return new CherryPickResult(false);
if (preg_match_all('/CONFLICT\s+\(\S+\):\s+\S+\s+renamed to\s+(\S+)/', $output, $matches) > 0) {
return new CherryPickResult(false, $matches[1]);
}

return new CherryPickResult(false, $matches[1]);
if (preg_match_all('/CONFLICT\s+\(\S+\):\s+(\S+)/', $output, $matches) > 0) {
return new CherryPickResult(false, $matches[1]);
}

return new CherryPickResult(false);
}
}
11 changes: 11 additions & 0 deletions tests/Unit/Service/Git/CherryPick/GitCherryPickParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ public function testParseWithNoCherryPick(): void
static::assertSame([], $result->conflicts);
}

public function testParseWithRename(): void
{
$data = "some random text\n";
$data .= " CONFLICT (rename/delete): src/Tests/Unit/AbstractTest.php renamed to src/Tests/Unit/AbstractTestCase.php in c61a64dc1de.";
$data .= "some random text\n";

$result = $this->parser->parse($data);
static::assertFalse($result->completed);
static::assertSame(['src/Tests/Unit/AbstractTestCase.php'], $result->conflicts);
}

public function testParseWithConflicts(): void
{
$data = "some random text\n";
Expand Down

0 comments on commit 20d7cc6

Please sign in to comment.