diff options
author | Wave <wave72@users.noreply.github.com> | 2016-07-22 10:55:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-22 10:55:02 +0200 |
commit | 744ad84714fe0f7a3d90250a4ff02dc4327b9061 (patch) | |
tree | 595fb74ec9ea0bc7130d18bd7993d719a222d343 /library/kzykhys/git/src/PHPGit/Command/RmCommand.php | |
parent | c38c79d71c8ef70ef649f83e322f1984b75ee2dd (diff) | |
parent | 7d897a3f03bd57ed556433eb84a41963ba44e02e (diff) | |
download | volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.tar.gz volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.tar.bz2 volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.zip |
Merge pull request #6 from redmatrix/dev
Dev
Diffstat (limited to 'library/kzykhys/git/src/PHPGit/Command/RmCommand.php')
-rw-r--r-- | library/kzykhys/git/src/PHPGit/Command/RmCommand.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/library/kzykhys/git/src/PHPGit/Command/RmCommand.php b/library/kzykhys/git/src/PHPGit/Command/RmCommand.php new file mode 100644 index 000000000..d6da31230 --- /dev/null +++ b/library/kzykhys/git/src/PHPGit/Command/RmCommand.php @@ -0,0 +1,97 @@ +<?php + +namespace PHPGit\Command; + +use PHPGit\Command; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; + +/** + * Remove files from the working tree and from the index - `git rm` + * + * @author Kazuyuki Hayashi + */ +class RmCommand extends Command +{ + + /** + * Remove files from the working tree and from the index + * + * ``` php + * $git = new PHPGit\Git(); + * $git->setRepository('/path/to/repo'); + * $git->rm('CHANGELOG-1.0-1.1.txt', ['force' => true]); + * ``` + * + * ##### Options + * + * - **force** (_boolean_) Override the up-to-date check + * - **cached** (_boolean_) Unstage and remove paths only from the index + * - **recursive** (_boolean_) Allow recursive removal when a leading directory name is given + * + * @param string|array|\Traversable $file Files to remove. Fileglobs (e.g. *.c) can be given to remove all matching files. + * @param array $options [optional] An array of options {@see RmCommand::setDefaultOptions} + * + * @return bool + */ + public function __invoke($file, array $options = array()) + { + $options = $this->resolve($options); + $builder = $this->git->getProcessBuilder() + ->add('rm'); + + $this->addFlags($builder, $options, array('force', 'cached')); + + if ($options['recursive']) { + $builder->add('-r'); + } + + if (!is_array($file) && !($file instanceof \Traversable)) { + $file = array($file); + } + + foreach ($file as $value) { + $builder->add($value); + } + + $this->git->run($builder->getProcess()); + + return true; + } + + /** + * Equivalent to $git->rm($file, ['cached' => true]); + * + * ##### Options + * + * - **force** (_boolean_) Override the up-to-date check + * - **recursive** (_boolean_) Allow recursive removal when a leading directory name is given + * + * @param string|array|\Traversable $file Files to remove. Fileglobs (e.g. *.c) can be given to remove all matching files. + * @param array $options [optional] An array of options {@see RmCommand::setDefaultOptions} + * + * @return bool + */ + public function cached($file, array $options = array()) + { + $options['cached'] = true; + + return $this->__invoke($file, $options); + } + + /** + * {@inheritdoc} + * + * - **force** (_boolean_) Override the up-to-date check + * - **cached** (_boolean_) Unstage and remove paths only from the index + * - **recursive** (_boolean_) Allow recursive removal when a leading directory name is given + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'force' => false, + 'cached' => false, + 'recursive' => false + )); + } + +}
\ No newline at end of file |