Return True if the directory is inside a git repo.
503713
def is_git_repo(repo_dir):
    """"""
    command = ['git', 'rev-parse']
    try:
        execute_git_command(command, repo_dir=repo_dir)
    except exceptions.SimplGitCommandError:
        return False
    else:
        return True
100150
def check_git():
    """"""
    try:
        with open(os.devnull, "wb") as devnull:
            subprocess.check_call(["git", "--version"], stdout=devnull, stderr=devnull)
    except:
        raise RuntimeError("Please make sure git is installed and on your path.")
450630
function getGitFolder() {
	// Based on logic in Module._nodeModulePaths at
	// https://github.com/joyent/node/blob/master/lib/module.js
	var from = path.resolve('.'),
		parts = from.split(process.platform === 'win32' ? /[\/\\]/ : /\//),
		tip, dir

	for (tip = parts.length - 1; tip >= 0; tip--) {
		dir = parts.slice(0, tip + 1).concat('.git').join(path.sep)
		try {
			if (fs.statSync(dir).isDirectory()) {
				// Found a valid .git directory
				return dir
			}
		} catch (e) {
			// Let 'for' iterate
		}
	}
	return ''
}
40094
def using_git(cwd):
    """"""
    try:
        git_log = shell_out(["git", "log"], cwd=cwd)
        return True
    except (CalledProcessError, OSError):  # pragma: no cover
        return False
92782
def is_git_file(cls, path, name):
        """"""
        os.chdir(path)
        p = subprocess.Popen(['git', 'ls-files', '--error-unmatch', name],
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        p.wait()
        return p.returncode == 0
432300
def isignored(self, relpath, directory=False):
    """"""
    relpath = self._relpath_no_dot(relpath)
    if directory:
      relpath = self._append_trailing_slash(relpath)
    return self.ignore.match_file(relpath)
69498
def get_files_in_commit(git_folder, commit_id="HEAD"):
    
    repo = Repo(str(git_folder))
    output = repo.git.diff("--name-only", commit_id+"^", commit_id)
    return output.splitlines()
755019
def pull(directory: str) -> Commit:
    
    if not os.path.exists(directory):
        raise ValueError(f"No subrepo found in \"{directory}\"")
    try:
        result = run([GIT_COMMAND, _GIT_SUBREPO_COMMAND, _GIT_SUBREPO_PULL_COMMAND, _GIT_SUBREPO_VERBOSE_FLAG,
                      get_directory_relative_to_git_root(directory)],
                     execution_directory=get_git_root_directory(directory))
    except RunException as e:
        if "Can't pull subrepo. Working tree has changes" in e.stderr:
            raise UnstagedChangeException() from e
    return status(directory)[2]
415999
async function isGitRepo(execaOpts) {
  try {
    return (await execa('git', ['rev-parse', '--git-dir'], execaOpts)).code === 0;
  } catch (error) {
    debug(error);
  }
}
726050
def has_repos(self):
        
        for section in self.sections():
            if section not in self.reserved_sections:
                return True
        return False
1193653
def _gitinfo():
    '''  '''
    result = None
    repo_path = os.path.join(os.path.dirname(__file__), '..', '..', '..', '.git')

    if os.path.exists(repo_path):
        # Check if the .git is a file. If it is a file, it means that we are in a submodule structure.
        if os.path.isfile(repo_path):
            try:
                gitdir = yaml.load(open(repo_path)).get('gitdir')
                # There is a posibility the .git file to have an absolute path.
                if os.path.isabs(gitdir):
                    repo_path = gitdir
                else:
                    repo_path = os.path.join(repo_path.split('.git')[0], gitdir)
            except (IOError, AttributeError):
                return ''
        f = open(os.path.join(repo_path, "HEAD"))
        branch = f.readline().split('/')[-1].rstrip("\n")
        f.close()
        branch_path = os.path.join(repo_path, "refs", "heads", branch)
        if os.path.exists(branch_path):
            f = open(branch_path)
            commit = f.readline()[:10]
            f.close()
            date = time.localtime(os.stat(branch_path).st_mtime)
            if time.daylight == 0:
                offset = time.timezone
            else:
                offset = time.altzone
            result = "({0} {1}) last updated {2} (GMT {3:+04d})".format(branch, commit,
                time.strftime("%Y/%m/%d %H:%M:%S", date), offset / -36)
    else:
        result = ''
    return result
721834
def find_worktree_git_dir(dotgit):
    """"""
    try:
        statbuf = os.stat(dotgit)
    except OSError:
        return None
    if not stat.S_ISREG(statbuf.st_mode):
        return None

    try:
        lines = open(dotgit, 'r').readlines()
        for key, value in [line.strip().split(': ') for line in lines]:
            if key == 'gitdir':
                return value
    except ValueError:
        pass
    return None
983152
def is_directory (self):
        
        filename = self.get_os_filename()
        return os.path.isdir(filename) and not os.path.islink(filename)
711367
def is_repo_instance(cls, path):
        
        try:
            cls.get_version(path)
            return True
        except subprocess.CalledProcessError:
            # Git returns non-zero status
            return False
        except OSError:
            # Git unavailable?
            return False
31329
def _is_gitted(self):
        
        from os import waitpid
        from subprocess import Popen, PIPE
    
        premote = Popen("cd {}; git remote -v".format(self.repodir),
                        shell=True, executable="/bin/bash", stdout=PIPE, stderr=PIPE)
        waitpid(premote.pid, 0)
        remote = premote.stdout.readlines()
        remerr = premote.stderr.readlines()

        pbranch = Popen("cd {}; git branch".format(self.repodir),
                        shell=True, executable="/bin/bash", stdout=PIPE, stderr=PIPE)
        waitpid(pbranch.pid, 0)
        branch = pbranch.stdout.readlines()
        braerr = pbranch.stderr.readlines()

        if len(remote) > 0 and len(remerr) > 0 and len(branch) > 0:
            return ((".git" in remote[0] and "fatal" not in remerr[0])
                    and any(["testing" in b for b in branch]))
        elif self.testmode and len(remote) == 0 and len(branch) == 0 and len(remerr) == 0:
            return True
        else:
            return False
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
493466
def _repo_is_preset(repo):
    

    package_template = "https://raw.githubusercontent.com"
    package_template += "/{repo}/master/package.json"
    package_path = package_template.format(repo=repo)

    response = get(package_path)
    if response.status_code == 404:
        return False

    try:
        data = response.json()
    except:
        return False

    if not data.get("type") == "bepreset":
        return False

    return True