Пример #1
0
    def test_raises_version_control_error_when_git_command_fails(
            self, mock_repo):
        mock_repo(
        ).git.symbolic_ref.side_effect = git_utils.git.exc.GitCommandError(
            "git symbolic_ref", 255)

        with pytest.raises(VersionControlError):
            git_utils.get_default_branch(mock_repo())
Пример #2
0
    def checkout(self, force: bool) -> None:
        """Check out all resolved libs to revision specified in .lib files."""
        for lib in self.iter_resolved():
            repo = git_utils.get_repo(lib.source_code_path)
            git_ref = lib.get_git_reference()

            if not git_ref.ref:
                git_ref.ref = git_utils.get_default_branch(repo)

            git_utils.fetch(repo, git_ref.ref)
            git_utils.checkout(repo, "FETCH_HEAD", force=force)
Пример #3
0
    def checkout(self, force: bool) -> None:
        """Check out all resolved libs to revision specified in .lib files."""
        for lib in self.iter_resolved():
            repo = git_utils.get_repo(lib.source_code_path)
            git_ref = lib.get_git_reference()

            if not git_ref.ref:
                repo.git.fetch()
                git_ref.ref = git_utils.get_default_branch(repo)
            else:
                # Fetch only the requested ref
                repo.git.fetch("origin", git_ref.ref)

            git_utils.checkout(repo, git_ref.ref, force=force)
Пример #4
0
def _print_dependency_table(libs: List) -> None:
    click.echo("The following library dependencies were fetched: \n")
    table = []
    for lib in libs:
        table.append([
            lib.reference_file.stem,
            lib.get_git_reference().repo_url,
            lib.source_code_path,
            git_utils.get_default_branch(
                git_utils.get_repo(lib.source_code_path)) if
            not lib.get_git_reference().ref else lib.get_git_reference().ref,
        ])

    headers = ("Library Name", "Repository URL", "Path", "Git Reference")
    click.echo(tabulate.tabulate(table, headers=headers))
Пример #5
0
    def test_returns_default_branch_name(self, mock_repo):
        mock_repo().git.symbolic_ref.return_value = "refs/remotes/origin/main"

        branch_name = git_utils.get_default_branch(mock_repo())

        assert branch_name == "main"