config = $config; $this->logger = $logger; } /** * Initialize a new repository * * @return bool */ public function init(): bool { if (!$this->isGitRepository()) { $this->exec('git init'); } return $this->isGitRepository(); } /** * Get the current branch name * * @return string */ public function getCurrentBranchName(): string { if (!$this->isGitRepository()) { return $this->config->get('docname'); } $output = $this->exec('git branch | grep \\\* | cut -d \' \' -f2'); return $output[0]; } /** * Check if repository is initialized * * @return bool */ public function isGitRepository(): bool { return is_dir(PROJECT_ROOT.'/.git') && file_exists(PROJECT_ROOT.'/.git/config'); } /** * Execute a system command * * @param string $cmd * @return array */ protected function exec(string $cmd): array { $output = array(); exec($cmd, $output); return $output; } }