|
@@ -0,0 +1,52 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace FD3\Command;
|
|
|
+
|
|
|
+use Symfony\Component\Console\Command\Command;
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
+use Symfony\Component\Console\Input\InputArgument;
|
|
|
+use Symfony\Component\Console\Input\InputOption;
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
+
|
|
|
+use PHPGit\Git;
|
|
|
+use PHPGit\Exception\GitException;
|
|
|
+
|
|
|
+class MakeVersionCommand extends Command
|
|
|
+{
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ $this
|
|
|
+ ->setName('make:version')
|
|
|
+ ->setDescription('Create a branch with version name in a git repository')
|
|
|
+ ->setHelp('This command allows you to create a branch with version name in a git repository')
|
|
|
+ ->addArgument('ini_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
|
|
|
+ ->addArgument('version', InputArgument::REQUIRED, 'Version number. e.g. v0.0')
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
+ {
|
|
|
+ $file = $input->getArgument("ini_file");
|
|
|
+ $version = $input->getArgument("version");
|
|
|
+
|
|
|
+ $realpath = realpath($file);
|
|
|
+ $dirname = dirname($realpath);
|
|
|
+ if (!chdir($dirname)) {
|
|
|
+ throw new \Exception("Can't change working directory to ".$dirname);
|
|
|
+ }
|
|
|
+
|
|
|
+ $content = parse_ini_file($realpath, true);
|
|
|
+ foreach ($content as $sec => $conf) {
|
|
|
+ try {
|
|
|
+ $git = new Git();
|
|
|
+ $git_path = $dirname.'/'.$sec;
|
|
|
+ $git->setRepository($git_path);
|
|
|
+ $git->branch->create($version);
|
|
|
+ $git->checkout($version);
|
|
|
+ } catch (GitException $e) {
|
|
|
+ $output->write($e->getMessage());
|
|
|
+ throw $e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|