Skip to content

Commit

Permalink
Merge pull request #20 from erikjwaxx/feature/list-tags
Browse files Browse the repository at this point in the history
Add a method to list tags in a repo
  • Loading branch information
kbjr committed Dec 3, 2013
2 parents b4ea81d + 4e4ff3c commit 6e2d901
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions Git.php
Expand Up @@ -32,16 +32,16 @@ class Git {
* @var string
*/
protected static $bin = '/usr/bin/git';

/**
* Sets git executable path
*
*
* @param string $path executable location
*/
public static function set_bin($path) {
self::$bin = $path;
}

/**
* Gets git executable path
*/
Expand Down Expand Up @@ -173,7 +173,7 @@ public function set_repo_path($repo_path, $create_new = false, $_init = true) {
$this->repo_path = $repo_path;
$this->bare = true;
}
} else {
} else {
if ($create_new) {
$this->repo_path = $repo_path;
if ($_init) {
Expand Down Expand Up @@ -509,6 +509,26 @@ public function add_tag($tag, $message = null) {
return $this->run("tag -a $tag -m $message");
}

/**
* List all the available repository tags.
*
* Optionally, accept a shell wildcard pattern and return only tags matching it.
*
* @access public
* @param string $pattern Shell wildcard pattern to match tags against.
* @return array Available repository tags.
*/
public function list_tags($pattern = null) {
$tagArray = explode("\n", $this->run("tag -l $pattern"));
foreach ($tagArray as $i => &$tag) {
$tag = trim($tag);
if ($tag == '') {
unset($tagArray[$i]);
}
}

return $tagArray;
}

/**
* Push specific branch to a remote
Expand All @@ -522,7 +542,7 @@ public function add_tag($tag, $message = null) {
public function push($remote, $branch) {
return $this->run("push --tags $remote $branch");
}

/**
* Pull specific branch from remote
*
Expand Down Expand Up @@ -563,7 +583,7 @@ public function get_description() {
public function setenv($key, $value) {
$this->envopts[$key] = $value;
}

}

/* End of file */

0 comments on commit 6e2d901

Please sign in to comment.