From e349ef1eaf6ee06e09f8d2aecf3db35efbe18bac Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Fri, 23 Nov 2018 21:20:48 +0100 Subject: [PATCH] setup configured git upstream --- src/commands/CodeUpAction.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/commands/CodeUpAction.php b/src/commands/CodeUpAction.php index a02a084..bf7a36f 100644 --- a/src/commands/CodeUpAction.php +++ b/src/commands/CodeUpAction.php @@ -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