/** * Pushes the deployment build to the temporary git repository. */ public function main() { // Check if all required properties are present. $this->checkRequiredProperties(); // Add the remote for the starterkit if it doesn't exist yet. $remote_branch = 'remotes/' . $this->starterkitRemote . '/' . $this->starterkitBranch; $remote_exists = $this->subsiteRepository->hasRemote($this->starterkitRemote); if (!$remote_exists) { $this->log('Adding remote repository.'); // Only track the given branch, and don't download any tags. $options = ['--no-tags' => TRUE, '-t' => [$this->starterkitBranch]]; $this->subsiteRepository->addRemote($this->starterkitRemote, $this->starterkitRepository, $options); } // Check if the tracking branch exists and create it if it doesn't. try { $this->subsiteRepository->run(array('rev-parse', $remote_branch)); } catch (GitException $e) { $this->log('Adding tracking branch.'); $this->subsiteRepository->remote('set-branches', '--add', $this->starterkitRemote, $this->starterkitBranch); } // Fetch the latest changes. $this->log('Fetching latest changes.'); $this->subsiteRepository->fetch($this->starterkitRemote); // Check if the latest commit on the remote is merged into the current // branch. $this->subsiteRepository->clearOutput(); $latest_commit = (string) $this->subsiteRepository->run(array('rev-parse', $remote_branch)); $merge_base = (string) $this->subsiteRepository->run(array('merge-base @ ' . $remote_branch)); // If the latest commit on the remote is not merged into the current branch, // the repository is not up-to-date. if ($merge_base !== $latest_commit) { throw new \BuildException('The current branch is not up to date with the starterkit.'); } $this->log('The starterkit is up to date.'); }
/** * 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 { // Create App folder mkdir($path, 0755, TRUE); chdir($path); // Clone repo $wrapper = new GitWrapper(); $wrapper->streamOutput(); $wrapper->cloneRepository($this->app->repo, $path); // Checkout correct version. $git = new GitWorkingCopy($wrapper, $this->getSourcePath()); $git->checkout($this->environment->version); } catch (\GitWrapper\GitException $e) { // If exception is because there is no git ref, continue. if (strpos($e->getMessage(), 'error: pathspec') !== 0) { 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(); }
/** * 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(); }
/** * Set up the git repository for our build. * * @param GitWorkingCopy $workingCopy * @param string $url * @param string $branch * @return mixed */ protected function doGitInit(GitWorkingCopy $workingCopy, $url, $branch) { $workingCopy->init(); $workingCopy->remote('add', 'origin', $url); try { $this->output->writeln("Attempting to fetch <path>origin/{$branch}</path>", OutputInterface::VERBOSITY_VERBOSE); $workingCopy->fetch('origin', $branch)->checkout('-f', $branch); } catch (GitException $exception) { $this->output->writeln("Fetch failed, creating new branch instead", OutputInterface::VERBOSITY_VERBOSE); $workingCopy->checkout('--orphan', $branch)->run(['commit', '--allow-empty', '-m', "Branch created by steak"])->push('-u', 'origin', $branch); } return $workingCopy->clearOutput(); }