From: Michael Wallner Date: Fri, 8 May 2015 10:09:03 +0000 (+0200) Subject: support for git tags/branches X-Git-Tag: v4.0.0~12 X-Git-Url: https://git.m6w6.name/?p=pharext%2Fpharext;a=commitdiff_plain;h=19af093853775f7cf8c423053806581be61f3cf4 support for git tags/branches --- diff --git a/src/pharext/Packager.php b/src/pharext/Packager.php index cd1d436..c08fce0 100644 --- a/src/pharext/Packager.php +++ b/src/pharext/Packager.php @@ -45,6 +45,8 @@ class Packager implements Command CliArgs::REQUIRED|CliArgs::SINGLE|CliArgs::REQARG], ["g", "git", "Use `git ls-tree` to determine file list", CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG], + ["b", "branch", "Checkout this tag/branch", + CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::REQARG], ["p", "pecl", "Use PECL package.xml to determine file list, name and release", CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG], ["d", "dest", "Destination directory", @@ -142,7 +144,7 @@ class Packager implements Command */ private function download($source) { if ($this->args->git) { - $task = new Task\GitClone($source); + $task = new Task\GitClone($source, $this->args->branch); } else { /* print newline only once */ $done = false; @@ -192,7 +194,7 @@ class Packager implements Command * @return string local source directory */ private function localize($source) { - if (!stream_is_local($source)) { + if (!stream_is_local($source) || ($this->args->git && isset($this->args->branch))) { $source = $this->download($source); $this->cleanup[] = new Task\Cleanup($source); } diff --git a/src/pharext/Task/GitClone.php b/src/pharext/Task/GitClone.php index 7b84ca1..55d7590 100644 --- a/src/pharext/Task/GitClone.php +++ b/src/pharext/Task/GitClone.php @@ -15,12 +15,18 @@ class GitClone implements Task * @var string */ private $source; + + /** + * @var string + */ + private $branch; /** * @param string $source git repo location */ - public function __construct($source) { + public function __construct($source, $branch = null) { $this->source = $source; + $this->branch = $branch; } /** @@ -33,7 +39,11 @@ class GitClone implements Task } $local = new Tempdir("gitclone"); $cmd = new ExecCmd("git", $verbose); - $cmd->run(["clone", $this->source, $local]); + if (strlen($this->branch)) { + $cmd->run(["clone", "--depth", 1, "--branch", $this->branch, $this->source, $local]); + } else { + $cmd->run(["clone", $this->source, $local]); + } return $local; } }