Пример #1
0
 /**
  * @{inheritdoc}
  */
 protected function executeCommandByProject($projectName, ProjectConfiguration $projectConfig, OutputInterface $output)
 {
     $output->writeln(sprintf('<comment>Opens Git gui for the project "<info>%s</info>"</comment>', $projectName));
     if (!is_dir($projectConfig->getLocalGitRepositoryDir())) {
         throw new \RuntimeException(sprintf('The directory "%s" does not exist', $projectConfig->getLocalGitRepositoryDir()));
     }
     $this->getExec()->passthru($this->executable, $projectConfig->getLocalGitRepositoryDir());
 }
Пример #2
0
 /**
  * @{inheritdoc}
  */
 protected function executeCommandByProject($projectName, ProjectConfiguration $projectConfig, OutputInterface $output)
 {
     $output->writeln(sprintf('<comment>Git status for project "<info>%s</info>"</comment>', $projectName));
     if (!is_dir($projectConfig->getLocalGitRepositoryDir())) {
         throw new \RuntimeException(sprintf('The directory "%s" does not exist', $projectConfig->getLocalGitRepositoryDir()));
     }
     $this->getExec()->passthru('git status', $projectConfig->getLocalGitRepositoryDir());
     $output->writeln(strtr(ob_get_clean(), ['up-to-date' => '<info>up-to-date</info>', 'is behind' => '<info>is behind</info>', 'can be fast-forwarded' => '<info>can be fast-forwarded</info>', 'modified:' => '<info>modified:</info>', 'both modified' => '<error>both modified:</error>', 'deleted:' => '<error>deleted:</error>', 'deleted by us' => '<error>deleted by us</error>']));
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 protected function executeCommandByProject($projectName, ProjectConfiguration $projectConfig, OutputInterface $output)
 {
     $output->writeln(sprintf('<comment>Git contributors for project "<info>%s</info>"</comment>', $projectName));
     if (!is_dir($projectConfig->getLocalGitRepositoryDir())) {
         throw new \RuntimeException(sprintf('The directory "%s" does not exist', $projectConfig->getLocalGitRepositoryDir()));
     }
     $output->writeln('repo age: ' . $this->getRepositoryAge($projectConfig->getLocalGitRepositoryDir()));
     $output->writeln('commits: ' . $this->getCommitCount($projectConfig->getLocalGitRepositoryDir()));
     $output->writeln('authors:');
     $output->writeln($this->getListAuthors($projectConfig->getLocalGitRepositoryDir()));
     $output->writeln('');
 }
Пример #4
0
 protected function cloneGitProject($projectName, ProjectConfiguration $config, OutputInterface $output)
 {
     if (is_dir($config->getLocalGitRepositoryDir())) {
         $output->writeln(sprintf('<comment>A project with that name "<info>%s</info>" already exists</comment>', $projectName));
         return;
     }
     $output->writeln(sprintf('<comment>Create git project "<info>%s</info>" in "<info>%s</info>"</comment>', $projectName, $config->getLocalGitRepositoryDir()));
     $this->getExec()->run(strtr('git clone %git_repository_url% %local_git_repository_dir% && cd %local_git_repository_dir% && git checkout %git_target_branch%', ['%local_git_repository_dir%' => $config->getLocalGitRepositoryDir(), '%git_repository_url%' => $config->getGitRepositoryUrl(), '%git_target_branch%' => $config->getGitTargetBranch()]), $output);
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 protected function executeCommandByProject($projectName, ProjectConfiguration $projectConfig, OutputInterface $output)
 {
     $output->writeln(sprintf('<comment>Git %s for project "<info>%s</info>"</comment>', $this->getName(), $projectName));
     if (!is_dir($projectConfig->getLocalGitRepositoryDir())) {
         throw new \RuntimeException(sprintf('The directory "%s" does not exist', $projectConfig->getLocalGitRepositoryDir()));
     }
     if (empty($this->gitCommand)) {
         throw new \LogicException('Git command is empty');
     }
     if ($this->colorsConsoleOutput) {
         ob_start();
     }
     $this->getExec()->passthru(sprintf('git %s', $this->gitCommand), $projectConfig->getLocalGitRepositoryDir());
     if ($this->colorsConsoleOutput) {
         $output->writeln(strtr(ob_get_clean(), ['up-to-date' => '<info>up-to-date</info>', 'is behind' => '<info>is behind</info>', 'can be fast-forwarded' => '<info>can be fast-forwarded</info>', 'modified:' => '<info>modified:</info>', 'both modified' => '<error>both modified:</error>', 'deleted:' => '<error>deleted:</error>', 'deleted by us' => '<error>deleted by us</error>', '-  ' => '<error>- </error>', '+  ' => '<info>+</info>']));
     }
     return $this->getExec()->getLastReturnStatus();
 }
Пример #6
0
 protected function getGiturl(ProjectConfiguration $projectConfig)
 {
     $giturl = $this->getExec()->exec('git config --get remote.' . $this->remote . '.url', $projectConfig->getLocalGitRepositoryDir());
     if ($this->getExec()->getLastReturnStatus() !== 0) {
         throw new \LogicException('Error retrieve git URL');
     }
     if (0 === strpos($giturl, 'git@')) {
         $giturl = str_replace(':', '/', $giturl);
         $giturl = str_replace('git@', 'http://', $giturl);
     }
     if (false !== strpos($giturl, '.git')) {
         $giturl = str_replace('.git', '', $giturl);
     }
     $branchName = null === $this->branchName ? $this->getCurrentBranch($projectConfig) : $this->branchName;
     $giturl .= '/tree/' . $branchName;
     return $giturl;
 }
Пример #7
0
 protected function openProjectWithSublimeText(ProjectConfiguration $projectConfig, OutputInterface $output)
 {
     $projectConfigPath = sprintf('%s/sublimetext/%s.sublime-project', $this->configDir, $projectConfig->getProjectName());
     !$this->logger ?: $this->logger->debug(sprintf('Checks the existence of file %s', $projectConfigPath));
     if (!$this->getLocalFilesystem()->exists($projectConfigPath) || $this->rewritesConfigFile) {
         $configData = ['folders' => [['follow_symlinks' => false, 'name' => $projectConfig->getProjectName(), 'path' => realpath($projectConfig->getLocalGitRepositoryDir())], ['follow_symlinks' => false, 'name' => 'vendor', 'path' => realpath($projectConfig->getLocalVendorDir())]]];
         if ($projectConfig->getLocalAssetsDir()) {
             $configData['folders'][] = ['follow_symlinks' => false, 'name' => 'assets_project', 'path' => realpath($projectConfig->getLocalAssetsDir())];
         }
         foreach ($this->directoriesConfig as $configCommonDirectory) {
             $configData['folders'][] = $configCommonDirectory;
         }
         $content = json_encode($configData, JSON_PRETTY_PRINT);
         !$this->logger ?: $this->logger->debug(sprintf('Dumps project json config into a file "<info>%s</info>".', $projectConfigPath));
         $this->getLocalFilesystem()->dumpFile($projectConfigPath, $content);
     }
     if ('' !== exec('which subl')) {
         $commandLine = 'subl -n ' . $projectConfigPath . (defined('PHP_WINDOWS_VERSION_BUILD') ? '' : ' > `tty`');
         !$this->logger ?: $this->logger->debug(sprintf('Executes command line %s', $commandLine));
         system($commandLine);
     } else {
         $output->writeln('<error><info>subl</info> command not found</error>');
     }
 }
Пример #8
0
 protected function extractCommitedFiles(ProjectConfiguration $projectConfig, $tmpStaging, OutputInterface $output)
 {
     $output->writeln(sprintf('<comment>%s for project "<info>%s</info>"</comment>', 'Extract commited files', $projectConfig->getProjectName()));
     $this->getExec()->exec('git rev-parse --verify HEAD 2> /dev/null', $projectConfig->getLocalGitRepositoryDir());
     // Initial commit: diff against an empty tree object
     $against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
     if ($this->getExec()->getLastReturnStatus() == 0) {
         $against = 'HEAD';
     }
     $files = [];
     // retrieve all files in staging area that are added, modified or renamed but no deletions etc
     $result = $this->getExec()->exec(sprintf('git diff-index --cached --full-index --diff-filter=ACMR %s -- ', $against), $projectConfig->getLocalGitRepositoryDir());
     // copy each committed file in a temporary location
     if ($result) {
         foreach ($result as $data) {
             $parts = explode(' ', preg_replace('/\\s+/i', ' ', $data));
             $sha = $parts[3];
             $filepath = $parts[5];
             if (strpos($filepath, 'vendor/') !== false) {
                 continue;
             }
             if (!preg_match($this->pattern, $filepath)) {
                 continue;
             }
             // Copy contents of staged version of files to temporary staging area
             // because we only want the staged version that will be commited and not
             // the version in the working directory
             $targetFile = sprintf('%s/%s', $tmpStaging, $filepath);
             $this->getLocalFilesystem()->mkdir(dirname($targetFile));
             $this->getExec()->run(strtr('git cat-file blob %sha% > "%file%"', ['%sha%' => $sha, '%dir%' => dirname($targetFile), '%file%' => $targetFile]), $output, $projectConfig->getLocalGitRepositoryDir());
             $files[] = $filepath;
         }
     }
     return $files;
 }
Пример #9
0
 protected function installCommandGitUp(ProjectConfiguration $projectConfig, OutputInterface $output)
 {
     // Il faut utiliser l'option --user pour forcer l'installation en mode user only
     $output->writeln('<error>git up command doesn\'t exist.</error>');
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion('Do you want to install git up? (y/n)', false);
     if (!$helper->ask($this->input, $output, $question)) {
         return;
     }
     if (!$this->commandExist('pip')) {
         $this->getExec()->run('sudo easy_install pip');
     }
     $this->getExec()->run('pip install --user git-up', $output, $projectConfig->getLocalGitRepositoryDir());
     if (0 == $this->getExec()->getLastReturnStatus()) {
         $output->writeln('<comment>Adding a path to the .bashrc file</comment>');
         $output->writeln('export PATH=$PATH:$HOME/.local/bin');
     }
     return $this->getExec()->getLastReturnStatus();
 }