diff options
author | redmatrix <git@macgirvin.com> | 2016-05-10 12:12:20 +1000 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-05-10 12:12:20 +1000 |
commit | b7e7ef0bf3ad47729ef45282a92a78f0dc0e3ec4 (patch) | |
tree | 2e4f069d66885c5ca5b77154e9dd5a43ec004ff5 /library/kzykhys/git/src/PHPGit/Command/AddCommand.php | |
parent | ea1173f8f632151d02c71fe6004c6a64d014e80a (diff) | |
parent | 0b8a7f1bd03edb2bb18eb050fcb0b482d0e231be (diff) | |
download | volse-hubzilla-b7e7ef0bf3ad47729ef45282a92a78f0dc0e3ec4.tar.gz volse-hubzilla-b7e7ef0bf3ad47729ef45282a92a78f0dc0e3ec4.tar.bz2 volse-hubzilla-b7e7ef0bf3ad47729ef45282a92a78f0dc0e3ec4.zip |
Merge pull request #372 from anaqreon/plugin-repo
Manage addon git repositories via the admin plugins page
Diffstat (limited to 'library/kzykhys/git/src/PHPGit/Command/AddCommand.php')
-rw-r--r-- | library/kzykhys/git/src/PHPGit/Command/AddCommand.php | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/library/kzykhys/git/src/PHPGit/Command/AddCommand.php b/library/kzykhys/git/src/PHPGit/Command/AddCommand.php new file mode 100644 index 000000000..c035b2412 --- /dev/null +++ b/library/kzykhys/git/src/PHPGit/Command/AddCommand.php @@ -0,0 +1,75 @@ +<?php + +namespace PHPGit\Command; + +use PHPGit\Command; +use PHPGit\Exception\GitException; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; + +/** + * Add file contents to the index - `git add` + * + * @author Kazuyuki Hayashi <hayashi@valnur.net> + */ +class AddCommand extends Command +{ + + /** + * Add file contents to the index + * + * ``` php + * $git = new PHPGit\Git(); + * $git->setRepository('/path/to/repo'); + * $git->add('file.txt'); + * $git->add('file.txt', ['force' => false, 'ignore-errors' => false); + * ``` + * + * ##### Options + * + * - **force** (_boolean_) Allow adding otherwise ignored files + * - **ignore-errors** (_boolean_) Do not abort the operation + * + * @param string|array|\Traversable $file Files to add content from + * @param array $options [optional] An array of options {@see AddCommand::setDefaultOptions} + * + * @throws GitException + * @return bool + */ + public function __invoke($file, array $options = array()) + { + $options = $this->resolve($options); + $builder = $this->git->getProcessBuilder() + ->add('add'); + + $this->addFlags($builder, $options); + + if (!is_array($file) && !($file instanceof \Traversable)) { + $file = array($file); + } + + foreach ($file as $value) { + $builder->add($value); + } + + $this->git->run($builder->getProcess()); + + return true; + } + + /** + * {@inheritdoc} + * + * - **force** (_boolean_) Allow adding otherwise ignored files + * - **ignore-errors** (_boolean_) Do not abort the operation + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + //'dry-run' => false, + 'force' => false, + 'ignore-errors' => false, + //'ignore-missing' => false, + )); + } + +}
\ No newline at end of file |