Browse Source

Se agrego un merge para evitar error de git

Se agregaron comentarios
gabriel 7 years ago
parent
commit
8487a8783f
2 changed files with 38 additions and 20 deletions
  1. 22 10
      tools/src/Command/TagModulesCommand.php
  2. 16 10
      tools/src/ComposerRequireCommand.php

+ 22 - 10
tools/src/Command/TagModulesCommand.php

@@ -64,12 +64,15 @@ class TagModulesCommand extends Command
                     $branchs = $git->branch(['all' => true]);
                     $findBranch = false;
                     $branchRemote = null;
+                    $branchOrigen = null;
                     // verifico si el branch a crear ya existe
 		    foreach ($branchs as $branch) {
+                        if ($branch['current']) {
+                            $branchOrigen = $branch['name'];
+                        }
                         if ($branch['name'] == $version) {
                             $findBranch = true;
                             $branchRemote = $branch['name'];
-                            break;
                         }
                     }
                     if (!$findBranch) {
@@ -77,17 +80,25 @@ class TagModulesCommand extends Command
                         $output->writeln('Creando la rama ' . $version);
                         $git->branch->create($version);
                     }
+                    $git->add('composer.json');
+                    $git->add('composer.lock');
+
+		    $output->writeln('Commit de los composer');
+                    $command = $cd_path . "; git commit -am 'Composer para la version " . $version . " y el tag " . $tag . "'";
+                    $output->writeln('\t' . $command);
+                    shell_exec($command);
+		    
 		    // cambio a la rama de la version y agrego los archivos modificados
                     $output->writeln('Checkout de la rama ' . $version);
                     $git->checkout($version);
-                    $git->add('composer.json');
-                    $git->add('composer.lock');
 
-                    $output->writeln('Push de los composer');
-                    $output->writeln('\t' . $cd_path . "; git commit -am 'Composer para la version " . $version . " y el tag " . $tag . "'");
-                    shell_exec($cd_path . "; git commit -am 'Composer para la version " . $version . " y el tag " . $tag . "'");
-                    $output->writeln('\t' . "; git push " . $optionRemoteGit . " " . $version);
-                    shell_exec($cd_path . "; git push " . $optionRemoteGit . " " . $version );
+                    $output->writeln('Merge entre la rama ' . $version . ' y ' . $branchOrigen);
+                    $git->merge($branchOrigen, 'Merge entre la rama ' . $version . ' y ' . $branchOrigen, ['strategy' => 'ours']);
+		    
+                    $output->writeln('Push de la rama ' . $version);
+		    $command = $cd_path . "; git push " . $optionRemoteGit . " " . $version;
+		    $output->writeln('\t' . $command);
+                    shell_exec($command);
                     // estoy creando un tag
                     $tags = $git->tag();
                     if (!in_array($tag, $tags)) {
@@ -103,9 +114,10 @@ class TagModulesCommand extends Command
                     }
                     // ejecuto el comando git
                     $output->writeln('Push de la rama.');
-                    $output->writeln('\t' . "; git push " . $optionRemoteGit . " --tags ");
+		    $command = $cd_path . "; git push " . $optionRemoteGit . " --tags ";
+                    $output->writeln('\t' . $command);
 		    // tengo que hacer el  --tags para que pase todos los tags
-                    shell_exec($cd_path . "; git push " . $optionRemoteGit . " --tags ");
+                    shell_exec($command);
                 } catch (GitException $e) {
                     $output->writeln("SE PRODUJO UN ERROR EN " . $sec);
                     shell_exec($cd_path . "; git reset ");

+ 16 - 10
tools/src/ComposerRequireCommand.php

@@ -40,18 +40,21 @@ class ComposerRequireCommand extends Command
         foreach ($content as $sec => $conf) {
             $composer_file = $sec . "/composer.json";
             if (file_exists($composer_file)) {
+                $output->writeln("----------------------------------------------------------------------");
                 $output->writeln($sec);
                 $composer_data = json_decode(file_get_contents($composer_file), true);
 		try {
                     foreach (array("require", "require-dev") as $k) {
 		        $output->writeln('Ejecutando:');
-		        $output->writeln('\tgit stash; git checkout master; git pull origin master');
-                        shell_exec('cd ' . $sec . '; git stash; git checkout master; git pull origin master');
+		        $command = 'cd ' . $sec . '; git stash; git fetch; git checkout master; git pull origin master';
+		        $output->writeln("\t" . $command);
+                        shell_exec($command);
                         if (strlen($pull) > 0) {
-		            $output->writeln('\tgit pull origin ' . $pull);
-                            shell_exec('cd ' . $sec . '; git pull origin ' . $pull);
+		            $command = 'cd ' . $sec . '; git pull origin ' . $pull);
+		            $output->writeln("\t" . $command);
+                            shell_exec($command);
                         }
-		        $output->writeln('\tReemplazo composer.json');
+		        $output->writeln("\t" . 'Reemplazo composer.json');
                         foreach ($composer_data[$k] as $package => $version) {
                             if (strpos($packages, "*") !== false) {
                                 $preg = "|^" . str_replace("*", "[^\b]*", $packages) . "$|";
@@ -59,7 +62,7 @@ class ComposerRequireCommand extends Command
                                     $composer_data[$k][$package] = (string)$new_version;
                                     $output->writeln("\t\t" . $package . " = " . $new_version);
                                 }
-                            } else {
+			    } else {
                                 if (strcmp($packages, $package) === 0) {
                                     $composer_data[$k][$package] = (string)$new_version;
 				    $output->writeln("\t\t" . $package . " = " . $new_version);
@@ -70,13 +73,15 @@ class ComposerRequireCommand extends Command
                     file_put_contents($composer_file, json_encode($composer_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
 		    if ($dockerCompose) {
 		        $output->writeln('Composer update');
-		        $output->writeln('\tdocker-compose exec ' . $sec . ' bin/composer-update.sh');
-                        shell_exec('docker-compose exec ' . $sec . ' bin/composer-update.sh');
+		        $command = 'docker-compose exec ' . $sec . ' bin/composer-update.sh';
+		        $output->writeln("\t" . $command);
+                        shell_exec($command);
                     }
 		} catch (Throwable $t) {
 		    $output->writeln('Se produjo un error. Reestableciendo datos.');
-		    $output->writeln('\tcd ' . $sec . '; git reset');
-                    $shell_exec('cd ' . $sec . '; git reset');
+		    $command = 'cd ' . $sec . '; git reset');
+		    $output->writeln("\t" . $command);
+                    $shell_exec($command);
 		}
             } else {
                 $output->writeln($sec . " no composer.json found");
@@ -84,3 +89,4 @@ class ComposerRequireCommand extends Command
         }
     }
 }
+