Skip to content

Commit b783a01

Browse files
Handle empty git repositories gracefully
- getRecentCommits now returns empty array for repos with no commits - getBranches now returns empty array for repos with no commits - Fixes test failures for empty repository tests Co-authored-by: Manuel Kießling <manuel@kiessling.net>
1 parent 928a37e commit b783a01

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/WorkspaceMgmt/Infrastructure/Adapter/GitCliAdapter.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ public function getRecentCommits(string $workspacePath, int $limit = 10): array
243243
$process->setWorkingDirectory($workspacePath);
244244
$process->setTimeout(self::TIMEOUT_SECONDS);
245245

246-
$this->runProcess($process, 'Failed to get recent commits');
246+
$process->run();
247+
248+
// Return empty array if git log fails (e.g., no commits yet)
249+
if (!$process->isSuccessful()) {
250+
return [];
251+
}
247252

248253
$output = $process->getOutput();
249254
if (trim($output) === '') {
@@ -279,7 +284,12 @@ public function getBranches(string $workspacePath): array
279284
$process->setWorkingDirectory($workspacePath);
280285
$process->setTimeout(self::TIMEOUT_SECONDS);
281286

282-
$this->runProcess($process, 'Failed to get branches');
287+
$process->run();
288+
289+
// Return empty array if git branch fails (e.g., no commits yet)
290+
if (!$process->isSuccessful()) {
291+
return [];
292+
}
283293

284294
$output = trim($process->getOutput());
285295
if ($output === '') {

0 commit comments

Comments
 (0)