Skip to content

Commit

Permalink
fix-rename-status (#173)
Browse files Browse the repository at this point in the history
* fix-rename-status

* code-style

* fix cs
  • Loading branch information
yunwuxin authored Dec 1, 2020
1 parent c47655a commit 60a7824
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
3 changes: 1 addition & 2 deletions ecs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
parameters:
sets:
- 'clean-code'
- 'psr2'
- 'psr12'
paths:
- 'src'
Expand All @@ -18,7 +17,7 @@ parameters:
services:
PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer:
syntax: short
Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer:
Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer:
max_line_length: 100 # default: 120
break_long_lines: true # default: true
inline_short_lines: false # default: true
17 changes: 9 additions & 8 deletions src/GitElephant/Status/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ public function copied(): \PhpCollection\Sequence
private function parseOutputLines(array $lines): void
{
foreach ($lines as $line) {
preg_match('/([MADRCU\? ])?([MADRCU\? ])?\ "?(\S+)"? ?( -> )?(\S+)?/', $line, $matches);
$x = isset($matches[1]) ? $matches[1] : null;
$y = isset($matches[2]) ? $matches[2] : null;
$file = isset($matches[3]) ? $matches[3] : null;
$renamedFile = isset($matches[4]) ? $matches[4] : null;
$this->files[] = StatusFile::create($x, $y, $file, $renamedFile);
$matches = $this->splitStatusLine($line);
if ($matches) {
$x = isset($matches[1]) ? $matches[1] : null;
$y = isset($matches[2]) ? $matches[2] : null;
$file = isset($matches[3]) ? $matches[3] : null;
$renamedFile = isset($matches[5]) ? $matches[5] : null;
$this->files[] = StatusFile::create($x, $y, $file, $renamedFile);
}
}
}

Expand All @@ -172,8 +174,7 @@ private function parseOutputLines(array $lines): void
*/
protected function splitStatusLine(string $line)
{
preg_match('/([MADRCU\?])?([MADRCU\?])?\ "?(\S+)"? ?( -> )?(\S+)?/', $line, $matches);

preg_match('/^([MADRCU\? ])?([MADRCU\? ])?\ "?([^"]+?)"?( -> "?([^"]+?)"?)?$/', $line, $matches);
return $matches;
}

Expand Down
10 changes: 10 additions & 0 deletions src/GitElephant/Status/StatusFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ public function getName(): string
return $this->name;
}

/**
* Get the renamed
*
* @return string|null
*/
public function getRenamed(): ?string
{
return $this->renamed;
}

/**
* Get the status of the index
*
Expand Down
2 changes: 2 additions & 0 deletions tests/GitElephant/Status/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public function testRenamed(): void
$s = $this->repository->getStatus();
$this->assertCount(1, $s->renamed());
$this->assertTrue($s->renamed()->first()->get()->isRenamed());
$this->assertEquals('test', $s->renamed()->first()->get()->getName());
$this->assertEquals('test2', $s->renamed()->first()->get()->getRenamed());
$this->assertInterfaces($s->renamed());
foreach ($s->renamed() as $file) {
$this->assertInstanceOf('GitElephant\Status\StatusFile', $file);
Expand Down

0 comments on commit 60a7824

Please sign in to comment.