:returns: `<short git hash>` if Git repository found
352678
def git_suffix(fname):
    
    # we assume that the .git folder is two levels above any package
    # i.e. openquake/engine/../../.git
    git_path = os.path.join(os.path.dirname(fname), '..', '..', '.git')

    # macOS complains if we try to execute git and it's not available.
    # Code will run, but a pop-up offering to install bloatware (Xcode)
    # is raised. This is annoying in end-users installations, so we check
    # if .git exists before trying to execute the git executable
    if os.path.isdir(git_path):
        try:
            gh = subprocess.check_output(
                ['git', 'rev-parse', '--short', 'HEAD'],
                stderr=open(os.devnull, 'w'),
                cwd=os.path.dirname(git_path)).strip()
            gh = "-git" + decode(gh) if gh else ''
            return gh
        except Exception:
            # trapping everything on purpose; git may not be installed or it
            # may not work properly
            pass

    return ''
137224
def validate_sha(sha):
    
    cmd = ["git", "log", "-r", sha]
    try:
        subprocess.check_output(cmd, stderr=subprocess.STDOUT)
    except subprocess.SubprocessError:
        raise ValueError(
            f"The sha listed in the branch name, {sha}, is not present in the repository"
        )
75857
def get_git_commit(self, sha):
        
        assert isinstance(sha, (str, unicode)), sha
        headers, data = self._requester.requestJsonAndCheck(
            "GET",
            self.url + "/git/commits/" + sha
        )
        return github.GitCommit.GitCommit(self._requester, headers, data, completed=True)
994540
def get_sha(path=None, log=None, short=False, timeout=None):
    
    # git_command = "git rev-parse HEAD {}".format(repo_name).split()
    # git_command = "git rev-parse HEAD".split()
    git_command = ["git", "rev-parse"]
    if short:
        git_command.append("--short")
    git_command.append("HEAD")

    kwargs = {}
    if path is not None:
        kwargs['cwd'] = path
    if timeout is not None:
        kwargs['timeout'] = timeout

    if log is not None:
        log.debug("{} {}".format(git_command, str(kwargs)))

    sha = subprocess.check_output(git_command, **kwargs)
    try:
        sha = sha.decode('ascii').strip()
    except:
        if log is not None:
            log.debug("decode of '{}' failed".format(sha))

    return sha
802179
def has_in_repos(self, repo):
        
        assert isinstance(repo, github.Repository.Repository), repo
        status, headers, data = self._requester.requestJson(
            "GET",
            self.url + "/repos/" + repo._identity
        )
        return status == 204
971331
def get_git_blob(self, sha):
        
        assert isinstance(sha, (str, unicode)), sha
        headers, data = self._requester.requestJsonAndCheck(
            "GET",
            self.url + "/git/blobs/" + sha
        )
        return github.GitBlob.GitBlob(self._requester, headers, data, completed=True)
315086
def get_gitdir(self):
        """"""
        if self.gitlookup is None:
            raise tornado.web.HTTPError(500, 'no git lookup configured')

        gitdir = self.gitlookup(self.request)
        if gitdir is None:
            raise tornado.web.HTTPError(404, 'unable to find repository')
        logger.debug("Accessing git at: %s", gitdir)

        return gitdir
283825
def probe_git():
    """"""
    try:
        repo = git.Repo()
    except git.InvalidGitRepositoryError:
        LOGGER.warning(
            "We highly recommend keeping your model in a git repository."
            " It allows you to track changes and to easily collaborate with"
            " others via online platforms such as https://github.com.\n")
        return
    if repo.is_dirty():
        LOGGER.critical(
            "Please git commit or git stash all changes before running"
            " the memote suite.")
        sys.exit(1)
    return repo
524608
def find_repo_type(self):
        """"""
        is_git = self.call(['git', 'rev-parse', '--is-inside-work-tree'],
                           devnull=True)
        if is_git != 0:
            if self.debug:
                click.echo('not git')
            is_hg = self.call(['hg', '-q', 'stat'], devnull=True)
            if is_hg != 0:
                if self.debug:
                    click.echo('not hg')
                exit(1)
            else:
                self.vc_name = 'hg'
