/** * */ 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; }
/** * @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(); $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(''); } }
public function testCheckout() { $git = new Git('/var/www/dashboard-server-package/data/testrepo/dashboard'); $git->pull(); }
private function getReporter() { if ($this->diff) { list($commitA, $commitB) = explode('...', $this->diff, 2); $git = new Git(getcwd()); $diffParser = new Parser(); $diff = $diffParser->parse($git->getDiff($commitA, $commitB)); return new Reporter\DiffFilter($this->getContainer()->get('reporter'), $diff); } return $this->getContainer()->get('reporter'); }