Checkout a branch or paths to the working tree.
public checkout ( ) : |
||
return |
public function deploy() { // Create the wrapper. $wrapper = new GitWrapper(); $wrapper->streamOutput(); // Iterate through each project. foreach ($this->projects as $name => $project) { // Check out all branches. foreach ($project['branches'] as $branch => $destination) { // Build our git interface. $git = null; if (!is_dir($destination)) { $git = $wrapper->cloneRepository($project['repo'], $destination); } else { $git = new GitWorkingCopy($wrapper, $destination); } // Fetch the latest. $git->fetch('origin'); // Checkout the desired branch. $git->checkout($branch, array('force' => true)); // Reset any local changes. $git->reset(array('hard' => true)); // Pull the latest from the branch. $git->pull('origin', $branch, array('force' => true)); } } }
/** * @param $deployTag * @throws \Exception * @throws GitException */ public function deployToProduction($deployTag) { $oldBranch = $this->getCurrentBranchName(); try { $this->precheck(); $this->wrapper->streamOutput(); $this->git->fetch()->checkout(BranchEnum::PRODUCTION)->reset('--hard')->merge($deployTag)->push(); } catch (GitException $e) { throw $e; } finally { $this->git->checkout($oldBranch); } }
/** * Merge three strings in a specified file. * * @param string $file * The file name in the git repository to which the content is written. * @param string $base * The common base text. * @param string $remote * The first changed text. * @param string $local * The second changed text * * @return string * The merged text. */ protected function mergeFile($file, $base, $remote, $local) { file_put_contents($file, $base); $this->git->add($file); $this->git->commit('Add base.'); if (!in_array('original', $this->git->getBranches()->all())) { $this->git->checkoutNewBranch('original'); } else { $this->git->checkout('original'); $this->git->rebase('master'); } file_put_contents($file, $remote); $this->git->add($file); $this->git->commit('Add remote.'); $this->git->checkout('master'); file_put_contents($file, $local); $this->git->add($file); $this->git->commit('Add local.'); $this->git->merge('original'); return file_get_contents($file); }
/** * Deploy a version to an environment. * * @param $version * A git branch, tag, or sha. */ public function deploy($version) { // Checkout the branch $wrapper = new GitWrapper(); $wrapper->streamOutput(); $git = new GitWorkingCopy($wrapper, $this->getSourcePath()); $git->checkout($version); $git->pull(); // Reload config so any changes get picked up. $this->reloadConfig(); // Run the deploy hooks, if there are any. if (isset($this->config['hooks']['deploy']) && !empty($this->config['hooks']['deploy'])) { chdir($this->getSourcePath()); $process = new Process($this->config['hooks']['deploy']); $process->run(function ($type, $buffer) { if (Process::ERR === $type) { // Error echo $buffer; } else { // OK echo $buffer; } }); } // @TODO: Save the environment // @TODO: Create EnvironmentFactory->save(); // Returning the branch for now. The command is saving the info. return $this->getRepo()->getCurrentBranch(); }
/** * Deploy a version to an environment. * * @param $version * A git branch, tag, or sha. */ public function deploy($version) { // Checkout the branch $wrapper = new GitWrapper(); $wrapper->streamOutput(); $git = new GitWorkingCopy($wrapper, $this->getSourcePath()); $git->checkout($version); $git->pull(); // Reload config so any changes get picked up. $this->reloadConfig(); // Run the deploy hooks chdir($this->getSourcePath()); $process = new Process($this->config['hooks']['deploy']); $process->run(function ($type, $buffer) { if (Process::ERR === $type) { // Error echo $buffer; } else { // OK echo $buffer; } }); // Save new branch to yml $this->director->config['apps'][$this->app]['environments'][$this->name]['git_ref'] = $this->getRepo()->getCurrentBranch(); $this->director->saveData(); }
/** * 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(); }