当前位置: 首页>>代码示例>>Python>>正文


Python git.Commit方法代码示例

本文整理汇总了Python中git.Commit方法的典型用法代码示例。如果您正苦于以下问题:Python git.Commit方法的具体用法?Python git.Commit怎么用?Python git.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git的用法示例。


在下文中一共展示了git.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_commits

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def test_get_commits():
    config = {
                "infile_globs": [
                    "test/grapher/*.lkml"
                ],

                "options": {
                    "node_size": 400,
                    "label_font_size": 10,
                    "text_angle": 30,
                    "image_width": 12,
                    "image_height" : 8
                }
            }
    animator = GraphAnimator(config)
    repo, commits = animator.get_commits("./", branch='master')
    assert isinstance(repo, git.Repo)
    assert len(commits) > 1
    assert isinstance(commits[0], git.Commit) 
开发者ID:ww-tech,项目名称:lookml-tools,代码行数:21,代码来源:test_graph_animator.py

示例2: commit_diff

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def commit_diff(c):
    """Return the set of changed files.

    Args:
        c (git.Commit)

    Returns:
        set[str]: a set of file paths (relative to the git repo's root directory).
    """
    changed = set()

    def add_path(blob):
        if blob is not None:
            changed.add(blob.path)

    prev_c = c.parents[0]
    for x in c.diff(prev_c):
        add_path(x.a_blob)
        add_path(x.b_blob)
    return changed 
开发者ID:kelvinguu,项目名称:lang2program,代码行数:22,代码来源:git_utils.py

示例3: commit

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def commit(self, rev):
        '''Return a Commit object.  rev can be _id or a branch/tag name'''
        cache = getattr(c, 'model_cache', '') or M.repository.ModelCache()
        result = cache.get(M.repository.Commit, dict(_id=rev))
        if result is None:
            # find the id by branch/tag name
            try:
                impl = self._git.rev_parse(str(rev) + '^0')
                result = cache.get(M.repository.Commit, dict(_id=impl.hexsha))
            except Exception:
                url = ''
                try:
                    from tg import request
                    url = ' at ' + request.url
                except:
                    pass
                log.exception('Error with rev_parse(%s)%s' %
                              (str(rev) + '^0', url))
        if result:
            result.set_context(self._repo)
        return result 
开发者ID:apache,项目名称:allura,代码行数:23,代码来源:git_repo.py

示例4: new_commits

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def new_commits(self, all_commits=False):
        graph = {}

        to_visit = [self._git.commit(rev=hd.object_id) for hd in self.heads]
        while to_visit:
            obj = to_visit.pop()
            if obj.hexsha in graph:
                continue
            if not all_commits:
                # Look up the object
                if M.repository.Commit.query.find(dict(_id=obj.hexsha)).count():
                    graph[obj.hexsha] = set()  # mark as parentless
                    continue
            graph[obj.hexsha] = set(p.hexsha for p in obj.parents)
            to_visit += obj.parents
        return list(topological_sort(graph)) 
开发者ID:apache,项目名称:allura,代码行数:18,代码来源:git_repo.py

示例5: __str__

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def __str__(self) -> str:
        output = []
        diff_body = self.printable_diff
        for bad_str in self.strings_found:  # type: ignore
            diff_body = diff_body.replace(bad_str, style_warning(bad_str))
        output.append(self.OUTPUT_SEPARATOR)
        output.append(style_ok("Reason: {}".format(self.issue_type.value)))  # type: ignore
        if self.issue_detail:
            output.append(style_ok("Detail: {}".format(self.issue_detail)))
        if self.diff:
            output.append(style_ok("Filepath: {}".format(self.file_path)))
        if self.branch_name:
            output.append(style_ok("Branch: {}".format(self.branch_name)))
        if self.commit:
            output.append(style_ok("Date: {}".format(self.commit_time)))
            output.append(style_ok("Hash: {}".format(self.commit_hash)))
            output.append(style_ok("Commit: {}".format(self.commit_message)))

        output.append(diff_body)
        output.append(self.OUTPUT_SEPARATOR)
        return "\n".join(output) 
开发者ID:godaddy,项目名称:tartufo,代码行数:23,代码来源:scanner.py

