support for git tags/branches
authorMichael Wallner <mike@php.net>
Fri, 8 May 2015 10:09:03 +0000 (12:09 +0200)
committerMichael Wallner <mike@php.net>
Fri, 8 May 2015 10:09:03 +0000 (12:09 +0200)
src/pharext/Packager.php
src/pharext/Task/GitClone.php

index cd1d43681d2d9a1167615c170365175cc3c5c9b4..c08fce0946abed5ff2ce76bef09de3d32880d6ce 100644 (file)
@@ -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);
                }
index 7b84ca1efa29abe34a543267ec1d436907d1c184..55d759040416fb377aa63dba663f64273e3d0c55 100644 (file)
@@ -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;
        }
 }