55use App \Contracts \PathsRepository ;
66use App \Factories \ConfigurationFactory ;
77use Illuminate \Support \Collection ;
8- use Illuminate \Support \Str ;
98use Symfony \Component \Process \Process ;
109
1110class GitPathsRepository implements PathsRepository
@@ -32,17 +31,15 @@ public function __construct($path)
3231 */
3332 public function dirty ()
3433 {
35- $ process = tap (new Process (['git ' , 'status ' , '--short ' , '-- ' , '**.php ' ]))->run ();
34+ $ process = tap (new Process (['git ' , 'diff ' , '--name-only ' , ' HEAD ' , '-- ' , '**.php ' ]))->run ();
3635
3736 if (! $ process ->isSuccessful ()) {
3837 abort (1 , 'The [--dirty] option is only available when using Git. ' );
3938 }
4039
4140 $ dirtyFiles = collect (preg_split ('/\R+/ ' , $ process ->getOutput (), flags: PREG_SPLIT_NO_EMPTY ))
42- ->mapWithKeys (fn ($ file ) => [substr ($ file , 3 ) => trim (substr ($ file , 0 , 3 ))])
43- ->reject (fn ($ status ) => $ status === 'D ' )
44- ->map (fn ($ status , $ file ) => $ status === 'R ' ? Str::after ($ file , ' -> ' ) : $ file )
45- ->values ();
41+ ->values ()
42+ ->map (fn ($ s ) => (string ) $ s );
4643
4744 return $ this ->processFileNames ($ dirtyFiles );
4845 }
@@ -83,21 +80,26 @@ public function diff($branch)
8380 */
8481 protected function processFileNames (Collection $ fileNames )
8582 {
83+ $ gitRoot = trim (tap (new Process (['git ' , 'rev-parse ' , '--show-toplevel ' ]))->run ()->getOutput ());
84+
8685 $ processedFileNames = $ fileNames
87- ->map (function ($ file ) {
86+ ->map (function ($ file ) use ($ gitRoot ) {
87+ $ absolutePath = $ gitRoot .DIRECTORY_SEPARATOR .$ file ;
88+
8889 if (PHP_OS_FAMILY === 'Windows ' ) {
89- $ file = str_replace ('/ ' , DIRECTORY_SEPARATOR , $ file );
90+ $ absolutePath = str_replace ('/ ' , DIRECTORY_SEPARATOR , $ absolutePath );
9091 }
9192
92- return $ this -> path . DIRECTORY_SEPARATOR . $ file ;
93+ return $ absolutePath ;
9394 })
9495 ->all ();
9596
9697 $ files = array_values (array_map (function ($ splFile ) {
9798 return $ splFile ->getPathname ();
98- }, iterator_to_array (ConfigurationFactory::finder ()
99- ->in ($ this ->path )
100- ->files ()
99+ }, iterator_to_array (
100+ ConfigurationFactory::finder ()
101+ ->in ($ this ->path )
102+ ->files ()
101103 )));
102104
103105 return array_values (array_intersect ($ files , $ processedFileNames ));
0 commit comments