diff options
author | Andrew Manning <tamanning@zoho.com> | 2016-05-01 22:29:51 -0400 |
---|---|---|
committer | Andrew Manning <tamanning@zoho.com> | 2016-05-01 22:29:51 -0400 |
commit | c2d15e6c3bd8a29bae89d184a999ddac15fcb807 (patch) | |
tree | 96cbbfa98f131d830fbfd154f82e37383bb37bd8 /library/kzykhys/git/src/PHPGit/Command/CommitCommand.php | |
parent | b1ae4d776c7c093c7f3ff6905e1a5302fbd5e3f6 (diff) | |
download | volse-hubzilla-c2d15e6c3bd8a29bae89d184a999ddac15fcb807.tar.gz volse-hubzilla-c2d15e6c3bd8a29bae89d184a999ddac15fcb807.tar.bz2 volse-hubzilla-c2d15e6c3bd8a29bae89d184a999ddac15fcb807.zip |
New plugin repo is cloned to /store/pluginrepos/REPONAME for analysis
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 |