Checks if given directory is a git repository
    :param path: path to check
    :return: True if it's a git repo and False otherwise
345523
def is_git_directory(path='.'):
    
    try:
        dulwich.repo.Repo.discover(path)
    except dulwich.errors.NotGitRepository:
        return False

    return True
680587
def _assert_path_is_dir(self, dir_path):
        
        if not os.path.isdir(dir_path):
            raise django.core.management.base.CommandError(
                'Invalid dir path. path="{}"'.format(dir_path)
            )
1154306
function(path) {

        var _this = this,
            target = PATH.resolve(this.root, this.target, path),
            repo = joinUrlPath(this.url, path);

        return QFS.exists(target)
            .then(function(exists) {

                var cmd = exists?
                        _this.getUpdateCmd(repo, target) :
                        _this.getInitialCheckoutCmd(repo, target),
                    d = Q.defer();

                _this.log(cmd);

                CP.exec(cmd, function(err, stdout, stderr) {
                    stdout && _this.log(stdout);
                    stderr && _this.log(stderr);

                    if (err) return d.reject(err);

                    _this.lastRunTime = Date.now();
                    d.resolve();
                });

                return d.promise;

            });

    }
1037365
def get_repo_content(path):
    
    path = Path(path)

    if zipfile.is_zipfile(str(path)):
        with zipfile.ZipFile(str(path)) as zz:
            filelist = [info.filename for info in zz.infolist()]
        iszip = True
    else:
        iszip = False
        filelist = [str(f) for f in path.glob('**/*') if f.is_file()]
    return namedtuple('repocontent', ['iszip', 'filelist'])(iszip, filelist)
466118
def fetch_git_sha(path, head=None):
    
    if not head:
        head_path = os.path.join(path, '.git', 'HEAD')
        if not os.path.exists(head_path):
            raise InvalidGitRepository(
                'Cannot identify HEAD for git repository at %s' % (path,))

        with open(head_path, 'r') as fp:
            head = text_type(fp.read()).strip()

        if head.startswith('ref: '):
            head = head[5:]
            revision_file = os.path.join(
                path, '.git', *head.split('/')
            )
        else:
            return head
    else:
        revision_file = os.path.join(path, '.git', 'refs', 'heads', head)

    if not os.path.exists(revision_file):
        if not os.path.exists(os.path.join(path, '.git')):
            raise InvalidGitRepository(
                '%s does not seem to be the root of a git repository' % (path,))

        # Check for our .git/packed-refs' file since a `git gc` may have run
        # https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery
        packed_file = os.path.join(path, '.git', 'packed-refs')
        if os.path.exists(packed_file):
            with open(packed_file) as fh:
                for line in fh:
                    line = line.rstrip()
                    if line and line[:1] not in ('#', '^'):
                        try:
                            revision, ref = line.split(' ', 1)
                        except ValueError:
                            continue
                        if ref == head:
                            return text_type(revision)

        raise InvalidGitRepository(
            'Unable to find ref to head "%s" in repository' % (head,))

    with open(revision_file) as fh:
        return text_type(fh.read()).strip()
241470
def check_for_local_repos(repo):
    
    repos_dict = Repo().default_repository()
    if repo in repos_dict:
        repo_url = repos_dict[repo]
        if repo_url.startswith("file:///"):
            return True
857995
def isfile(self, path, follow_symlinks=True):
        
        return self._is_of_type(path, S_IFREG, follow_symlinks)
378854
protected function isRequiredRepository($path, $url)
    {
        if ($this->isMultiRepository() && $this->isRepositoryCloned($path)) {
            $this->process->execute(sprintf('git config --get remote.origin.url'), $output, $path);
            return $url == trim($output);
        }
        return true; //empty directory
    }
1331159
def absolute_git_root_dir(fpath=""):
    
    if len(fpath) == 0:
        dirname_str = os.getcwd()
    else:
        dirname_str = os.path.dirname(fpath)
    dirname_str = os.path.abspath(dirname_str)
    dirnames = dirname_str.split(os.sep)
    n = len(dirnames)
    for i in xrange(n):
        # is there a .git directory at this level?
        # FIXME hack
        basedir = "/" + os.path.join(*dirnames[0:n - i])
        gitdir = os.path.join(basedir, ".git")
        if os.path.exists(gitdir):
            return basedir
206091
def commits?(path)
      res = false
      Dir.chdir(path) do
        _stdout, _stderr, exit_status = Open3.capture3( "git rev-parse HEAD" )
        res = (exit_status.to_i.zero?)
      end
      res
    end
1128946
def is_git_directory_clean(path_to_repo: Path,
                           search_parent_dirs: bool = True,
                           check_untracked: bool = False) -> None:
    
    repo = Repo(str(path_to_repo), search_parent_directories=search_parent_dirs)
    logger.debug("is_git_directory_clean check for repo in path={} from "\
                  "cwd={} with search_parent_directories={}".format(
                        path_to_repo, os.getcwd(), search_parent_dirs))

    # If there are changes to already tracked files
    if repo.is_dirty():
        raise DirtyRepoException("Changes to the index or working tree."
                                 "Commit them first .")
    if check_untracked:
        if repo.untracked_files:
            raise DirtyRepoException("Untracked files. Commit them first.")
909893
def _git_repo_path(self):
        
        logger.debug('Checking for git directory in: %s', self._package_top_dir)
        for p in self._package_top_dir:
            gitdir = os.path.join(p, '.git')
            if os.path.exists(gitdir):
                logger.debug('_is_git_clone() true based on %s' % gitdir)
                return gitdir
        logger.debug('_is_git_clone() false')
        return None
1120709
def _is_dirty(dir_path):
    """"""
    try:
        subprocess.check_call(["git", "diff", "--quiet"], cwd=dir_path)
        return False
    except subprocess.CalledProcessError:
        return True
1302474
def is_valid_file(path):
    '''  '''
    return os.path.exists(path) and os.path.isfile(path)
479378
def isdir(self, path, follow_symlinks=True):
        
        return self._is_of_type(path, S_IFDIR, follow_symlinks)
1054475
def _package_exists(path):
    # type: (str) -> bool
    
    while path:
        if os.path.exists(path):
            return True
        else:
            path = os.path.dirname(path)

    return False
1268390
def in_repo(self, filepath):
        
        filepath = set(filepath.replace('\\', '/').split('/'))
        for p in ('.git', '.hg', '.svn', '.cvs', '.bzr'):
            if p in filepath:
                return True
        return False