示例6: release_changelog

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def release_changelog(repo: Repo, version: Version) -> Commit:
    print("generate release commit")
    check_call(["towncrier", "--yes", "--version", version.public], cwd=str(ROOT_SRC_DIR))
    release_commit = repo.index.commit(f"release {version}")
    return release_commit 
开发者ID:tox-dev,项目名称:tox,代码行数:7,代码来源:release.py

示例7: are_child_commits_contained

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def are_child_commits_contained(self, git_ref: str) -> bool:
        r"""
        Magic begins here.

        `git format-patch` produces patches which cannot be applied when commits,
        in front of a git ref, have parents behind:

        * | | | | | | | |   ea500ac513 (tag: v245) Merge pull request #15...
        |\ \ \ \ \ \ \ \ \
        | * | | | | | | | | 0d5aef3eb5 hwdb: update for v245
        | | |_|_|_|_|_|/ /
        | |/| | | | | | |
        * | | | | | | | | 03985d069b NEWS: final contributor update for v245

        In this example, you can see that ea500 is tagged with 245 and
        is a merge commit. The additional lines mean that child commits of v245
        have parents behind v245 which means that `git format-patch` may
        create patches which may not able able to be applied.

        This method detects the situation described above.

        :param git_ref: git ref to check
        :return: yes if all child commits of the selected git ref are contained
                 within the set of git_ref children commits
        """
        commits = self.get_commits_since_ref(
            git_ref, add_upstream_head_commit=True, no_merge_commits=False
        )
        for commit in islice(commits, 1, None):  # 0 = upstream, don't check that one
            for parent_commit in commit.parents:
                if parent_commit not in commits:
                    logger.info(f"Commit {commit!r} has a parent behind {git_ref!r}.")
                    return False
        logger.debug(f"All commits are contained on top of {git_ref!r}.")
        return True 
开发者ID:packit-service,项目名称:packit,代码行数:37,代码来源:patches.py

示例8: get_commits_since_ref

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def get_commits_since_ref(
        self,
        git_ref: str,
        add_upstream_head_commit: bool = True,
        no_merge_commits: bool = True,
    ) -> List[git.Commit]:
        """
        Return a list of different commits between HEAD and selected git_ref

        :param git_ref: get commits since this git ref
        :param add_upstream_head_commit: add also upstream rev/tag commit as a first value
        :param no_merge_commits: do not include merge commits in the list if True
        :return: list of commits (last commit on the current branch.).
        """

        if is_a_git_ref(repo=self.lp.git_repo, ref=git_ref):
            upstream_ref = git_ref
        else:
            upstream_ref = f"origin/{git_ref}"
            if upstream_ref not in self.lp.git_repo.refs:
                raise Exception(
                    f"Upstream {upstream_ref!r} branch nor {git_ref!r} tag not found."
                )

        commits = list(
            self.lp.git_repo.iter_commits(
                rev=f"{git_ref}..{self.lp.ref}",
                reverse=True,
                no_merges=no_merge_commits,  # do not include merge commits in the list
            )
        )
        if add_upstream_head_commit:
            commits.insert(0, self.lp.git_repo.commit(upstream_ref))

        logger.debug(f"Delta ({upstream_ref}..{self.lp.ref}): {len(commits)}")
        return commits 
开发者ID:packit-service,项目名称:packit,代码行数:38,代码来源:patches.py

示例9: check_signature_of_commit

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def check_signature_of_commit(
        self, commit: git.Commit, possible_key_fingerprints: List[str]
    ) -> bool:
        """
        Check the validity of the commit signature
        and test if the signer is present in the provided list.
        (Commit without signature returns False.)
        """
        status = self.get_commit_signature_status(commit=commit)
        if status == CommitSignatureStatus.no_signature:
            logger.debug("Commit not signed.")
            return False

        if status == CommitSignatureStatus.cannot_be_checked:
            # We need to download keys before getting the signer
            for key in possible_key_fingerprints:
                self.download_gpg_key_if_needed(key_fingerprint=key)

        signer = self.get_commit_signer_fingerprint(commit)

        if not signer:
            logger.debug("Cannot get a signer of the commit.")
            return False

        if signer not in possible_key_fingerprints:
            logger.warning("Signature author not authorized.")
            return False

        is_valid = self.is_commit_signature_valid(commit)
        if not is_valid:
            logger.warning(f"Commit {commit.hexsha!r} signature is not valid.")
        return is_valid 