439151
def remote_differs?
      remote_sha = nil
      current_sha = nil
      git_repo = git_repo_for(@repo_dir)
      without_size_limit(git_repo) do
        do_fetch(git_repo)
        revision = resolve_revision
        remote_name = validate_revision(git_repo, revision)
        remote_sha = git_repo.sha_for(remote_name ? remote_name : revision)
        current_sha = git_repo.sha_for(nil)
      end
      current_sha != remote_sha
    end
1198987
function dependencyMatch (expected, actual) {
  // expand github:user/repo#hash to git://github.com/...
  if (expected.indexOf('github:') === 0) {
    expected = expected.replace(/^github:/, 'git://github.com/')
    var parsed = url.parse(expected)
    parsed.pathname += '.git'
    expected = url.format(parsed)
  }

    // normalize git+https prefix
  actual = actual.replace(/^git\+https/, 'git')
  expected = expected.replace(/^git\+https/, 'git')

  expected = ngu(expected)
  actual = ngu(actual)

  expected.url = expected.url.replace('https://', 'git://')
  actual.url = actual.url.replace('https://', 'git://')

  if (expected.url !== actual.url) {
    return false
  }

  if (actual.branch && actual.branch.indexOf(expected.branch) !== 0) {
    return false
  }

  return true
}
394530
def get_repo_hexsha(git_folder):
    """"""
    repo = Repo(str(git_folder))
    if repo.bare:
        not_git_hexsha = "notgitrepo"
        _LOGGER.warning("Not a git repo, SHA1 used will be: %s", not_git_hexsha)
        return not_git_hexsha
    hexsha = repo.head.commit.hexsha
    _LOGGER.info("Found REST API repo SHA1: %s", hexsha)
    return hexsha
644744
def _find_git_info(self, gitdir):
        
        res = {'remotes': None, 'tag': None, 'commit': None, 'dirty': None}
        try:
            logger.debug('opening %s as git.Repo', gitdir)
            repo = Repo(path=gitdir, search_parent_directories=False)
            res['commit'] = repo.head.commit.hexsha
            res['dirty'] = repo.is_dirty(untracked_files=True)
            res['remotes'] = {}
            for rmt in repo.remotes:
                # each is a git.Remote
                urls = [u for u in rmt.urls]  # generator
                if len(urls) > 0:
                    res['remotes'][rmt.name] = urls[0]
            for tag in repo.tags:
                # each is a git.Tag object
                if tag.commit.hexsha == res['commit']:
                    res['tag'] = tag.name
        except Exception:
            logger.debug('Exception getting git information', exc_info=True)
        return res
303349
def commit_hash(dir='.'):
    

    cmd = ['git', 'rev-parse', 'HEAD']

    try:
        with open(os.devnull, 'w') as devnull:
            revision_hash = subprocess.check_output(
                cmd,
                cwd=dir,
                stderr=devnull
            )
        if sys.version_info.major > 2:
            revision_hash = revision_hash.decode('ascii')

        return revision_hash.strip()

    except subprocess.CalledProcessError:
        return None
205554
def repository(self):
        
        self._completeIfNotSet(self._repository)
        if self._repository is github.GithubObject.NotSet:
            # The repository was not set automatically, so it must be looked up by url.
            repo_url = "/".join(self.url.split("/")[:-2])
            self._repository = github.GithubObject._ValuedAttribute(github.Repository.Repository(self._requester, self._headers, {'url': repo_url}, completed=False))
        return self._repository.value
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.")
530555
def _check_submodule(self):
        

        if (self.path is None or
                (os.path.exists(self.path) and not os.path.isdir(self.path))):
            return False

        if self.use_git:
            return self._check_submodule_using_git()
        else:
            return self._check_submodule_no_git()