File tree Expand file tree Collapse file tree 2 files changed +8
-18
lines changed Expand file tree Collapse file tree 2 files changed +8
-18
lines changed Original file line number Diff line number Diff line change @@ -422,30 +422,19 @@ public function getDiff($revisions)
422422 /**
423423 * Returns the size of repository, in kilobytes.
424424 *
425- * @throws RuntimeException An error occurred while computing size
426- *
427425 * @return int A sum, in kilobytes
428426 */
429427 public function getSize ()
430428 {
431- $ process = new Process (['du ' , '-skc ' , $ this ->gitDir ]);
432- $ process ->run ();
433-
434- if (!preg_match ('/(\d+)\s+total$/ ' , trim ($ process ->getOutput ()), $ vars )) {
435- $ message = sprintf ("Unable to parse process output \ncommand: %s \noutput: %s " , $ process ->getCommandLine (), $ process ->getOutput ());
436-
437- if (null !== $ this ->logger ) {
438- $ this ->logger ->error ($ message );
429+ $ totalBytes = 0 ;
430+ $ path = realpath ($ this ->gitDir );
431+ if ($ path && file_exists ($ path )) {
432+ foreach (new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ path , \FilesystemIterator::SKIP_DOTS )) as $ object ) {
433+ $ totalBytes += $ object ->getSize ();
439434 }
440-
441- if (true === $ this ->debug ) {
442- throw new RuntimeException ('unable to parse repository size output ' );
443- }
444-
445- return ;
446435 }
447436
448- return $ vars [ 1 ] ;
437+ return ( int ) ( $ totalBytes / 1000 + 0.5 ) ;
449438 }
450439
451440 /**
Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ public function testGetBlob_WithExisting_Works($repository)
3535 public function testGetSize ($ repository )
3636 {
3737 $ size = $ repository ->getSize ();
38- $ this ->assertGreaterThan (70 , $ size , 'Repository is greater than 70KB ' );
38+ $ this ->assertGreaterThanOrEqual (69 , $ size , 'Repository is at least 69KB ' );
39+ $ this ->assertLessThan (80 , $ size , 'Repository is less than 80KB ' );
3940 }
4041
4142 public function testIsBare ()
You can’t perform that action at this time.
0 commit comments