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


Python pygit2.Repository方法代码示例

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


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

示例1: test_request_pull_reference

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def test_request_pull_reference(self):
        """ Test if there is a reference created for a new PR. """

        tests.create_projects(self.session)
        tests.create_projects_git(
            os.path.join(self.path, "requests"), bare=True
        )

        set_up_git_repo(
            self.session, self.path, new_project=None, branch_from="feature"
        )

        project = pagure.lib.query.get_authorized_project(self.session, "test")
        self.assertEqual(len(project.requests), 1)

        # View the pull-request
        output = self.app.get("/test/pull-request/1")
        self.assertEqual(output.status_code, 200)

        gitrepo = os.path.join(self.path, "repos", "test.git")
        repo = pygit2.Repository(gitrepo)
        self.assertEqual(
            list(repo.listall_references()),
            ["refs/heads/feature", "refs/heads/master", "refs/pull/1/head"],
        ) 
开发者ID:Pagure,项目名称:pagure,代码行数:27,代码来源:test_pagure_flask_ui_fork.py

示例2: setUp

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def setUp(self):
        """ Set up the environnment, ran before every tests. """
        super(PagureFlaskUiArchivesTest, self).setUp()
        tests.create_projects(self.session)
        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
        project = pagure.lib.query._get_project(self.session, "test")

        # test has both commits and tags
        repopath = os.path.join(self.path, "repos", "test.git")
        tests.add_readme_git_repo(repopath)
        repo = pygit2.Repository(repopath)
        add_repo_tag(self.path, repo, ["v1.0", "v1.1"], "test.git")

        # test2 has only commits
        tests.add_readme_git_repo(
            os.path.join(self.path, "repos", "test2.git")
        )

        # somenamespace/test3 has neither commits nor tags

        # Create the archive folder:
        self.archive_path = os.path.join(self.path, "archives")
        os.mkdir(self.archive_path) 
开发者ID:Pagure,项目名称:pagure,代码行数:25,代码来源:test_pagure_flask_ui_archives.py

示例3: test_project_w_commit_tar_gz

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def test_project_w_commit_tar_gz(self):
        """ Test getting the archive from a commit. """
        repopath = os.path.join(self.path, "repos", "test.git")
        repo = pygit2.Repository(repopath)
        commit = repo.head.target.hex
        with mock.patch.dict(
            "pagure.config.config",
            {"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
        ):
            output = self.app.get(
                "/test/archive/%s/test-v1.0.tar.gz" % commit,
                follow_redirects=True,
            )

            self.assertEqual(output.status_code, 200)

        self.assertEqual(os.listdir(self.archive_path), ["test"])
        self.assertEqual(
            os.listdir(os.path.join(self.archive_path, "test")), [commit]
        )
        self.assertEqual(
            os.listdir(os.path.join(self.archive_path, "test", commit)),
            ["test-v1.0.tar.gz"],
        ) 
开发者ID:Pagure,项目名称:pagure,代码行数:26,代码来源:test_pagure_flask_ui_archives.py

示例4: test_view_history_file_on_tag

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [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

示例5: test_view_blame_file_default_branch_non_master

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def test_view_blame_file_default_branch_non_master(self):
        """ Test the view_blame_file endpoint """
        repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
        reference = repo.lookup_reference("refs/heads/feature").resolve()
        repo.set_head(reference.name)
        output = self.app.get("/test/blame/sources")
        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>bar</code></pre></td>', output_text
        )
        self.assertIn('<td class="cell_user">Aritz Author</td>', output_text)
        data = self.regex.findall(output_text)
        self.assertEqual(len(data), 3) 
开发者ID:Pagure,项目名称:pagure,代码行数:23,代码来源:test_pagure_flask_ui_repo_view_blame.py

示例6: test_view_blame_file_unborn_head_no_identifier

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def test_view_blame_file_unborn_head_no_identifier(self):
        repo_obj = pygit2.Repository(
            os.path.join(self.path, "repos", "test.git")
        )
        repo_obj.set_head("refs/heads/unexistent")

        output = self.app.get("/test/blame/sources")
        self.assertEqual(output.status_code, 404)
        output_text = output.get_data(as_text=True)
        self.assertIn(
            "<title>Page not found :'( - Pagure</title>", output_text
        )
        self.assertIn("<h2>Page not found (404)</h2>", output_text)
        self.assertIn(
            "<p>Identifier is mandatory on unborn HEAD repos</p>", output_text
        ) 
开发者ID:Pagure,项目名称:pagure,代码行数:18,代码来源:test_pagure_flask_ui_repo_view_blame.py

示例7: test_view_file_from_commit

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def test_view_file_from_commit(self):
        repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
        commit = repo.revparse_single("HEAD")

        output = self.app.get("/api/0/test/tree/%s" % commit.oid.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" % commit.oid.hex,
                        "name": "README.rst",
                        "path": "README.rst",
                        "type": "file",
                    }
                ],
                "name": None,
                "type": "folder",
            },
        ) 
