From c2d15e6c3bd8a29bae89d184a999ddac15fcb807 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sun, 1 May 2016 22:29:51 -0400 Subject: New plugin repo is cloned to /store/pluginrepos/REPONAME for analysis --- .../git/src/PHPGit/Command/CheckoutCommand.php | 145 +++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 library/kzykhys/git/src/PHPGit/Command/CheckoutCommand.php (limited to 'library/kzykhys/git/src/PHPGit/Command/CheckoutCommand.php') diff --git a/library/kzykhys/git/src/PHPGit/Command/CheckoutCommand.php b/library/kzykhys/git/src/PHPGit/Command/CheckoutCommand.php new file mode 100644 index 000000000..caddf07bd --- /dev/null +++ b/library/kzykhys/git/src/PHPGit/Command/CheckoutCommand.php @@ -0,0 +1,145 @@ + + */ +class CheckoutCommand extends Command +{ + + /** + * Switches branches by updating the index, working tree, and HEAD to reflect the specified branch or commit + * + * ``` php + * $git = new PHPGit\Git(); + * $git->setRepository('/path/to/repo'); + * $git->checkout('develop'); + * ``` + * + * ##### Options + * + * - **force** (_boolean_) Proceed even if the index or the working tree differs from HEAD + * - **merge** (_boolean_) Merges local modification + * + * @param string $branch Branch to checkout + * @param array $options [optional] An array of options {@see CheckoutCommand::setDefaultOptions} + * + * @throws GitException + * @return bool + */ + public function __invoke($branch, array $options = array()) + { + $options = $this->resolve($options); + $builder = $this->git->getProcessBuilder() + ->add('checkout'); + + $this->addFlags($builder, $options, array('force', 'merge')); + + $builder->add($branch); + $this->git->run($builder->getProcess()); + + return true; + } + + /** + * Create a new branch and checkout + * + * ``` php + * $git = new PHPGit\Git(); + * $git->setRepository('/path/to/repo'); + * $git->checkout->create('patch-1'); + * $git->checkout->create('patch-2', 'develop'); + * ``` + * + * ##### Options + * + * - **force** (_boolean_) Proceed even if the index or the working tree differs from HEAD + * + * @param string $branch Branch to checkout + * @param string $startPoint The name of a commit at which to start the new branch + * @param array $options [optional] An array of options {@see CheckoutCommand::setDefaultOptions} + * + * @throws GitException + * @return bool + */ + public function create($branch, $startPoint = null, array $options = array()) + { + $options = $this->resolve($options); + $builder = $this->git->getProcessBuilder() + ->add('checkout') + ->add('-b'); + + $this->addFlags($builder, $options, array('force', 'merge')); + + $builder->add($branch); + + if ($startPoint) { + $builder->add($startPoint); + } + + $this->git->run($builder->getProcess()); + + return true; + } + + /** + * Create a new orphan branch, named , started from and switch to it + * + * ``` php + * $git = new PHPGit\Git(); + * $git->setRepository('/path/to/repo'); + * $git->checkout->orphan('gh-pages'); + * ``` + * + * ##### Options + * + * - **force** (_boolean_) Proceed even if the index or the working tree differs from HEAD + * + * @param string $branch Branch to checkout + * @param string $startPoint [optional] The name of a commit at which to start the new branch + * @param array $options [optional] An array of options {@see CheckoutCommand::setDefaultOptions} + * + * @throws GitException + * @return bool + */ + public function orphan($branch, $startPoint = null, array $options = array()) + { + $options = $this->resolve($options); + $builder = $this->git->getProcessBuilder() + ->add('checkout'); + + $this->addFlags($builder, $options, array('force', 'merge')); + + $builder->add('--orphan')->add($branch); + + if ($startPoint) { + $builder->add($startPoint); + } + + $this->git->run($builder->getProcess()); + + return true; + } + + /** + * {@inheritdoc} + * + * - **force** (_boolean_) Proceed even if the index or the working tree differs from HEAD + * - **merge** (_boolean_) Merges local modification + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'force' => false, + 'merge' => false + )); + } + +} \ No newline at end of file -- cgit v1.2.3