Пример #1
0
def run(args: argparse.Namespace) -> None:
    workspace_path = args.workspace_path or Path.cwd()

    cfg_path = workspace_path / ".tsrc" / "config.yml"

    if cfg_path.exists():
        raise tsrc.Error(
            f"Workspace already configured. `{cfg_path}` already exists")

    ui.info_1("Configuring workspace in", ui.bold, workspace_path)

    workspace_config = WorkspaceConfig(
        manifest_url=args.manifest_url,
        manifest_branch=args.manifest_branch,
        clone_all_repos=args.clone_all_repos,
        repo_groups=args.groups or [],
        shallow_clones=args.shallow_clones,
        singular_remote=args.singular_remote,
    )

    workspace_config.save_to_file(cfg_path)

    workspace = Workspace(workspace_path)
    workspace.update_manifest()
    manifest = workspace.get_manifest()
    workspace.repos = repos_from_config(manifest, workspace_config)
    workspace.clone_missing()
    workspace.set_remotes()
    workspace.perform_filesystem_operations()
    ui.info_2("Workspace initialized")
    ui.info_2("Configuration written in", ui.bold, workspace.cfg_path)
Пример #2
0
def main(args: argparse.Namespace) -> None:
    path_as_str = args.workspace_path or os.getcwd()
    workspace_path = Path(path_as_str)
    cfg_path = workspace_path / ".tsrc" / "config.yml"

    if cfg_path.exists():
        raise tsrc.Error("Workspace already configured with file " + cfg_path)

    ui.info_1("Configuring workspace in", ui.bold, workspace_path)

    workspace_config = WorkspaceConfig(
        manifest_url=args.url,
        manifest_branch=args.branch,
        clone_all_repos=args.clone_all_repos,
        repo_groups=args.groups,
        shallow_clones=args.shallow,
    )

    workspace_config.save_to_file(cfg_path)

    workspace = Workspace(workspace_path)
    workspace.update_manifest()
    workspace.clone_missing()
    workspace.set_remotes()
    workspace.copy_files()
    ui.info_2("Workspace initialized")
    ui.info_2("Configuration written in", ui.bold, workspace.cfg_path)
Пример #3
0
def create_workspace(
    tmp_path: Path,
    *,
    repo_groups: Optional[List[str]] = None,
    clone_all_repos: bool = False,
) -> Workspace:
    config = WorkspaceConfig(
        manifest_url="[email protected]/manifest.git",
        manifest_branch="master",
        shallow_clones=False,
        clone_all_repos=clone_all_repos,
        repo_groups=repo_groups or [],
    )
    config.save_to_file(tmp_path / ".tsrc" / "config.yml")
    return Workspace(tmp_path)
Пример #4
0
def test_save(tmp_path: Path) -> None:
    """ Check that workspace config can be written
    and read.

    Note: the writing is done by `tsrc init`, all other
    commands simply read the file.
    """
    config = WorkspaceConfig(
        manifest_url="https://gitlab.example",
        manifest_branch="stable",
        shallow_clones=True,
        repo_groups=["default", "a-team"],
        clone_all_repos=False,
    )
    persistent_path = tmp_path / "config.yml"
    config.save_to_file(persistent_path)
    actual = WorkspaceConfig.from_file(persistent_path)
    assert actual == config
Пример #5
0
def init(
    url: str,
    workspace_path: Optional[Path] = None,
    groups: Optional[List[str]] = None,
    branch: str = "master",
    clone_all_repos: bool = False,
    shallow: bool = False,
    singular_remote: Optional[str] = None,
) -> None:
    """ initialize a new workspace"""
    path_as_str = workspace_path or os.getcwd()
    workspace_path = Path(path_as_str)
    cfg_path = workspace_path / ".tsrc" / "config.yml"

    if cfg_path.exists():
        raise tsrc.Error("Workspace already configured with file " + cfg_path)

    ui.info_1("Configuring workspace in", ui.bold, workspace_path)

    workspace_config = WorkspaceConfig(
        manifest_url=url,
        manifest_branch=branch,
        clone_all_repos=clone_all_repos,
        repo_groups=groups or [],
        shallow_clones=shallow,
        singular_remote=singular_remote,
    )

    workspace_config.save_to_file(cfg_path)

    workspace = Workspace(workspace_path)
    workspace.update_manifest()
    manifest = workspace.get_manifest()
    workspace.repos = repos_from_config(manifest, workspace_config)
    workspace.clone_missing()
    workspace.set_remotes()
    workspace.perform_filesystem_operations()
    ui.info_2("Workspace initialized")
    ui.info_2("Configuration written in", ui.bold, workspace.cfg_path)
Пример #6
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)
Пример #7
0
def change_workspace_manifest_branch(workspace_path: Path,
                                     branch: str) -> None:
    cfg_path = workspace_path / ".tsrc/config.yml"
    workspace_config = WorkspaceConfig.from_file(cfg_path)
    workspace_config.manifest_branch = branch
    workspace_config.save_to_file(cfg_path)