Gush\Helper\GitHelper::isGitDir PHP Method

isGitDir() public method

Returns whether the current working dir is a Git directory.
public isGitDir ( boolean $requireRoot = true ) : boolean
$requireRoot boolean Require directory is the root of the Git repository, default is true.
return boolean
    public function isGitDir($requireRoot = true)
    {
        $directory = $this->getGitDir();
        if ('' === $directory) {
            return false;
        }
        if ($requireRoot && str_replace('\\', '/', getcwd()) !== $directory) {
            return false;
        }
        return true;
    }

Usage Example

Beispiel #1
0
 /**
  * @runInSeparateProcess
  */
 public function testThrowExceptionForNonGitDir()
 {
     chdir(sys_get_temp_dir());
     $this->setExpectedExceptionRegExp('\\RuntimeException', '#^fatal: Not a git repository \\(or any of the parent directories\\): \\.git$#', 128);
     $this->assertFalse($this->git->isGitDir());
 }