/** * Clones the source code for this project. */ public function init($path) { $wrapper = new GitWrapper(); $wrapper->streamOutput(); $wrapper->clone($this->environment->source_url, $path); chdir($path); $wrapper->git('branch'); $wrapper->git('status'); $this->loadConfig(); // Save config to director apps registry. // @TODO: Improve config saving system. $this->director->config['apps'][$this->app]['environments'][$this->name]['config'] = $this->getConfig(); $this->director->saveData(); // Run the build hooks if (!empty($this->config['hooks']['build'])) { chdir($this->getSourcePath()); $process = new Process($this->config['hooks']['build']); $process->run(function ($type, $buffer) { if (Process::ERR === $type) { echo $buffer; } else { echo $buffer; } }); } }
/** * Clones the source code for this project. */ public function init($path = null) { $path = is_null($path) ? $this->environment->path : $path; // Check if clone already exists at this path. If so we can safely skip. if (file_exists($path)) { $wrapper = new GitWrapper(); try { $working_copy = new GitWorkingCopy($wrapper, $path); $output = $working_copy->remote('-v'); } catch (GitException $e) { throw new \Exception('Path already exists.'); } // if repo exists in the remotes already, this working copy is ok. if (strpos(strtolower($output), strtolower($this->app->repo)) !== false) { return true; } else { throw new Exception('Git clone already exists at that path, but it is not for this app.'); } } try { mkdir($path, 0755, TRUE); chdir($path); $options = array(); if ($this->environment->version) { $options['branch'] = $this->environment->version; } $wrapper = new GitWrapper(); $wrapper->streamOutput(); $wrapper->cloneRepository($this->app->repo, $path, $options); } catch (\GitWrapper\GitException $e) { return false; } chdir($path); $wrapper->git('branch'); $wrapper->git('status'); $this->loadConfig(); // Run the build hooks if (!empty($this->config['hooks']['build'])) { chdir($this->getSourcePath()); $process = new Process($this->config['hooks']['build']); $process->run(function ($type, $buffer) { if (Process::ERR === $type) { echo $buffer; } else { echo $buffer; } }); } return $this->writeConfig(); }
/** * @group functional */ public function testTag() { $wrapper = new GitWrapper(); $output = explode("\n", trim($wrapper->git('tag -l', __DIR__ . '/..'))); rsort($output); $this->assertTrue(version_compare($output[0], Version::VERSION, '==')); }
/** * Clones the source code for this project. */ public function init($path) { $wrapper = new GitWrapper(); $wrapper->streamOutput(); $wrapper->clone($this->app->source_url, $path, array('bare' => TRUE)); chdir($path); $wrapper->git('branch'); }
/** * Executes a bad command. * * @param bool $catch_exception * Whether to catch the exception to continue script execution, defaults * to false. */ public function runBadCommand($catch_exception = false) { try { $this->_wrapper->git('a-bad-command'); } catch (GitException $e) { if (!$catch_exception) { throw $e; } } }
/** * @param $repository * @return array */ public function getRemoteTags($repository) { $refs = []; $result = $this->wrapper->git('ls-remote ' . $repository); $rows = explode(PHP_EOL, trim($result)); foreach ($rows as $row) { list($hash, $ref) = explode("\t", $row, 2); $this->assignHashByRef($refs, $ref, $hash); } return $refs; }
/** * Update the vulnerability database (returning any output from the git wrapper) * * @throws \Exception */ public function updateDatabase() { $wrapper = new GitWrapper(); $repositoryPath = __DIR__ . self::REPOSITORY_PATH; if (!file_exists($repositoryPath . '/.git')) { $git = $wrapper->clone(self::REPOSITORY_URL, $repositoryPath); $git->getOutput(); } else { $wrapper->git('pull', $repositoryPath); } $this->replaceJsonFiles(); }
/** * Execute the console command. * * @return mixed */ public function handle() { $currentUser = get_current_user(); $privateKey = php_uname('s') == 'Darwin' ? realpath("/Users/{$currentUser}/.ssh/id_rsa") : realpath("/home/{$currentUser}/.ssh/id_rsa"); $blog = base_path('resources/blog/'); $git = new GitWrapper(); $git->setPrivateKey($privateKey); if (!file_exists($blog)) { $git->cloneRepository(config('blog.repository'), $blog); } $git->git('pull origin master', $blog); }
protected function execute(InputInterface $input, OutputInterface $output) { // App $app_name = $input->getArgument('app'); if (empty($app_name)) { $helper = $this->getHelper('question'); $question = new ChoiceQuestion('Which app? ', array_keys($this->director->config['apps']), 0); $app_name = $helper->ask($input, $output, $question); } $app = $this->director->getApp($app_name); // Environment $env_name = $input->getArgument('environment'); if (empty($env_name)) { $helper = $this->getHelper('question'); $question = new ChoiceQuestion('Which environment? ', array_keys($app->environments), 0); $env_name = $helper->ask($input, $output, $question); } $environment = $app->getEnvironment($env_name); $output->writeln('<info>PATH:</info> ' . $environment->getSourcePath()); $output->writeln('<info>BRANCH:</info> ' . $environment->getRepo()->getCurrentBranch()); // Look for .director.yml $config = $environment->getConfig(); if (empty($config)) { $output->writeln('<error>CONFIG:</error> .director.yml not found at ' . $environment->getSourcePath()); } else { $output->writeln('<info>CONFIG:</info> Loaded .director.yml'); } // Show git status $status = $environment->getRepo()->getStatus(); if (!empty($status)) { $wrapper = new GitWrapper(); $wrapper->streamOutput(); chdir($environment->getSourcePath()); $wrapper->git('status'); } // Save to yml $this->director->config['apps'][$app_name]['environments'][$env_name]['config'] = $environment->getConfig(); $this->director->config['apps'][$app_name]['environments'][$env_name]['git_ref'] = $environment->getRepo()->getCurrentBranch(); $this->director->saveData(); $output->writeln("Saved environment details."); // Look for services if (isset($environment->config['services']) && is_array($environment->config['services'])) { foreach ($environment->config['services'] as $service => $type) { $serviceFactory = $this->director->getService($service); if ($serviceFactory) { $output->writeln("<info>SERVICE:</info> {$service}: {$serviceFactory->galaxy_role}"); } else { $output->writeln("<error>SERVICE:</error> {$service}: not found. Use service:add to fix."); $output->writeln("Looking for available {$service} {$type}"); } } } }
/** * Clones the source code for this project. */ public function init($path = NULL) { $path = is_null($path) ? $this->environment->path : $path; // Check if clone already exists at this path. If so we can safely skip. if (file_exists($path)) { $wrapper = new GitWrapper(); $working_copy = new GitWorkingCopy($wrapper, $path); $output = $working_copy->remote('-v'); if (strpos($output, $this->app->repo) !== FALSE) { return TRUE; } else { return FALSE; } } try { $wrapper = new GitWrapper(); $wrapper->streamOutput(); $wrapper->clone($this->app->repo, $path); } catch (\GitWrapper\GitException $e) { return FALSE; } chdir($path); $wrapper->git('branch'); $wrapper->git('status'); $this->loadConfig(); // Run the build hooks if (!empty($this->config['hooks']['build'])) { chdir($this->getSourcePath()); $process = new Process($this->config['hooks']['build']); $process->run(function ($type, $buffer) { if (Process::ERR === $type) { echo $buffer; } else { echo $buffer; } }); } return $this->writeConfig(); }
/** * Returns the output of a `git status -s` command. * * @return string * * @throws \GitWrapper\GitException */ public function getStatus() { return $this->wrapper->git('status -s', $this->directory); }
/** * Returns Git's "user.name" configuration. * * @return string * * @throws \GitWrapper\GitException; */ public function getGitUsername() { return rtrim($this->gitWrapper->git('config --get --global user.name')); }
private function createAndDownloadFromGit(bool $upload) { try { $gitWrapper = new GitWrapper(); if (substr($this->workbenchSettings->requested["type"]['valore'], -7) != 'package') { $gitWorkingCopy = $gitWrapper->init(\Padosoft\Workbench\Parameters\Dir::adjustPath($this->workbenchSettings->requested['dir']['valore'] . $this->workbenchSettings->requested['domain']['valore'] . "/www", [])); } if (substr($this->workbenchSettings->requested["type"]['valore'], -7) == 'package') { $gitWorkingCopy = $gitWrapper->init(\Padosoft\Workbench\Parameters\Dir::adjustPath($this->workbenchSettings->requested['dir']['valore'] . $this->workbenchSettings->requested['domain']['valore'], [])); } //$gitWorkingCopy=$gitWrapper->init($this->workbenchSettings->requested['dir']['valore'].$this->workbenchSettings->requested['domain']['valore'],[]); $gitWrapper->git("config --global user.name " . $this->workbenchSettings->requested['user']['valore']); $gitWrapper->git("config --global user.email " . $this->workbenchSettings->requested['email']['valore']); $gitWrapper->git("config --global user.password " . $this->workbenchSettings->requested['password']['valore']); $gitWorkingCopy->add('.'); switch ($this->workbenchSettings->requested['type']['valore']) { case Parameters\Type::AGNOSTIC_PACKAGE: $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@github.com/padosoft/" . Config::get('workbench.type_repository.agnostic_package') . ".git"); $this->info("Downloading skeleton agnostic package..."); break; case Parameters\Type::LARAVEL_PACKAGE: $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@github.com/padosoft/" . Config::get('workbench.type_repository.laravel_package') . ".git"); $this->info("Downloading skeleton laravel package..."); break; case Parameters\Type::LARAVEL: $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@github.com/padosoft/" . Config::get('workbench.type_repository.laravel') . ".git"); $this->info("Downloading skeleton laravel project..."); break; case Parameters\Type::NORMAL: $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@github.com/padosoft/" . Config::get('workbench.type_repository.normal') . ".git"); //$this->info("Downloading skeleton normal project..."); break; } if ($this->workbenchSettings->requested['gitaction']['valore'] == Parameters\GitAction::PULL) { $this->info("Donwloading repo..."); $gitWorkingCopy->removeRemote('origin'); $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@" . $this->workbenchSettings->requested["git"]["valore"] . ".com/" . $this->workbenchSettings->requested['organization']['valore'] . "/" . $this->workbenchSettings->requested['packagename']['valore'] . ".git"); } if ($this->workbenchSettings->requested['type']['valore'] != Parameters\Type::NORMAL) { $gitWorkingCopy->pull('origin', 'master'); $this->info("Download complete."); } if ($upload && $this->workbenchSettings->requested['gitaction']['valore'] == Parameters\GitAction::PUSH) { $gitWorkingCopy->removeRemote('origin'); $extension = $this->workbenchSettings->requested["git"]["valore"] == Parameters\Git::BITBUCKET ? "org" : "com"; $gitWorkingCopy->addRemote('origin', "https://" . $this->workbenchSettings->requested['user']['valore'] . ":" . $this->workbenchSettings->requested['password']['valore'] . "@" . $this->workbenchSettings->requested["git"]["valore"] . "." . $extension . "/" . $this->workbenchSettings->requested['organization']['valore'] . "/" . $this->workbenchSettings->requested['packagename']['valore'] . ".git"); $this->substitute(); $gitWorkingCopy->add('.'); $gitWorkingCopy->commit("Substitute"); $this->info("Uploading repo..."); $gitWorkingCopy->push('origin', 'master'); $this->info("Upload complete"); } $dir = \Padosoft\Workbench\Parameters\Dir::adjustPath(__DIR__) . 'config/pre-commit'; if (!File::exists($dir)) { $this->error('File ' . $dir . ' not exist'); exit; } if (substr($this->workbenchSettings->requested["type"]['valore'], -7) != 'package') { File::copy($dir, \Padosoft\Workbench\Parameters\Dir::adjustPath($this->workbenchSettings->requested["dir"]['valore'] . $this->workbenchSettings->requested["domain"]['valore']) . 'www/.git/hooks/pre-commit'); } if (substr($this->workbenchSettings->requested["type"]['valore'], -7) == 'package') { File::copy($dir, \Padosoft\Workbench\Parameters\Dir::adjustPath($this->workbenchSettings->requested["dir"]['valore'] . $this->workbenchSettings->requested["domain"]['valore']) . '.git/hooks/pre-commit'); } } catch (\Exception $ex) { $this->error($ex->getMessage()); exit; } return true; }