public function setGitDir($dir, $check = true)
    {
        if (!is_string($dir)) {
            throw new InvalidArgumentException('string', 0);
        }

        if ($check && !realpath($dir)) {
            throw new Exception("Directory $dir does not exist");
        }
        $this->gitDir = $dir;
        $this->command->chdir($dir);
        return $this;
    }