Skip to content

Commit 6e2d901

Browse files
committed
Merge pull request kbjr#20 from erikjwaxx/feature/list-tags
Add a method to list tags in a repo
2 parents b4ea81d + 4e4ff3c commit 6e2d901

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

Git.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ class Git {
3232
* @var string
3333
*/
3434
protected static $bin = '/usr/bin/git';
35-
35+
3636
/**
3737
* Sets git executable path
38-
*
38+
*
3939
* @param string $path executable location
4040
*/
4141
public static function set_bin($path) {
4242
self::$bin = $path;
4343
}
44-
44+
4545
/**
4646
* Gets git executable path
4747
*/
@@ -173,7 +173,7 @@ public function set_repo_path($repo_path, $create_new = false, $_init = true) {
173173
$this->repo_path = $repo_path;
174174
$this->bare = true;
175175
}
176-
} else {
176+
} else {
177177
if ($create_new) {
178178
$this->repo_path = $repo_path;
179179
if ($_init) {
@@ -509,6 +509,26 @@ public function add_tag($tag, $message = null) {
509509
return $this->run("tag -a $tag -m $message");
510510
}
511511

512+
/**
513+
* List all the available repository tags.
514+
*
515+
* Optionally, accept a shell wildcard pattern and return only tags matching it.
516+
*
517+
* @access public
518+
* @param string $pattern Shell wildcard pattern to match tags against.
519+
* @return array Available repository tags.
520+
*/
521+
public function list_tags($pattern = null) {
522+
$tagArray = explode("\n", $this->run("tag -l $pattern"));
523+
foreach ($tagArray as $i => &$tag) {
524+
$tag = trim($tag);
525+
if ($tag == '') {
526+
unset($tagArray[$i]);
527+
}
528+
}
529+
530+
return $tagArray;
531+
}
512532

513533
/**
514534
* Push specific branch to a remote
@@ -522,7 +542,7 @@ public function add_tag($tag, $message = null) {
522542
public function push($remote, $branch) {
523543
return $this->run("push --tags $remote $branch");
524544
}
525-
545+
526546
/**
527547
* Pull specific branch from remote
528548
*
@@ -563,7 +583,7 @@ public function get_description() {
563583
public function setenv($key, $value) {
564584
$this->envopts[$key] = $value;
565585
}
566-
586+
567587
}
568588

569589
/* End of file */

0 commit comments

Comments
 (0)