Try to describe the current commit of a Git repository.

    Return a string containing a string with the commit ID and/or a base tag,
    if successful. Otherwise, return None.
542257
def git_try_describe(repo_path):
    
    try:
        p = subprocess.Popen(['git', 'describe', '--always', '--dirty'],
                             cwd=repo_path, stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        output, _ = p.communicate()
    except:
        return None
    else:
        if p.returncode == 0:
            return output.strip()

    return None
40039
def commit(self, commit):
		
		try:
			return self._commitData(self.repo.get_commit(commit))
		except (ValueError, KeyError, GithubException):
			raise KeyError("Commit %s not found" % commit)
455832
def get_commit_from_tag(self, tag: str) -> Commit:
        
        try:
            selected_tag = self.repo.tags[tag]
            return self.get_commit(selected_tag.commit.hexsha)
        except (IndexError, AttributeError):
            logger.debug('Tag %s not found', tag)
            raise
789287
def get_revision():
    
    proc = Process("git log", ["git", "log", "-1"])

    try:
        while True:
            line = proc.stdout.pop().strip().decode('utf8')
            if not line:
                continue
            if line.startswith("commit "):
                return line[7:]
    finally:
        with suppress_exception:
            proc.join()
1064555
def commit_container(self, container_id, image=None, message=None):
        
        logger.info("committing container '%s'", container_id)
        logger.debug("container_id = '%s', image = '%s', message = '%s'",
                     container_id, image, message)
        tag = None
        if image:
            tag = image.tag
            image = image.to_str(tag=False)
        response = self.d.commit(container_id, repository=image, tag=tag, message=message)
        logger.debug("response = '%s'", response)
        try:
            return response['Id']
        except KeyError:
            logger.error("ID missing from commit response")
            raise RuntimeError("ID missing from commit response")
815011
def get_rev(tag=True):
    
    rev_cmd = "git describe --always --tag" if tag in (True, "True") else \
              "git rev-parse HEAD"
    return local(rev_cmd, capture=True).strip()
32723
def commit_check():
    '''
    
    '''
    conn = __proxy__['junos.conn']()
    ret = {}
    ret['out'] = True
    try:
        conn.cu.commit_check()
        ret['message'] = 'Commit check succeeded.'
    except Exception as exception:
        ret['message'] = 'Commit check failed with {0}'.format(exception)
        ret['out'] = False

    return ret
804880
def get_commit_url(repo_url):
    """"""
    if "github.com" in repo_url:
        return repo_url[:-4] if repo_url.endswith(".git") else repo_url
    if "git.openstack.org" in repo_url:
        uri = '/'.join(repo_url.split('/')[-2:])
        return "https://github.com/{0}".format(uri)

    # If it didn't match these conditions, just return it.
    return repo_url
879853
def commit(self):
        """"""
        obj = self.object
        while obj.type != 'commit':
            if obj.type == "tag":
                # it is a tag object which carries the commit as an object - we can point to anything
                obj = obj.object
            else:
                raise ValueError(("Cannot resolve commit as tag %s points to a %s object - " +
                                  "use the `.object` property instead to access it") % (self, obj.type))
        return obj
978686
def tag(self, tagname, message=None, force=True):
        """"""
        return git_tag(self.repo_dir, tagname, message=message, force=force)
344321
def get_git_info(git_folder, verbose=False):
    
    if verbose:
        print("detect GIT info by folder: '%s'" % git_folder)
    try:
        git_info = {
            "commitid": get_commit_id(git_folder),
            "branch": get_current_branch(git_folder),
            "git_path": get_git_file_path(git_folder),
            "url": get_remote_url(git_folder),
            "scm": "unknown",
            "scm_group": "unknown",
            "scm_path": "unknown",
            "scm_link": ""
        }
        if is_git_root_dirty(git_folder):
            git_info['dirty'] = True
    except Exception as err:  # pylint: disable=broad-except
        print("GitTool exception:")
        print(err)
        return {}

    if isinstance(git_info['url'], str):
        match = re.search(r"github\.com:(.*)\/(.*)", git_info['url'])
        if match:
            git_info["scm"] = "github.com"
            git_info["scm_path"] = match.group(2)
            git_info["scm_group"] = match.group(1)
            scm_link_end = " %s/%s" % (git_info["scm_group"],
                                       git_info["scm_path"].replace(".git", ""))
            git_info["scm_link"] = "https://github.com/" + scm_link_end
            git_info["scm_link"] += "/tree/%s/%s" % (git_info['commitid'], git_info["git_path"])

    if verbose:
        print("all git_info:")
        print(git_info)

    return git_info
134440
def infer(args: argparse.Namespace) -> None:
    
    try:
        last_tag = last_git_release_tag(git_tags())
    except NoGitTagsException:
        print(SemVer(0, 1, 0))
        exit(0)

    commit_log = git_commits_since_last_tag(last_tag)
    action = parse_commit_log(commit_log)

    last_ver = git_tag_to_semver(last_tag)

    if action == 'min':
        new_ver = last_ver.bump_minor()
    elif action == 'maj':
        new_ver = last_ver.bump_major()
    else:
        new_ver = last_ver.bump_patch()

    print(new_ver)
593778
def format_git_describe(git_str, pep440=False):
    """"""
    if git_str is None:
        return None
    if "-" not in git_str:  # currently at a tag
        return git_str
    else:
        # formatted as version-N-githash
        # want to convert to version.postN-githash
        git_str = git_str.replace("-", ".post", 1)
        if pep440:  # does not allow git hash afterwards
            return git_str.split("-")[0]
        else:
            return git_str.replace("-g", "+git")
117872
def git_repo():
    
    try:
        reldir = subprocess.check_output(
            ["git", "rev-parse", "--git-dir"])
        reldir = reldir.decode("utf-8")
        return os.path.basename(os.path.dirname(os.path.abspath(reldir)))
    except subprocess.CalledProcessError:
        return None
248859
def inspect_commit(self, commit):
        
        req = proto.InspectCommitRequest(commit=commit_from(commit))
        return self.stub.InspectCommit(req, metadata=self.metadata)
1096024
def get_git_tag(self, sha):
        
        assert isinstance(sha, (str, unicode)), sha
        headers, data = self._requester.requestJsonAndCheck(
            "GET",
            self.url + "/git/tags/" + sha
        )
        return github.GitTag.GitTag(self._requester, headers, data, completed=True)
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)