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


Python pygit2.Signature方法代码示例

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


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

示例1: add_repo_tag

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def add_repo_tag(git_dir, repo, tags, repo_name):
    """ Use a list to create multiple tags on a git repo """
    for tag in reversed(tags):
        time.sleep(1)
        tests.add_commit_git_repo(
            os.path.join(git_dir, "repos", repo_name), ncommits=1
        )
        first_commit = repo.revparse_single("HEAD")
        tagger = pygit2.Signature("Alice Doe", "adoe@example.com", 12347, 0)
        repo.create_tag(
            tag,
            first_commit.oid.hex,
            pygit2.GIT_OBJ_COMMIT,
            tagger,
            "Release " + tag,
        ) 
开发者ID:Pagure,项目名称:pagure,代码行数:18,代码来源:test_pagure_lib_git_get_tags_objects.py

示例2: add_tag_git_repo

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def add_tag_git_repo(folder, tagname, obj_hash, message):
    """ Add a tag to the given object of the given repo annotated by given message. """
    repo, newfolder, branch_ref_obj = _clone_and_top_commits(
        folder, "master", branch_ref=True
    )

    tag_sha = repo.create_tag(
        tagname,
        obj_hash,
        repo.get(obj_hash).type,
        pygit2.Signature("Alice Author", "alice@authors.tld"),
        message,
    )

    # Push to origin
    ori_remote = repo.remotes[0]
    PagureRepo.push(
        ori_remote, "refs/tags/%s:refs/tags/%s" % (tagname, tagname)
    )

    shutil.rmtree(newfolder)
    return tag_sha 
开发者ID:Pagure,项目名称:pagure,代码行数:24,代码来源:__init__.py

示例3: test_view_history_file_on_tag

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def test_view_history_file_on_tag(self):
        """ Test the view_history_file endpoint """
        # set a tag on the head's parent commit
        repo_obj = pygit2.Repository(
            os.path.join(self.path, "repos", "test.git")
        )
        commit = repo_obj[repo_obj.head.target]
        parent = commit.parents[0].oid.hex
        tagger = pygit2.Signature("Alice Doe", "adoe@example.com", 12347, 0)
        repo_obj.create_tag(
            "v1.0", parent, pygit2.GIT_OBJ_COMMIT, tagger, "Release v1.0"
        )

        output = self.app.get("/test/history/sources?identifier=v1.0")
        self.assertEqual(output.status_code, 200)
        output_text = output.get_data(as_text=True)
        self.assertIn("<strong>initial commit</strong>", output_text)
        data = self.regex.findall(output_text)
        self.assertEqual(len(data), 1) 
开发者ID:Pagure,项目名称:pagure,代码行数:21,代码来源:test_pagure_flask_ui_repo_view_history.py

示例4: git_commit

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def git_commit(self):
        """Commit the current index to the git repository."""
        author = pygit2.Signature(
            'Git-Annex-Adapter Tester',
            'git-annex-adapter-tester@example.com',
            1500000000, # Date: 2017-07-14 02:40:00
        )

        try:
            parents = [self.repo.head.get_object().hex]
        except pygit2.GitError:
            parents = []

        return self.repo.create_commit(
            'HEAD', author, author, 'Test commit',
            self.repo.index.write_tree(), parents,
        ) 
开发者ID:alpernebbi,项目名称:git-annex-adapter,代码行数:19,代码来源:utils.py

