コード例 #1
0
ファイル: sync.py プロジェクト: dmerejkowsky/tsrc
def run(args: argparse.Namespace) -> None:
    force = args.force
    update_manifest = args.update_manifest
    groups = args.groups
    all_cloned = args.all_cloned
    regex = args.regex
    iregex = args.iregex
    workspace = get_workspace(args)
    num_jobs = get_num_jobs(args)

    if update_manifest:
        ui.info_2("Updating manifest")
        workspace.update_manifest()
    else:
        ui.info_2("Not updating manifest")

    workspace.repos = resolve_repos(workspace,
                                    groups=groups,
                                    all_cloned=all_cloned,
                                    regex=regex,
                                    iregex=iregex)

    workspace.clone_missing(num_jobs=num_jobs)
    workspace.set_remotes(num_jobs=num_jobs)
    workspace.sync(force=force, num_jobs=num_jobs)
    workspace.perform_filesystem_operations()
    ui.info_1("Workspace synchronized")
コード例 #2
0
def test_no_args_no_config_no_default_group(tmp_path: Path) -> None:
    """ Scenario:
        * Nothing passed on the command line
        * No default group in the manifest
        * No workspace config

        Should return all repos in the manifest
        """
    create_manifest(tmp_path, repos=["foo", "bar"])
    workspace = create_workspace(tmp_path)
    actual = resolve_repos(workspace, groups=None, all_cloned=False)
    assert repo_names(actual) == ["foo", "bar"]
コード例 #3
0
def test_no_args_workspace_configured_with_all_repos(tmp_path: Path) -> None:
    """ Scenario:
        * Nothing passed on the command line
        * A default group in the manifest containing foo
        * A repo named 'outside' in the manifest - not in any group
        * Workspace configured with clone_all_repos: True

        Should return everything
        """
    groups = {
        "default": {"repos": ["foo"]},
    }
    create_manifest(tmp_path, repos=["foo", "outside"], groups=groups)
    workspace = create_workspace(tmp_path, clone_all_repos=True)

    actual = resolve_repos(workspace, groups=None, all_cloned=False)
    assert repo_names(actual) == ["foo", "outside"]
コード例 #4
0
def test_no_args_no_config_default_group(tmp_path: Path) -> None:
    """ Scenario:
        * Nothing passed on the command line
        * A default group in the manifest containing 'foo'
        * A repo named 'outside' in the manifest - not in any group
        * No workspace config

        Should use the default group
        """
    groups = {
        "default": {"repos": ["foo"]},
    }
    create_manifest(tmp_path, repos=["foo", "outside"], groups=groups)
    workspace = create_workspace(tmp_path)

    actual = resolve_repos(workspace, groups=None, all_cloned=False)
    assert repo_names(actual) == ["foo"]
コード例 #5
0
def test_no_args_workspace_configured_with_some_groups(tmp_path: Path) -> None:
    """ Scenario:
        * Nothing passed on the command line
        * A group named 'group1' in the manifest containing foo
        * A group named 'group2' in the manifest containing bar
        * Workspace configured with repo_groups=[group1]

        Should return foo from group1
        """
    groups = {
        "group1": {"repos": ["foo"]},
        "group2": {"repos": ["bar"]},
    }
    create_manifest(tmp_path, repos=["foo", "bar"], groups=groups)
    workspace = create_workspace(tmp_path, repo_groups=["group1"])

    actual = resolve_repos(workspace, groups=None, all_cloned=False)
    assert repo_names(actual) == ["foo"]
コード例 #6
0
def test_groups_requested(tmp_path: Path) -> None:
    """ Scenario:
        * A group named 'group1' in the manifest containing foo
        * A group named 'group2' in the manifest containing bar
        * Workspace configured with repo_groups=[group1, group2]
        * --group group1 used on the command line

        Should return repos from group1
        """
    groups = {
        "group1": {"repos": ["foo"]},
        "group2": {"repos": ["bar"]},
    }
    create_manifest(tmp_path, repos=["foo", "bar"], groups=groups)
    workspace = create_workspace(tmp_path, repo_groups=["group1"])

    actual = resolve_repos(workspace, groups=["group1"], all_cloned=False)
    assert repo_names(actual) == ["foo"]
