コード例 #1
0
ファイル: GitRepository.php プロジェクト: sp4ceb4r/php-git
 /**
  * Process existing git configuration files. Files are read
  * from the system level to the local level, overwriting options
  * as we go.
  *
  * @return void
  */
 protected function processGitConfig()
 {
     $configs = ["/etc/gitconfig", realpath("~/.gitconfig"), "{$this->git->getProjectDirectory()}/.git/config"];
     foreach ($configs as $index => $file) {
         if (!is_file($file)) {
             continue;
         }
         if ($index === 2) {
             $this->initialized = true;
         }
         foreach (parse_ini_file($file, true) as $section => $values) {
             if (substr($section, 0, 6) === 'remote') {
                 $remote = substr($section, 7);
                 if (!isset($this->config['remotes'])) {
                     $this->config['remotes'] = [];
                 }
                 $this->config['remotes'][$remote] = ['name' => $remote, 'url' => $values['url']];
             } elseif (substr($section, 0, 6) === 'branch') {
                 $this->config['branches'][] = substr($section, 7);
             } elseif ($section === 'user') {
                 $this->config['user'] = $values;
             }
         }
     }
 }