getCurrentBranch() public method

public getCurrentBranch ( ) : string
return string
 /**
  *
  */
 private function injectBubble($request, $response)
 {
     //NOP if not in browser or if an ajax request or etc
     if (App::runningInConsole() or $request->ajax()) {
         return $response;
     }
     //steps:
     //[1] get current git branch (if possible / appropriate)
     //[2] inject git branch bubble into content of $response
     //[3] return $response
     //[1]--------
     $content = $response->getContent();
     $bubbleText = 'unknown';
     //using sebastian/git
     $git = new Git(base_path());
     try {
         $bubbleText = $git->getCurrentBranch();
     } catch (RuntimeException $exception) {
         //NOP
     }
     /*
     //using kzykhys/git
     $git = new \PHPGit\Git(base_path());
     foreach($git->branch() as $branch)
     {
         if($branch['current'])
         {
             $bubbleText = $branch['name'];
         }
     }
     */
     //[2]--------
     $bubbleHtml = $this->getBubbleHtml($bubbleText);
     //get last </body> or </BODY> and - if present - inject just before it
     //(else simply append to $content)
     $position = strripos($content, '</body>');
     if ($position !== false) {
         $content = substr($content, 0, $position) . $bubbleHtml . substr($content, $position);
     } else {
         $content = $content . $bubbleHtml;
     }
     $response->setContent($content);
     //[3]--------
     return $response;
 }
Example #2
0
 /**
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null|int null or 0 if everything went fine, or an error code
  */
 private function executeHistory(InputInterface $input, OutputInterface $output)
 {
     $git = new Git($input->getOption('git-repository'));
     $currentBranch = $git->getCurrentBranch();
     $revisions = $git->getRevisions();
     $count = [];
     $progressBar = null;
     if ($input->getOption('progress')) {
         $progressBar = new ProgressBar($output, count($revisions));
         $progressBar->start();
     }
     foreach ($revisions as $revision) {
         $git->checkout($revision['sha1']);
         $directories = [];
         foreach ($input->getArgument('values') as $value) {
             $directory = realpath($value);
             if ($directory) {
                 $directories[] = $directory;
             }
         }
         $_count = $this->count($directories, $input->getOption('exclude'), $this->handleCSVOption($input, 'names'), $this->handleCSVOption($input, 'names-exclude'), $input->getOption('count-tests'));
         if ($_count) {
             $_count['commit'] = $revision['sha1'];
             $count[$revision['date']->format(\DateTime::W3C)] = $_count;
         }
         if ($progressBar !== null) {
             $progressBar->advance();
         }
     }
     $git->checkout($currentBranch);
     if ($progressBar !== null) {
         $progressBar->finish();
         $output->writeln('');
     }
     if ($input->getOption('log-csv')) {
         $printer = new History();
         $printer->printResult($input->getOption('log-csv'), $count);
     }
 }
Example #3
0
 /**
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null|int null or 0 if everything went fine, or an error code
  */
 private function executeHistory(InputInterface $input, OutputInterface $output)
 {
     if (!is_dir($input->getOption('git-repository'))) {
         throw new RuntimeException(sprintf('Working directory "%s" does not exist', $input->getOption('git-repository')));
     }
     $git = new Git($input->getOption('git-repository'));
     if (!$git->isWorkingCopyClean()) {
         throw new RuntimeException(sprintf('Working directory "%s" is not clean', $input->getOption('git-repository')));
     }
     $currentBranch = $git->getCurrentBranch();
     $revisions = $git->getRevisions();
     $printer = null;
     $progressBar = null;
     if ($input->getOption('log-csv')) {
         $printer = new History($input->getOption('log-csv'));
     }
     if ($input->getOption('progress')) {
         $progressBar = new ProgressBar($output, count($revisions));
         $progressBar->start();
     }
     foreach ($revisions as $revision) {
         $git->checkout($revision['sha1']);
         $directories = [];
         foreach ($input->getArgument('values') as $value) {
             $directory = realpath($value);
             if ($directory) {
                 $directories[] = $directory;
             }
         }
         $_count = $this->count($directories, $input->getOption('exclude'), $this->handleCSVOption($input, 'names'), $this->handleCSVOption($input, 'names-exclude'), $input->getOption('count-tests'));
         if ($_count) {
             $_count['commit'] = $revision['sha1'];
             $_count['date'] = $revision['date']->format(\DateTime::W3C);
             if ($printer) {
                 $printer->printRow($_count);
             }
         }
         if ($progressBar !== null) {
             $progressBar->advance();
         }
     }
     $git->checkout($currentBranch);
     if ($progressBar !== null) {
         $progressBar->finish();
         $output->writeln('');
     }
 }