aboutsummaryrefslogtreecommitdiffstats
path: root/library/kzykhys/git/src/PHPGit/Command/DescribeCommand.php
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-05-10 12:12:20 +1000
committerredmatrix <git@macgirvin.com>2016-05-10 12:12:20 +1000
commitb7e7ef0bf3ad47729ef45282a92a78f0dc0e3ec4 (patch)
tree2e4f069d66885c5ca5b77154e9dd5a43ec004ff5 /library/kzykhys/git/src/PHPGit/Command/DescribeCommand.php
parentea1173f8f632151d02c71fe6004c6a64d014e80a (diff)
parent0b8a7f1bd03edb2bb18eb050fcb0b482d0e231be (diff)
downloadvolse-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/DescribeCommand.php')
-rw-r--r--library/kzykhys/git/src/PHPGit/Command/DescribeCommand.php90
1 files changed, 90 insertions, 0 deletions
diff --git a/library/kzykhys/git/src/PHPGit/Command/DescribeCommand.php b/library/kzykhys/git/src/PHPGit/Command/DescribeCommand.php
new file mode 100644
index 000000000..affdd009b
--- /dev/null
+++ b/library/kzykhys/git/src/PHPGit/Command/DescribeCommand.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace PHPGit\Command;
+
+use PHPGit\Command;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
+/**
+ * Show the most recent tag that is reachable from a commit - `git describe`
+ *
+ * @author Kazuyuki Hayashi <hayashi@valnur.net>
+ */
+class DescribeCommand extends Command
+{
+
+ /**
+ * Returns the most recent tag that is reachable from a commit
+ *
+ * ``` php
+ * $git = new PHPGit\Git();
+ * $git->setRepository('/path/to/repo');
+ * $git->tag->create('v1.0.0');
+ * $git->commit('Fixes #14');
+ * echo $git->describe('HEAD', ['tags' => true]);
+ * ```
+ *
+ * ##### Output Example
+ *
+ * ```
+ * v1.0.0-1-g7049efc
+ * ```
+ *
+ * ##### Options
+ *
+ * - **all** (_boolean_) Enables matching any known branch, remote-tracking branch, or lightweight tag
+ * - **tags** (_boolean_) Enables matching a lightweight (non-annotated) tag
+ * - **always** (_boolean_) Show uniquely abbreviated commit object as fallback
+ *
+ * @param string $committish [optional] Committish object names to describe.
+ * @param array $options [optional] An array of options {@see DescribeCommand::setDefaultOptions}
+ *
+ * @return string
+ */
+ public function __invoke($committish = null, array $options = array())
+ {
+ $options = $this->resolve($options);
+ $builder = $this->git->getProcessBuilder()
+ ->add('describe');
+
+ $this->addFlags($builder, $options, array());
+
+ if ($committish) {
+ $builder->add($committish);
+ }
+
+ return trim($this->git->run($builder->getProcess()));
+ }
+
+ /**
+ * Equivalent to $git->describe($committish, ['tags' => true]);
+ *
+ * @param string $committish [optional] Committish object names to describe.
+ * @param array $options [optional] An array of options {@see DescribeCommand::setDefaultOptions}
+ *
+ * @return string
+ */
+ public function tags($committish = null, array $options = array())
+ {
+ $options['tags'] = true;
+
+ return $this->__invoke($committish, $options);
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * - **all** (_boolean_) Enables matching any known branch, remote-tracking branch, or lightweight tag
+ * - **tags** (_boolean_) Enables matching a lightweight (non-annotated) tag
+ * - **always** (_boolean_) Show uniquely abbreviated commit object as fallback
+ */
+ public function setDefaultOptions(OptionsResolverInterface $resolver)
+ {
+ $resolver->setDefaults(array(
+ 'all' => false,
+ 'tags' => false,
+ 'always' => false,
+ ));
+ }
+
+}