Add Git\Repository::createArchive

This commit is contained in:
Jérôme Tamarelle
2012-07-14 12:41:57 +02:00
parent 4cef2830be
commit a4cff9b831

View File

@@ -472,6 +472,37 @@ class Repository
return $data;
}
/**
* Extract the tree hash for a given branch or tree reference
*
* @param string $branch
* @return string
*/
public function getBranchTree($branch)
{
$hash = $this->getClient()->run($this, "log --pretty='%T' --max-count=1 $refspec");
$hash = trim($hash, "\r\n ");
return $hash ? : false;
}
/**
* Create a TAR or ZIP archive of a git tree
*
* @param string $tree Tree-ish reference
* @param string $output Output File name
* @param string $format Archive format
*/
public function createArchive($tree, $output, $format = 'zip')
{
if (!file_exists($dir = dirname($output)) && !@mkdir($dir, 0777, true)) {
throw new \RuntimeException("Unable to create directory $dir");
}
$this->getClient()->run($this, "archive --format=$format --output=$output $tree");
}
/**
* Get the Tree for the provided folder
*