コード例 #7
0
def test_filter_exclusive(tmp_path: Path) -> None:
    """Scenario:
    * A group named 'group1' in the manifest containing foo, foo2, bar, bar2
    * A repo named 'other' in the manifest
    * Workspace configured with repo_group=[group]
    * --group group1 used on the command line
    * -i foo used on the command line

    Should return repos bar and bar2 from group1
    """
    groups = {"group1": {"repos": ["foo", "foo2", "bar", "bar2"]}}
    create_manifest(
        tmp_path, repos=["foo", "foo2", "bar", "bar2", "other"], groups=groups
    )
    workspace = create_workspace(tmp_path, repo_groups=["group1"])

    actual = resolve_repos(workspace, groups=["group1"], all_cloned=False, iregex="foo")
    assert repo_names(actual) == ["bar", "bar2"]
コード例 #8
0
def sync(
    workspace_path: Optional[Path] = None,
    groups: Optional[List[str]] = None,
    all_cloned: bool = False,
    force: bool = False,
) -> None:
    """ synchronize the current workspace with the manifest """
    workspace = get_workspace(workspace_path)

    ui.info_2("Updating manifest")
    workspace.update_manifest()

    workspace.repos = resolve_repos(workspace,
                                    groups=groups,
                                    all_cloned=all_cloned)
    workspace.clone_missing()
    workspace.set_remotes()
    workspace.sync(force=force)
    workspace.perform_filesystem_operations()
    ui.info("Done", ui.check)
コード例 #9
0
def test_all_cloned_requested(tmp_path: Path) -> None:
    """ Scenario:
        * A group named 'group1' in the manifest containing foo and bar
        * A repo named 'other' in the manifest
        * Workspace configured with repo_groups=[group1]
        * tmp_path / foo and tmp_path / other exists, but not tmp_path / bar
        * --all-cloned used on the command line

        Should return foo and other
        """
    groups = {
        "group1": {"repos": ["foo", "bar"]},
    }
    create_manifest(tmp_path, repos=["foo", "bar", "other"], groups=groups)
    workspace = create_workspace(tmp_path, repo_groups=["group1"])

    (tmp_path / "foo").makedirs_p()
    (tmp_path / "other").makedirs_p()

    actual = resolve_repos(workspace, groups=None, all_cloned=True)
    assert repo_names(actual) == ["foo", "other"]
コード例 #10
0
def run(args: argparse.Namespace) -> None:
    force = args.force
    update_manifest = args.update_manifest
    groups = args.groups
    all_cloned = args.all_cloned

    workspace = get_workspace(args)

    if update_manifest:
        ui.info_2("Updating manifest")
        workspace.update_manifest()
    else:
        ui.info_2("Not updating manifest")

    workspace.repos = resolve_repos(workspace,
                                    groups=groups,
                                    all_cloned=all_cloned)

    workspace.clone_missing()
    workspace.set_remotes()
    workspace.sync(force=force)
    workspace.perform_filesystem_operations()
    ui.info("Done", ui.check)
コード例 #11
0
def local_sync(
    workspace_path: Optional[Path] = None,
    groups: Optional[List[str]] = None,
    all_cloned: bool = False,
    force: bool = False,
) -> None:
    """ synchronize the current workspace with the manifest """

    try:
        remote_url = subprocess.check_output('git config --get remote.origin.url', shell=True).decode('utf-8').replace('\n', '')
        cmd_string = "git rev-parse --abbrev-ref HEAD"
        remote_branch = subprocess.check_output(cmd_string, shell=True).decode('utf-8').replace('\n', '')
    except Exception:
        remote_url = False
        remote_branch = False

    workspace_config = WorkspaceConfig(
        manifest_url=remote_url,
        manifest_branch=remote_branch,
        clone_all_repos=False,
        repo_groups=[],
        shallow_clones=False,
        singular_remote=None,
    )
    cfg_path = Path(os.getcwd()) / ".tsrc" / "config.yml"
    workspace_config.save_to_file(cfg_path)

    workspace = get_workspace(workspace_path, local_file=True)
    update_manifest_local()

    workspace.repos = resolve_repos(workspace, groups=groups, all_cloned=all_cloned)
    workspace.clone_missing()
    workspace.set_remotes()
    workspace.sync(force=force)
    workspace.perform_filesystem_operations()
    ui.info("Done", ui.check)