示例5: test_incomplete_signature_does_not_crash_gitdata_classes

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def test_incomplete_signature_does_not_crash_gitdata_classes(self):
        import tempfile

        with tempfile.TemporaryDirectory(prefix="tmprepo_") as tmp_repo_location:
            # change working directory
            os.chdir(tmp_repo_location)
            subprocess.run(['git', 'init'], cwd=tmp_repo_location)
            # create a file a single line in it
            filename = 'file.txt'
            with open(os.path.join(tmp_repo_location, filename), "w") as f:
                f.write("A single line of code\n")
            subprocess.run(['git', 'add', 'file.txt'], cwd=tmp_repo_location)
            # apparently it is not possible to create pygit.Signature with empty author's email (and name)
            # but commits with no author's email can be created via git
            subprocess.run(['git', 'commit', '-m "No-email author" --author "Author NoEmail <>"'],
                           cwd=tmp_repo_location)
            try:
                # Commit without author's email does not crash data fetch
                git_repository = Repository(tmp_repo_location)
                WholeHistory(git_repository)
                BlameData(git_repository)
            except Exception as e:
                self.fail(str(e)) 
开发者ID:vifactor,项目名称:repostat,代码行数:25,代码来源:test_gitdata.py

示例6: add_binary_git_repo

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def add_binary_git_repo(folder, filename):
    """ Create a fake image file for the specified git repo. """
    repo, newfolder, parents = _clone_and_top_commits(folder, "master")

    content = b"""\x00\x00\x01\x00\x01\x00\x18\x18\x00\x00\x01\x00 \x00\x88
\t\x00\x00\x16\x00\x00\x00(\x00\x00\x00\x18\x00x00\x00\x01\x00 \x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa7lM\x01\xa6kM\t\xa6kM\x01
\xa4fF\x04\xa2dE\x95\xa2cD8\xa1a
"""

    # Create a file in that git repo
    with open(os.path.join(newfolder, filename), "wb") as stream:
        stream.write(content)
    repo.index.add(filename)
    repo.index.write()

    # Commits the files added
    tree = repo.index.write_tree()
    author = pygit2.Signature("Alice Author", "alice@authors.tld")
    committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
    repo.create_commit(
        "refs/heads/master",  # the name of the reference to update
        author,
        committer,
        "Add a fake image file",
        # binary string representing the tree object ID
        tree,
        # list of binary strings representing parents of the new commit
        parents,
    )

    # Push to origin
    ori_remote = repo.remotes[0]
    master_ref = repo.lookup_reference("HEAD").resolve()
    refname = "%s:%s" % (master_ref.name, master_ref.name)

    PagureRepo.push(ori_remote, refname)

    shutil.rmtree(newfolder) 
开发者ID:Pagure,项目名称:pagure,代码行数:42,代码来源:__init__.py

示例7: test_view_blame_file_on_tag

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def test_view_blame_file_on_tag(self):
        """ Test the view_blame_file endpoint """
        # set a tag on the head's parent commit
        repo_obj = pygit2.Repository(
            os.path.join(self.path, "repos", "test.git")
        )
        commit = repo_obj[repo_obj.head.target]
        parent = commit.parents[0].oid.hex
        tagger = pygit2.Signature("Alice Doe", "adoe@example.com", 12347, 0)
        repo_obj.create_tag(
            "v1.0", parent, pygit2.GIT_OBJ_COMMIT, tagger, "Release v1.0"
        )

        output = self.app.get("/test/blame/sources?identifier=v1.0")
        self.assertEqual(output.status_code, 200)
        output_text = output.get_data(as_text=True)
        self.assertIn('<table class="code_table">', output_text)
        self.assertTrue(
            '<tr><td class="cell1"><a id="1" href="#1" '
            'data-line-number="1"></a></td>' in output_text
            or '<tr><td class="cell1"><a data-line-number="1" '
            'href="#1" id="1"></a></td>' in output_text
        )
        self.assertIn(
            '<td class="cell2"><pre><code>foo</code></pre></td>', output_text
        )
        self.assertIn('<td class="cell_user">Alice Author</td>', output_text)
        data = self.regex.findall(output_text)
        self.assertEqual(len(data), 1) 
开发者ID:Pagure,项目名称:pagure,代码行数:31,代码来源:test_pagure_flask_ui_repo_view_blame.py

