Skip to content

Commit

Permalink
Fix undefined offset: 1 in "gitRepository" action when GIT repository…
Browse files Browse the repository at this point in the history
… is empty
  • Loading branch information
AdamVyborny committed Jan 9, 2023
1 parent 20466bd commit f99045c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Service/GitRepositoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ public function listRemoteBranches(string $projectPath): array
];
$process = new Process($args, $projectPath);
$process->mustRun();
$branches = (array) explode("\n", trim($process->getOutput()));

if (trim($process->getOutput()) !== '') {
$branches = (array) explode("\n", trim($process->getOutput()));
} else {
return [];
}

return array_map(function ($item) {
[$branchRaw, $comment, $sha, $author, $email, $date] = explode(',', $item);
Expand Down
10 changes: 10 additions & 0 deletions tests/phpunit/Service/GitRepositoryServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public function testClonePrivateRepository(string $url, string $username, string
$this->assertTrue(true);
}

public function testListBranchesEmptyGitProject(): void
{
$gitService = new GitRepositoryService($this->dataDir);
$gitService->clone('https://github.com/keboola/empty-repo-test.git');
$branches = $gitService->listRemoteBranches($this->dataDir . '/dbt-project');

self::assertIsArray($branches);
self::assertEmpty($branches);
}

/**
* @dataProvider privateRepositoryInvalidCredentials
*/
Expand Down

0 comments on commit f99045c

Please sign in to comment.