开发者ID:packit-service,项目名称:packit,代码行数:34,代码来源:security.py

示例10: is_commit_signature_valid

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def is_commit_signature_valid(self, commit: git.Commit) -> bool:
        """
        Check the validity of the commit signature.
        Key needs to be already present.
        """
        commit_status = self.get_commit_signature_status(commit)
        if commit_status in VALID_SIGNATURE_STATUSES:
            logger.debug(f"Commit {commit.hexsha!r} signature is valid.")
            return True

        logger.warning(f"Commit {commit.hexsha!r} signature is not valid.")
        return False 
开发者ID:packit-service,项目名称:packit,代码行数:14,代码来源:security.py

示例11: get_commit_signature_status

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def get_commit_signature_status(commit: git.Commit) -> "CommitSignatureStatus":
        """Get a signature status from the given commit."""
        signature_mark = CommitVerifier._get_commit_info(commit, pretty_format="%G?")
        return CommitSignatureStatus(signature_mark) 
开发者ID:packit-service,项目名称:packit,代码行数:6,代码来源:security.py

示例12: _get_commit_info

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def _get_commit_info(commit: git.Commit, pretty_format: str) -> str:
        """
        Return a commit information in a given format.

        See `git show --help` and `--pretty=format` for more information.
        """
        try:
            return commit.repo.git.show(commit.hexsha, pretty=f"format:{pretty_format}")
        except git.GitCommandError as error:
            raise PackitException(
                f"Cannot find commit {commit.hexsha!r} to check its signature.", error
            ) 
开发者ID:packit-service,项目名称:packit,代码行数:14,代码来源:security.py

示例13: _init_commit_tags_index

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def _init_commit_tags_index(
        repo: Repo, tag_prefix: str, tag_pattern: Optional[str] = None
    ) -> Dict[Commit, List[TagReference]]:
        """ Create reverse index """
        reverse_tag_index = {}
        semver_regex = default_tag_pattern
        for tagref in repo.tags:
            tag_name = tagref.name
            commit = tagref.commit

            consider_tag = False

            # consider & remove the prefix if we found one
            if tag_name.startswith(tag_prefix):
                tag_name = tag_name.replace(tag_prefix, "")

                # if user specified a tag pattern => consider it
                if tag_pattern is not None:
                    if re.fullmatch(tag_pattern, tag_name):
                        consider_tag = True
                # no tag pattern specified by user => check semver semantic
                elif re.fullmatch(semver_regex, tag_name):
                    consider_tag = True

            # good format of the tag => consider it
            if consider_tag:
                if commit not in reverse_tag_index:
                    reverse_tag_index[commit] = []
                reverse_tag_index[commit].append(tagref)
        return reverse_tag_index 
开发者ID:Michael-F-Bryan,项目名称:auto-changelog,代码行数:32,代码来源:repository.py

示例14: test_include_unreleased

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def test_include_unreleased(mock_ggu, mock_ena, mock_era, mock_repo):
    mock_repo.return_value.iter_commits.return_value = [Mock(spec=Commit), Mock(spec=Commit)]

    repository = GitRepository(".", skip_unreleased=False)
    changelog = repository.generate_changelog()

    assert changelog.releases[0].title == "Unreleased" 
开发者ID:Michael-F-Bryan,项目名称:auto-changelog,代码行数:9,代码来源:test_repository.py

示例15: test_latest_version

# 需要导入模块: import git [as 别名]
# 或者: from git import Commit [as 别名]
def test_latest_version(mock_ggu, mock_ena, mock_era, mock_repo):
    mock_repo.return_value.iter_commits.return_value = [Mock(spec=Commit), Mock(spec=Commit)]

    repository = GitRepository(".", latest_version="v1.2.3")
    changelog = repository.generate_changelog()

    assert changelog.releases[0].title == "v1.2.3" 
开发者ID:Michael-F-Bryan,项目名称:auto-changelog,代码行数:9,代码来源:test_repository.py


注:本文中的git.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。