开发者ID:Pagure,项目名称:pagure,代码行数:25,代码来源:test_pagure_flask_api_project_view_file.py

示例8: test_api_new_git_branch_json

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def test_api_new_git_branch_json(self):
        """ Test the api_new_branch method of the flask api """
        tests.create_projects(self.session)
        repo_path = os.path.join(self.path, "repos")
        tests.create_projects_git(repo_path, bare=True)
        tests.add_content_git_repo(os.path.join(repo_path, "test.git"))
        tests.create_tokens(self.session, project_id=None)
        tests.create_tokens_acl(self.session, "aaabbbcccddd", "create_branch")
        headers = {
            "Authorization": "token aaabbbcccddd",
            "Content-Type": "application/json",
        }
        args = {"branch": "test123"}
        output = self.app.post(
            "/api/0/test/git/branch", headers=headers, data=json.dumps(args)
        )
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.get_data(as_text=True))
        expected_output = {"message": "Project branch was created"}
        self.assertEqual(data, expected_output)
        git_path = os.path.join(self.path, "repos", "test.git")
        repo_obj = pygit2.Repository(git_path)
        self.assertIn("test123", repo_obj.listall_branches()) 
开发者ID:Pagure,项目名称:pagure,代码行数:25,代码来源:test_pagure_flask_api_project.py

示例9: test_api_new_git_branch_from_branch

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def test_api_new_git_branch_from_branch(self):
        """ Test the api_new_branch method of the flask api """
        tests.create_projects(self.session)
        repo_path = os.path.join(self.path, "repos")
        tests.create_projects_git(repo_path, bare=True)
        tests.add_content_git_repo(os.path.join(repo_path, "test.git"))
        tests.create_tokens(self.session, project_id=None)
        tests.create_tokens_acl(self.session, "aaabbbcccddd", "create_branch")
        git_path = os.path.join(self.path, "repos", "test.git")
        repo_obj = pygit2.Repository(git_path)
        parent = pagure.lib.git.get_branch_ref(repo_obj, "master").peel()
        repo_obj.create_branch("dev123", parent)
        headers = {"Authorization": "token aaabbbcccddd"}
        args = {"branch": "test123", "from_branch": "dev123"}
        output = self.app.post(
            "/api/0/test/git/branch", headers=headers, data=args
        )
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.get_data(as_text=True))
        expected_output = {"message": "Project branch was created"}
        self.assertEqual(data, expected_output)
        self.assertIn("test123", repo_obj.listall_branches()) 
开发者ID:Pagure,项目名称:pagure,代码行数:24,代码来源:test_pagure_flask_api_project.py

示例10: test_api_new_git_branch_from_commit

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def test_api_new_git_branch_from_commit(self):
        """ Test the api_new_branch method of the flask api """
        tests.create_projects(self.session)
        repos_path = os.path.join(self.path, "repos")
        tests.create_projects_git(repos_path, bare=True)
        git_path = os.path.join(repos_path, "test.git")
        tests.add_content_git_repo(git_path)
        tests.create_tokens(self.session, project_id=None)
        tests.create_tokens_acl(self.session, "aaabbbcccddd", "create_branch")
        repo_obj = pygit2.Repository(git_path)
        from_commit = repo_obj.revparse_single("HEAD").oid.hex
        headers = {"Authorization": "token aaabbbcccddd"}
        args = {"branch": "test123", "from_commit": from_commit}
        output = self.app.post(
            "/api/0/test/git/branch", headers=headers, data=args
        )
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.get_data(as_text=True))
        expected_output = {"message": "Project branch was created"}
        self.assertEqual(data, expected_output)
        self.assertIn("test123", repo_obj.listall_branches()) 