示例8: test_view_file_from_tag_hex

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def test_view_file_from_tag_hex(self):
        repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
        commit = repo.revparse_single("HEAD")
        tagger = pygit2.Signature("Alice Doe", "adoe@example.com", 12347, 0)
        tag = repo.create_tag(
            "v1.0_tag",
            commit.oid.hex,
            pygit2.GIT_OBJ_COMMIT,
            tagger,
            "Release v1.0",
        )

        output = self.app.get("/api/0/test/tree/%s" % tag.hex)
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.get_data(as_text=True))
        self.assertDictEqual(
            data,
            {
                "content": [
                    {
                        "content_url": "http://localhost/test/raw/"
                        "%s/f/README.rst" % tag.hex,
                        "name": "README.rst",
                        "path": "README.rst",
                        "type": "file",
                    }
                ],
                "name": None,
                "type": "folder",
            },
        ) 
开发者ID:Pagure,项目名称:pagure,代码行数:33,代码来源:test_pagure_flask_api_project_view_file.py

示例9: _make_signature

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def _make_signature(name, email):
    if six.PY2:
        if isinstance(name, six.text_type):
            name = name.encode("utf-8")
        if isinstance(email, six.text_type):
            email = email.encode("utf-8")
    return pygit2.Signature(name=name, email=email) 
开发者ID:Pagure,项目名称:pagure,代码行数:9,代码来源:git.py

示例10: new_git_tag

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def new_git_tag(project, tagname, target, user, message=None, force=False):
    """ Create a new git tag in the git repositorie of the specified project.

    :arg project: the project in which we want to create a git tag
    :type project: pagure.lib.model.Project
    :arg tagname: the name of the tag to create
    :type tagname: str
    :arg user: the user creating the tag
    :type user: pagure.lib.model.User
    :kwarg message: the message to include in the annotation of the tag
    :type message: str or None
    :kwarg force: a boolean specifying wether to force the creation of
        the git tag or not
    :type message: bool
    """
    repopath = pagure.utils.get_repo_path(project)
    repo_obj = PagureRepo(repopath)

    target_obj = repo_obj.get(target)
    if not target_obj:
        raise pygit2.GitError("Unknown target: %s" % target)

    if force:
        existing_tag = repo_obj.lookup_reference("refs/tags/%s" % tagname)
        if existing_tag:
            existing_tag.delete()

    tag = repo_obj.create_tag(
        tagname,
        target,
        target_obj.type,
        pygit2.Signature(user.fullname, user.default_email),
        message,
    )

    return tag 
开发者ID:Pagure,项目名称:pagure,代码行数:38,代码来源:git.py

示例11: commit_changes

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def commit_changes(self):
        self.repo.index.add_all()
        self.repo.index.write()
        tree = self.repo.index.write_tree()
        author = pygit2.Signature("bx", "bx@cs")
        old = self.repo.create_commit(self.get_head(),
                                      author,
                                      author,
                                      "auto commit for testing",
                                      tree,
                                      [self.repo.head.get_object().hex]) 
开发者ID:bx,项目名称:bootloader_instrumentation_suite,代码行数:13,代码来源:git_mgr.py

示例12: map_signature

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def map_signature(mailmap, signature: git.Signature):
    # the unmapped email is used on purpose
    email = signature.email
    try:
        mapped_signature = mailmap.resolve_signature(signature)
        name = mapped_signature.name
    except ValueError:
        name = signature.name
        if not name:
            name = "Empty Empty"
            # warnings.warn(f"{str(e)}. Name will be replaced with '{name}'")
        if not email:
            email = "empty@empty.empty"
            # warnings.warn(f"{str(e)}. Email will be replaced with '{email}'")
    return name, email 
开发者ID:vifactor,项目名称:repostat,代码行数:17,代码来源:gitdata.py

示例13: set_author

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def set_author(self, name: str, email: str):
            self.author_signature = git.Signature(name, email)
            return self 
