Example #1
0
def _get_repo(path: str, project: ProjectEntry) -> VCS:
    """Get the repo type from the project."""
    if not os.path.exists(project.destination):
        raise RuntimeError(
            "You cannot generate a diff of a project that was never fetched")
    main_project_dir = os.path.dirname(path)
    if GitLocalRepo(main_project_dir).is_git():
        return GitRepo(project)
    if SvnRepo.check_path(main_project_dir):
        return SvnRepo(project)

    raise RuntimeError("Can only create patch in SVN or Git repo", )
Example #2
0
def test_check(name, project, cmd_result, expectation):

    with patch("dfetch.project.svn.run_on_cmdline") as run_on_cmdline_mock:

        run_on_cmdline_mock.side_effect = cmd_result

        assert SvnRepo(project).check() == expectation
Example #3
0
def _import_projects() -> Sequence[ProjectEntry]:
    """Find out what type of VCS is used and import projects."""
    if GitRepo.check_path():
        projects = _import_from_git()
    elif SvnRepo.check_path():
        projects = _import_from_svn()
    else:
        raise RuntimeError(
            "Only git or SVN projects can be imported.",
            "Run this command within either a git or SVN repository",
        )
    return projects
Example #4
0
def test_externals(name, externals, expectations):

    with patch("dfetch.project.svn.run_on_cmdline") as run_on_cmdline_mock:
        with patch("dfetch.project.svn.SvnRepo._get_info_from_target"
                   ) as target_info_mock:
            with patch("dfetch.project.svn.os.getcwd") as cwd_mock:

                cmd_output = str(os.linesep * 2).join(externals)
                run_on_cmdline_mock().stdout = cmd_output.encode("utf-8")
                target_info_mock.return_value = {"Repository Root": REPO_ROOT}

                cwd_mock.return_value = CWD
                parsed_externals = SvnRepo.externals()

                for actual, expected in zip(parsed_externals, expectations):
                    assert actual == expected
Example #5
0
def _import_from_svn() -> Sequence[ProjectEntry]:
    projects: List[ProjectEntry] = []

    for external in SvnRepo.externals():
        projects.append(
            ProjectEntry({
                "name": external.name,
                "revision": external.revision,
                "url": external.url,
                "dst": external.path,
                "branch": external.branch,
                "tag": external.tag,
                "src": external.src,
            }))
        logger.info(f"Found {external.name}")

    return projects
Example #6
0
def test_get_info():

    with patch("dfetch.project.svn.run_on_cmdline") as run_on_cmdline_mock:

        run_on_cmdline_mock.return_value.stdout = os.linesep.join(
            SVN_INFO.split("\n")).encode()
        result = SvnRepo._get_info_from_target("bla")

        expectation = {
            "Path": "cpputest",
            "URL": "https://github.com/cpputest/cpputest",
            "Relative URL": "^/",
            "Repository Root": "https://github.com/cpputest/cpputest",
            "Repository UUID": "077c9a1d-76f4-0596-57cc-ce57b7db7bff",
            "Revision": "3976",
            "Node Kind": "directory",
            "Last Changed Author": "bas.vodde",
            "Last Changed Rev": "3976",
            "Last Changed Date": "2021-02-06 13:57:00 +0100 (za, 06 feb 2021)",
        }

        assert result == expectation