Skip to content

Commit bea4e1e

Browse files
authored
Merge pull request #9 from olivertappin/hotfix/8
Remove need for grep -P flag when filtering diff lines
2 parents 31d172a + abd21e2 commit bea4e1e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/PhpcsDiff.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,26 @@ protected function getChangedFiles()
248248
protected function getChangedLinesPerFile(array $files)
249249
{
250250
$extract = [];
251-
$pattern = '@@ -[0-9]+(?:,[0-9]+)? \+([0-9]+)(?:,([0-9]+))? @@';
251+
$pattern = [
252+
'basic' => '^@@ (.*) @@',
253+
'specific' => '@@ -[0-9]+(?:,[0-9]+)? \+([0-9]+)(?:,([0-9]+))? @@',
254+
];
252255

253256
foreach ($files as $file => $data) {
254257
$command = 'git diff -U0 ' . $this->baseBranch . ' ' . $this->currentBranch . ' ' . $file .
255-
' | grep -P ' . escapeshellarg($pattern);
258+
' | grep -E ' . escapeshellarg($pattern['basic']);
259+
256260
$lineDiff = shell_exec($command);
257261
$lines = array_filter(explode(PHP_EOL, $lineDiff));
258262
$linesChanged = [];
259263

260264
foreach ($lines as $line) {
261-
preg_match('/' . $pattern . '/', $line, $matches);
265+
preg_match('/' . $pattern['specific'] . '/', $line, $matches);
266+
267+
// If there were no specific matches, skip this line
268+
if ([] === $matches) {
269+
continue;
270+
}
262271

263272
$start = $end = (int)$matches[1];
264273

0 commit comments

Comments
 (0)