开发者ID:vifactor,项目名称:repostat,代码行数:5,代码来源:gitrepository.py

示例14: test_records_count_in_history

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def test_records_count_in_history(self):
        # create second branch from 'master' (which already had one commit)
        branch = self.test_repo.branches.local.create('second_branch', self.test_repo.head.peel())
        self.test_repo.checkout(branch)

        # create commit on new branch
        self.test_repo.commit_builder \
            .set_author("Author Author", "author@author.net") \
            .add_file(content=["some content"]) \
            .commit()

        # so far no merge commits, both linear and whole history caches should contain 2 records
        whole_history_df = WholeHistory(self.test_repo).as_dataframe()
        self.assertEqual(2, len(whole_history_df.index))
        linear_history_df = LinearHistory(self.test_repo).as_dataframe()
        self.assertEqual(2, len(linear_history_df.index))

        # now merge commit is being created
        # checkout to master
        master_branch = self.test_repo.branches.get('master')
        self.test_repo.checkout(master_branch)
        # and merge 'second_branch' into 'master'
        self.test_repo.merge(self.test_repo.branches.get('second_branch').peel().id)
        # by creating merge commit
        author = Signature("name", "email")
        committer = author
        tree = self.test_repo.index.write_tree()
        message = "Merge 'second_branch' into 'master'"
        self.test_repo.create_commit('HEAD', author, committer, message, tree,
                                     [self.test_repo.head.target,
                                      self.test_repo.branches.get('second_branch').peel().oid])

        # whole history cache should contain 3 records: initial commit + commit in merged branch + merge commit
        whole_history_df = WholeHistory(self.test_repo).as_dataframe()
        self.assertEqual(3, len(whole_history_df.index))
        # linear history cache still contains 2 records: initial commit + merge commit
        linear_history_df = LinearHistory(self.test_repo).as_dataframe()
        self.assertEqual(2, len(linear_history_df.index))

        # check merge commits count (there is a single merge commit)
        self.assertEqual(1, whole_history_df['is_merge_commit'].sum()) 
开发者ID:vifactor,项目名称:repostat,代码行数:43,代码来源:test_gitdata.py

示例15: add_commit_git_repo

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Signature [as 别名]
def add_commit_git_repo(
    folder, ncommits=10, filename="sources", branch="master", symlink_to=None
):
    """ Create some more commits for the specified git repo. """
    repo, newfolder, branch_ref_obj = _clone_and_top_commits(
        folder, branch, branch_ref=True
    )

    for index in range(ncommits):
        # Create a file in that git repo
        if symlink_to:
            os.symlink(symlink_to, os.path.join(newfolder, filename))
        else:
            with open(os.path.join(newfolder, filename), "a") as stream:
                stream.write("Row %s\n" % index)
        repo.index.add(filename)
        repo.index.write()

        parents = []
        commit = None
        try:
            if branch_ref_obj:
                commit = repo[branch_ref_obj.peel().hex]
            else:
                commit = repo.revparse_single("HEAD")
        except (KeyError, AttributeError):
            pass
        if commit:
            parents = [commit.oid.hex]

        # Commits the files added
        tree = repo.index.write_tree()
        author = pygit2.Signature("Alice Author", "alice@authors.tld")
        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
        branch_ref = "refs/heads/%s" % branch
        repo.create_commit(
            branch_ref,
            author,
            committer,
            "Add row %s to %s file" % (index, filename),
            # binary string representing the tree object ID
            tree,
            # list of binary strings representing parents of the new commit
            parents,
        )
        branch_ref_obj = pagure.lib.git.get_branch_ref(repo, branch)

    # Push to origin
    ori_remote = repo.remotes[0]
    PagureRepo.push(ori_remote, "%s:%s" % (branch_ref, branch_ref))

    shutil.rmtree(newfolder) 
开发者ID:Pagure,项目名称:pagure,代码行数:54,代码来源:__init__.py


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