Przeglądaj źródła

fix get:source command

Guillermo Espinoza 6 lat temu
rodzic
commit
4d72465a23
1 zmienionych plików z 18 dodań i 11 usunięć
  1. 18 11
      tools/src/GetSource.php

+ 18 - 11
tools/src/GetSource.php

@@ -57,14 +57,15 @@ class GetSource extends Command
             }
             $git->setRepository($git_path);
 
+            $remoteName = $input->getOption("remote-name");
             try {
-                $git->remote->rm($input->getOption("remote-name"));
+                $git->remote->rm($remoteName);
             } catch (GitException $e) {
-                $output->writeln("<error>" . $e->getMessage() . "</error>");
+                // $output->writeln("<error>" . $e->getMessage() . "</error>");
             }
-            $git->remote->add($input->getOption("remote-name"), $url);
+            $git->remote->add($remoteName, $url);
             try {
-                $git->fetch($input->getOption("remote-name"));
+                $git->fetch($remoteName);
             } catch (GitException $e) {
                 $output->writeln("<error>" . $e->getMessage() . "</error>");
             }
@@ -75,18 +76,24 @@ class GetSource extends Command
             if (!empty($branch_from_options)) {
                 $git->checkout($branch_from_options);
                 $conf["branch"] = $branch_from_options;
-            } else if (strtolower($conf["branch"]) != "master"){
+            } else if (strtolower($conf["branch"]) != "master") {
                 try {
-                    $git->checkout->create($conf["branch"]);
+                    $tags = $git->tag();
+                    if (in_array($conf["branch"], $tags)) {
+                        $git->checkout($conf["branch"]);
+                    } else {
+                        $git->checkout->create($conf["branch"]);
+                        $git->merge("origin/" . $conf["branch"]);
+                    }
                 } catch (GitException $e) {
                     $output->writeln($e->getTraceAsString());
+
                     die;
                 }
-                $git->merge("origin/" . $conf["branch"]);
             }
 
-            if (isset($branches["remotes/" . $input->getOption("remote-name") . "/" . $conf["branch"]])) {
-                $git->merge($input->getOption("remote-name") . "/" . $conf["branch"]);
+            if (isset($branches["remotes/" . $remoteName . "/" . $conf["branch"]])) {
+                $git->merge($remoteName . "/" . $conf["branch"]);
             }
 
             $status = $git->status();
@@ -96,10 +103,10 @@ class GetSource extends Command
                     $output->writeln("\t" . $change["file"] . " is not commited");
                 }
             } else if ($input->getOption("push")) {
-                $git->push($input->getOption("remote-name"), $conf["branch"]);
+                $git->push($remoteName, $conf["branch"]);
 
                 foreach ($git->tag() as $tag) {
-                    $git->push($input->getOption("remote-name"), $tag, array('force' => true));
+                    $git->push($remoteName, $tag, array('force' => true));
                 }
             }
         }