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/CommitCommand.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/CommitCommand.php')
-rw-r--r-- | library/kzykhys/git/src/PHPGit/Command/CommitCommand.php | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/library/kzykhys/git/src/PHPGit/Command/CommitCommand.php b/library/kzykhys/git/src/PHPGit/Command/CommitCommand.php new file mode 100644 index 000000000..a4f2bdd95 --- /dev/null +++ b/library/kzykhys/git/src/PHPGit/Command/CommitCommand.php @@ -0,0 +1,87 @@ +<?php + +namespace PHPGit\Command; + +use PHPGit\Command; +use PHPGit\Exception\GitException; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; + +/** + * Record changes to the repository - `git commit` + * + * @author Kazuyuki Hayashi <hayashi@valnur.net> + */ +class CommitCommand extends Command +{ + + /** + * Record changes to the repository + * + * ``` php + * $git = new PHPGit\Git(); + * $git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo'); + * $git->setRepository('/path/to/repo'); + * $git->add('README.md'); + * $git->commit('Fixes README.md'); + * ``` + * + * ##### Options + * + * - **all** (_boolean_) Stage files that have been modified and deleted + * - **reuse-message** (_string_) Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit + * - **squash** (_string_) Construct a commit message for use with rebase --autosquash + * - **author** (_string_) Override the commit author + * - **date** (_string_) Override the author date used in the commit + * - **cleanup** (_string_) Can be one of verbatim, whitespace, strip, and default + * - **amend** (_boolean_) Used to amend the tip of the current branch + * + * @param string $message Use the given <$msg> as the commit message + * @param array $options [optional] An array of options {@see CloneCommand::setDefaultOptions} + * + * @throws GitException + * @return bool + */ + public function __invoke($message, array $options = array()) + { + $options = $this->resolve($options); + $builder = $this->git->getProcessBuilder() + ->add('commit') + ->add('-m')->add($message); + + $this->addFlags($builder, $options, array('all', 'amend')); + $this->addValues($builder, $options, array('reuse-message', 'squash', 'author', 'date', 'cleanup')); + + $this->git->run($builder->getProcess()); + + return true; + } + + /** + * {@inheritdoc} + * + * - **all** (_boolean_) Stage files that have been modified and deleted + * - **reuse-message** (_string_) Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit + * - **squash** (_string_) Construct a commit message for use with rebase --autosquash + * - **author** (_string_) Override the commit author + * - **date** (_string_) Override the author date used in the commit + * - **cleanup** (_string_) Can be one of verbatim, whitespace, strip, and default + * - **amend** (_boolean_) Used to amend the tip of the current branch + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'all' => false, + 'reuse-message' => null, + 'squash' => null, + 'author' => null, + 'date' => null, + 'cleanup' => null, + 'amend' => false + )); + + $resolver->setAllowedValues(array( + 'cleanup' => array(null, 'default', 'verbatim', 'whitespace', 'strip') + )); + } + +}
\ No newline at end of file |