/** * Test GitHelper::getConfig(). */ public function testGetConfig() { $email = '*****@*****.**'; $repository = $this->getRepositoryDir(); chdir($repository); shell_exec('git config user.email ' . $email); $config = $this->gitHelper->getConfig('user.email', $repository); $this->assertEquals($email, $config); }
/** * Ensure there are appropriate Git remotes in the repository. * * @param string $dir * @param string $url */ public function ensureGitRemote($dir, $url) { if (!file_exists($dir . '/.git')) { throw new \InvalidArgumentException('The directory is not a Git repository'); } $gitHelper = new GitHelper(); $gitHelper->ensureInstalled(); $gitHelper->setDefaultRepositoryDir($dir); $currentUrl = $gitHelper->getConfig("remote." . $this->config->get('detection.git_remote_name') . ".url", $dir); if (!$currentUrl) { $gitHelper->execute(['remote', 'add', $this->config->get('detection.git_remote_name'), $url], $dir, true); } elseif ($currentUrl != $url) { $gitHelper->execute(['remote', 'set-url', $this->config->get('detection.git_remote_name'), $url], $dir, true); } // Add an origin remote too. if ($this->config->get('detection.git_remote_name') !== 'origin' && !$gitHelper->getConfig("remote.origin.url", $dir)) { $gitHelper->execute(['remote', 'add', 'origin', $url]); } }
/** * @param string $dir * * @throws \RuntimeException * If the directory is not a clone of a Platform.sh Git repository. * * @return string|false * The project ID, or false if it cannot be determined. */ protected function getProjectIdFromGit($dir) { if (!file_exists("{$dir}/.git")) { throw new \RuntimeException('The directory is not a Git repository'); } $gitHelper = new GitHelper(); $gitHelper->ensureInstalled(); $originUrl = $gitHelper->getConfig("remote.origin.url", $dir); if (!$originUrl) { throw new \RuntimeException("Git remote 'origin' not found"); } if (!preg_match('/^([a-z][a-z0-9]{12})@git\\.[a-z\\-]+\\.platform\\.sh:\\1\\.git$/', $originUrl, $matches)) { throw new \RuntimeException("The Git remote 'origin' is not a Platform.sh URL"); } return $matches[1]; }
/** * Test GitHelper::getConfig(). */ public function testGetConfig() { $config = $this->gitHelper->getConfig('user.email'); $this->assertEquals('*****@*****.**', $config); }
/** * Ensure there are appropriate Git remotes in the repository. * * @param string $dir * @param string $url */ public function ensureGitRemote($dir, $url) { if (!file_exists("{$dir}/.git")) { throw new \InvalidArgumentException('The directory is not a Git repository'); } $gitHelper = new GitHelper(); $gitHelper->ensureInstalled(); $gitHelper->setDefaultRepositoryDir($dir); $platformUrl = $gitHelper->getConfig("remote.platform.url", $dir); if (!$platformUrl) { $gitHelper->execute(array('remote', 'add', 'platform', $url), $dir, true); } elseif ($platformUrl != $url) { $gitHelper->execute(array('remote', 'set-url', 'platform', $url), $dir, true); } // Add an origin remote too. if (!$gitHelper->getConfig("remote.origin.url", $dir)) { $gitHelper->execute(array('remote', 'add', 'origin', $url)); } }