SebastianBergmann\Git\Git::getCurrentBranch PHP Method

getCurrentBranch() public method

public getCurrentBranch ( ) : string
return string
    public function getCurrentBranch()
    {
        $output = $this->execute('symbolic-ref --short HEAD');
        return $output[0];
    }

Usage Example

 /**
  *
  */
 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;
 }
All Usage Examples Of SebastianBergmann\Git\Git::getCurrentBranch