开发者ID:Pagure,项目名称:pagure,代码行数:23,代码来源:test_pagure_flask_api_project.py

示例11: test_set_default_branch

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def test_set_default_branch(self):
        """ Test the set-default-branch funcion of pagure-admin. """

        gitrepo_path = os.path.join(self.path, "repos", "test.git")
        tests.add_content_git_repo(gitrepo_path)
        tests.add_commit_git_repo(gitrepo_path, branch="dev")

        # Check default branch before:
        gitrepo = pygit2.Repository(gitrepo_path)
        self.assertEqual(gitrepo.head.shorthand, "master")

        args = munch.Munch({"project": "test", "user": None, "branch": "dev"})

        with tests.capture_output() as output:
            pagure.cli.admin.do_set_default_branch(args)
        output = output.getvalue()
        self.assertEqual("Branch dev set as default\n", output)

        # Check default branch after:
        self.assertEqual(gitrepo.head.shorthand, "dev") 
开发者ID:Pagure,项目名称:pagure,代码行数:22,代码来源:test_pagure_admin.py

示例12: install

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def install(cls, project, dbobj):
        """ Method called to install the hook for a project.

        :arg project: a ``pagure.model.Project`` object to which the hook
            should be installed

        """
        repopaths = [get_repo_path(project)]

        repo_obj = pygit2.Repository(repopaths[0])  # noqa

        # Configure the hook
        # repo_obj.config.set_multivar()

        # Install the hook itself
        # cls.base_install(repopaths, dbobj, 'irc', 'git_irc.py') 
开发者ID:Pagure,项目名称:pagure,代码行数:18,代码来源:irc.py

示例13: delete_branch

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def delete_branch(self, session, name, namespace, user, branchname):
    """ Delete a branch from a git repo.
    """
    project = pagure.lib.query._get_project(
        session, namespace=namespace, name=name, user=user
    )

    with project.lock("WORKER"):
        repo_obj = pygit2.Repository(pagure.utils.get_repo_path(project))

        try:
            branch = repo_obj.lookup_branch(branchname)
            branch.delete()
        except pygit2.GitError as err:
            _log.exception(err)

    return ret(
        "ui_ns.view_branches", repo=name, namespace=namespace, username=user
    ) 
开发者ID:Pagure,项目名称:pagure,代码行数:21,代码来源:tasks.py

示例14: commits_history_stats

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def commits_history_stats(self, session, repopath):
    """ Returns the evolution of the commits made against the specified
    git repository.
    """

    if not os.path.exists(repopath):
        raise ValueError("Git repository not found.")

    repo_obj = pygit2.Repository(repopath)

    dates = collections.defaultdict(int)
    for commit in repo_obj.walk(
        repo_obj.head.peel().oid.hex, pygit2.GIT_SORT_NONE
    ):
        delta = (
            datetime.datetime.utcnow() - arrow.get(commit.commit_time).naive
        )
        if delta.days > 365:
            break
        dates[arrow.get(commit.commit_time).date().isoformat()] += 1

    return [(key, dates[key]) for key in sorted(dates)] 
开发者ID:Pagure,项目名称:pagure,代码行数:24,代码来源:tasks.py

示例15: __init__

# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import Repository [as 别名]
def __init__(self, path=None, ref=None, **kwargs):
        """

        Parameters
        ----------
        path: str (optional)
            Local location of the repo (uses current directory if not given)
        ref: str (optional)
            Reference to work with, could be a hash, tag or branch name. Defaults
            to current working tree. Note that ``ls`` and ``open`` also take hash,
            so this becomes the default for those operations
        kwargs
        """
        super().__init__(**kwargs)
        self.repo = pygit2.Repository(path or os.getcwd())
        self.ref = ref or "master" 
开发者ID:intake,项目名称:filesystem_spec,代码行数:18,代码来源:git.py


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