Skip to content

Commit

Permalink
Merge pull request #168 from fortrabbit/fix/support-for-no-repo
Browse files Browse the repository at this point in the history
Add support for no existing repo
  • Loading branch information
pheeque1 authored Apr 19, 2023
2 parents bcf6a48 + 85bbe82 commit e1d4dbc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 2.4.1 - 2023-04-19
- Add support for no existing repo with new git client

## 2.4.0 - 2023-04-17
- Replace `cpliakas/git-wrapper` with `gitonomy/gitlib`
- Allow customising commit message made in `code/up` command
Expand Down
33 changes: 22 additions & 11 deletions src/Services/Git/GitonomyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use fortrabbit\Copy\Exceptions\GitException;
use Gitonomy\Git\Admin;
use Gitonomy\Git\Exception\ProcessException;
use Gitonomy\Git\Exception\ReferenceNotFoundException;
use Gitonomy\Git\Reference\Branch;
use Gitonomy\Git\Repository;
use LogicException;
Expand Down Expand Up @@ -38,11 +39,19 @@ public function pull(string $upstream, string $branch = 'master'): string

public function getLocalHead(): ?string
{
$head = $this->repository->getHead();
if ($head instanceof Branch) {
return $head->getName();
try {
$head = $this->repository->getHead();

if ($head instanceof Branch) {
return $head->getName();
}

return $head->getFullName();
} catch (ReferenceNotFoundException) {
return NULL;
}
return $head->getFullName();

return NULL;
}

public function getLocalBranches(): array
Expand Down Expand Up @@ -72,11 +81,13 @@ public function getRemotes(?string $for = 'push'): array
$remotes = explode(PHP_EOL, rtrim($this->run(GitCommand::REMOTE, ['-v'])));

$map = [];
foreach ($remotes as $mixed) {
[$key, $value] = explode("\t", $mixed);
$map[$key] = strtok($value, " ");
}
$remotes = $map;
foreach ($remotes as $mixed) {
if ($mixed === '') continue;

[$key, $value] = explode("\t", $mixed);
$map[$key] = strtok($value, " ");
}
$remotes = $map;

return $remotes;
}
Expand Down Expand Up @@ -114,7 +125,6 @@ public function addRemote(string $name, ?string $url)
public function setDirectory(string $directory)
{
$this->directory = $directory;
$this->repository = new Repository($directory);
}

public function getDirectory(): string
Expand All @@ -124,7 +134,8 @@ public function getDirectory(): string

public function init()
{
Admin::init($this->directory, $this->repository->isBare());
Admin::init($this->directory, false);
$this->repository = new Repository($this->directory);
}

public function log(...$argsOrOptions): string
Expand Down

0 comments on commit e1d4dbc

Please sign in to comment.