@@ -248,35 +248,32 @@ protected function getChangedFiles()
248248 protected function getChangedLinesPerFile (array $ files )
249249 {
250250 $ extract = [];
251- $ pattern = '@@ -[0-9]+(?:,[0-9]+)? \+([0-9]+)(,([0-9]+))? @@ ' ;
251+ $ pattern = '@@ -[0-9]+(?:,[0-9]+)? \+([0-9]+)(?: ,([0-9]+))? @@ ' ;
252252
253253 foreach ($ files as $ file => $ data ) {
254- $ lineDiff = shell_exec (
255- 'git diff -U0 ' . $ this ->baseBranch . ' ' . $ this ->currentBranch . ' ' . $ file .
256- ' | grep -E \'' . $ pattern . '\''
257- );
258-
254+ $ command = 'git diff -U0 ' . $ this ->baseBranch . ' ' . $ this ->currentBranch . ' ' . $ file .
255+ ' | grep -P ' . escapeshellarg ($ pattern );
256+ $ lineDiff = shell_exec ($ command );
259257 $ lines = array_filter (explode (PHP_EOL , $ lineDiff ));
260258 $ linesChanged = [];
261259
262260 foreach ($ lines as $ line ) {
263261 preg_match ('/ ' . $ pattern . '/ ' , $ line , $ matches );
264- $ start = (int )$ matches [1 ];
265262
266- if (!isset ($ matches [2 ])) {
267- // We only have a single line that was changed
268- $ linesChanged [] = $ start ;
269- continue ;
270- }
263+ $ start = $ end = (int )$ matches [1 ];
271264
272- // Multiple lines were changed, so we need to create a range
273- $ length = (int )$ matches [2 ];
274- $ end = $ start + $ length ;
265+ // Multiple lines were changed, so we need to calculate the end line
266+ if (isset ($ matches [2 ])) {
267+ $ length = (int )$ matches [2 ];
268+ $ end = $ start + $ length - 1 ;
269+ }
275270
276- array_merge ($ linesChanged , range ($ start , $ end ));
271+ foreach (range ($ start , $ end ) as $ l ) {
272+ $ linesChanged [$ l ] = null ;
273+ }
277274 }
278275
279- $ extract [$ file ] = $ linesChanged ;
276+ $ extract [$ file ] = array_keys ( $ linesChanged) ;
280277 }
281278
282279 return $ extract ;
0 commit comments