| | if (!is_dir($this->rootPath)) return; |
| | |
| | - // 1. Scan for all valid .git directories first |
| | $found = []; |
| | $glob = glob($this->rootPath . '/*.git'); |
| | |
| | - if ($glob !== false) { |
| | + if ($glob) { |
| | foreach ($glob as $path) { |
| | if (is_dir($path)) { |
| | $name = basename($path, '.git'); |
| | $found[$name] = [ |
| | 'path' => $path, |
| | - 'name' => urldecode($name), // rudimentary decoding |
| | + 'name' => urldecode($name), |
| | 'safe_name' => $name |
| | ]; |
| | } |
| | } |
| | } |
| | |
| | - // 2. Parse order.txt |
| | $orderFile = $this->rootPath . '/order.txt'; |
| | $sortMap = []; |
| | $hidden = []; |
| | |
| | if (file_exists($orderFile)) { |
| | $lines = file($orderFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
| | foreach ($lines as $index => $line) { |
| | - // Clean up artifacts (e.g. "") |
| | $line = trim(preg_replace('/^\\s*/', '', $line)); |
| | if (empty($line)) continue; |
| | |
| | $isHidden = ($line[0] === '-'); |
| | $cleanName = basename($isHidden ? substr($line, 1) : $line, '.git'); |
| | |
| | if ($isHidden) { |
| | $hidden[$cleanName] = true; |
| | } else { |
| | - // Keep track of the explicit order index |
| | $sortMap[$cleanName] = $index; |
| | } |
| | } |
| | } |
| | |
| | - // 3. Filter hidden repositories |
| | $visibleRepos = array_filter($found, function($repo) use ($hidden) { |
| | return !isset($hidden[$repo['safe_name']]); |
| | }); |
| | |
| | - // 4. Sort: Explicit order first, then alphabetical for the rest |
| | uasort($visibleRepos, function($a, $b) use ($sortMap) { |
| | $idxA = $sortMap[$a['safe_name']] ?? PHP_INT_MAX; |
 |
| | }); |
| | |
| | - // 5. Execute callback |
| | foreach ($visibleRepos as $repo) { |
| | $callback($repo); |