Skip to content

Commit

Permalink
setup configured git upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Stark committed Nov 23, 2018
1 parent b1b0e8e commit e349ef1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/commands/CodeUpAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,26 @@ public function run(string $config = null)
*/
protected function getUpstream(Git $git): string
{
// Non
// Get configured remote & sshUrl
$upstream = explode('/', $this->config->gitRemote)[0];
$sshUrl = $this->config->sshUrl;

// Nothing found
if (!$remotes = $git->getRemotes()) {
$sshUrl = $this->config->sshUrl;
if ($this->confirm("No remotes configured. Do you want to add '{$sshUrl}'?")) {
return $git->addRemote($sshUrl);
}
}

// There is just one
if (count($remotes) == 1) {
return array_keys($remotes)[0];
// Auto setup
if (!array_key_exists($upstream, $remotes)) {
$git->addRemote($sshUrl);
$remotes = $git->getRemotes();
}

// Use configured remote
$upstream = explode('/', $this->config->gitRemote)[0];
if (in_array($upstream, array_keys($remotes))) {
return $upstream;
// Just one
if (count($remotes) == 1) {
return array_keys($remotes)[0];
}

// Multiple
Expand Down

0 comments on commit e349ef1

Please sign in to comment.