Esempio n. 1
0
def test_use_specific_groups(
    tsrc_cli: CLI, git_server: GitServer, workspace_path: Path
) -> None:
    """ Scenario:
    * the manifest contains two groups, 'foo' and 'spam'
    * the manifest contains one repo 'other'
    * the 'other' repo is configured with a file copy

    * the user runs `init --group foo, spam`

    * we don't want 'other' to be cloned
    * we don't want the file copy to be attempted
    """
    git_server.add_group("foo", ["bar", "baz"])
    git_server.add_group("spam", ["eggs", "beacon"])
    git_server.add_repo("other")
    git_server.push_file("other", "THANKS")
    git_server.manifest.set_repo_file_copies("other", [("THANKS", "THANKS.copy")])

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "--groups", "foo", "spam")

    assert_cloned(workspace_path, "bar")
    assert_cloned(workspace_path, "eggs")
    assert_not_cloned(workspace_path, "other")
Esempio n. 2
0
def test_use_given_group(
    tsrc_cli: CLI,
    git_server: GitServer,
    workspace_path: Path,
    message_recorder: MessageRecorder,
) -> None:
    """Scenario:
    * Create a manifest with two disjoint groups,
      group1 and group2
    * Initialize a workspace from this manifest using
      the two groups
    * Run `tsrc status --group group1`
    * Check that the output contains repos from group1, but not
      from group2
    """
    git_server.add_group("group1", ["foo"])
    git_server.add_group("group2", ["bar"])

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "--groups", "group1", "group2")

    message_recorder.reset()
    tsrc_cli.run("status", "--group", "group1")
    assert message_recorder.find(r"\* foo"), "foo status have been read"
    assert not message_recorder.find(r"\* bar"), "bar should have been skipped"
Esempio n. 3
0
    def test_can_use_new_group(tsrc_cli: CLI, git_server: GitServer,
                               workspace_path: Path) -> None:
        """Scenario:
        * Create a manifest containing:
          * a group named 'default'  containing the repos 'foo'  and 'bar'
        * Initialize a workspace from this manifest using the default group
        * Create a new group 'group1' containing just 'foo'
        * Push a new file to 'foo' and 'bar'
        * Run `tsrc sync --group 'group1'
        * Check only `foo` is updated
        """
        git_server.add_group("default", ["foo", "bar"])

        tsrc_cli.run("init", git_server.manifest_url)

        git_server.manifest.configure_group("group1", ["foo"])
        git_server.push_file("foo", "foo.txt")
        git_server.push_file("bar", "bar.txt")

        tsrc_cli.run("sync", "--group", "group1")

        assert (workspace_path / "foo/foo.txt").exists(
        ), "foo should have been updated - included in the 'group1 group"

        assert not (workspace_path / "bar/bar.txt").exists(), (
            "bar should not have been updated - not included in the 'group1 group"
        )
Esempio n. 4
0
def test_use_default_group(tsrc_cli: CLI, git_server: GitServer,
                           workspace_path: Path) -> None:
    git_server.add_group("default", ["a", "b"])
    git_server.add_repo("c")

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url)

    assert_cloned(workspace_path, "a")
    assert_not_cloned(workspace_path, "c")
Esempio n. 5
0
def test_custom_group(tsrc_cli: CLI, git_server: GitServer,
                      message_recorder: MessageRecorder) -> None:
    git_server.add_group("foo", ["bar", "baz"])
    git_server.add_repo("other")

    tsrc_cli.run("init", git_server.manifest_url, "--group", "foo")

    message_recorder.reset()
    tsrc_cli.run("sync")
    assert message_recorder.find("bar")
    assert not message_recorder.find("other")
Esempio n. 6
0
def test_clone_all_repos(tsrc_cli: CLI, git_server: GitServer,
                         workspace_path: Path) -> None:
    git_server.add_group("default", ["a", "b"])
    git_server.add_repo("orphan")

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "--clone-all-repos")

    assert_cloned(workspace_path, "a")
    assert_cloned(workspace_path, "b")
    assert_cloned(workspace_path, "orphan")
Esempio n. 7
0
def test_foreach_error_when_using_missing_groups(
        tsrc_cli: CLI, git_server: GitServer,
        message_recorder: MessageRecorder) -> None:
    git_server.add_group("foo", ["bar", "baz"])
    git_server.add_group("spam", ["eggs", "beacon"])

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "-g", "foo")

    message_recorder.reset()
    tsrc_cli.run("foreach", "-g", "foo", "-g", "spam", "ls", expect_fail=True)
Esempio n. 8
0
def test_use_specific_group(tsrc_cli: CLI, git_server: GitServer,
                            workspace_path: Path) -> None:
    git_server.add_group("foo", ["bar", "baz"])
    git_server.add_group("spam", ["eggs", "beacon"])
    git_server.add_repo("other")

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "-g", "foo", "-g", "spam")

    assert_cloned(workspace_path, "bar")
    assert_cloned(workspace_path, "eggs")
    assert_not_cloned(workspace_path, "other")
Esempio n. 9
0
def test_foreach_groups_warn_skipped(
        tsrc_cli: CLI, git_server: GitServer,
        message_recorder: MessageRecorder) -> None:
    git_server.add_group("foo", ["bar", "baz"])
    git_server.add_group("spam", ["eggs", "beacon"])
    git_server.add_repo("other")

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "-g", "foo")

    cmd = get_cmd_for_foreach_test(shell=False)

    message_recorder.reset()
    tsrc_cli.run("foreach", "-g", "foo", "-g", "spam", *cmd)
Esempio n. 10
0
    def test_non_existing_group(
        tsrc_cli: CLI, git_server: GitServer, workspace_path: Path
    ) -> None:
        """Scenario:
        * Create a manifest containing :
          * a group named 'group1'  containing the repo 'foo'
          * a group named 'group2'  containing the repo 'bar'
        * Initialize a workspace from this manifest using the 'group1' and 'group2' groups
        * Check that `tsrc sync --group no-such-group` fails
        """
        git_server.add_group("group1", ["foo"])
        git_server.add_group("group2", ["bar"])

        tsrc_cli.run("init", git_server.manifest_url)

        tsrc_cli.run_and_fail_with(GroupNotFound, "sync", "--group", "no-such-group")
Esempio n. 11
0
def test_foreach_with_groups_from_config(
        tsrc_cli: CLI, git_server: GitServer,
        message_recorder: MessageRecorder) -> None:
    git_server.add_group("foo", ["bar", "baz"])
    git_server.add_group("spam", ["eggs", "beacon"])
    git_server.add_repo("other")

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "--groups", "foo", "spam")

    message_recorder.reset()
    tsrc_cli.run("foreach", "--groups-from-config", "ls")

    assert message_recorder.find("bar\n")
    assert message_recorder.find("baz\n")
    assert message_recorder.find("eggs\n")
    assert not message_recorder.find("other\n")
Esempio n. 12
0
    def test_ignore_other_groups(
        tsrc_cli: CLI, git_server: GitServer, workspace_path: Path
    ) -> None:
        """Scenario:
        * Create a manifest containing:
          * a group named 'group1' containing the repos 'foo'  and 'bar'
          * a group named 'group2' containing the repo 'baz'
        * Initialize a workspace from this manifest using the `group1` and 'group2' groups
        * Push a new file to all three repos
        * Run `tsrc sync --group group1`
        * Add `quux` in `group2`
        * Add a copy from `baz/baz.txt` to `top.txt`
        * Check that `foo` and `bar` have been updated, but not `baz`
        * Check that `quux` has not been cloned
        * Check that `top` has not been created
        """
        git_server.add_group("group1", ["foo", "bar"])
        git_server.add_group("group2", ["baz"])

        tsrc_cli.run("init", git_server.manifest_url, "--groups", "group1", "group2")

        git_server.push_file("foo", "foo.txt")
        git_server.push_file("bar", "bar.txt")
        git_server.push_file("baz", "baz.txt")
        git_server.add_repo("quux")
        git_server.manifest.set_file_copy("baz", "baz.txt", "top.txt")
        git_server.manifest.configure_group("group2", ["baz", "quux"])

        tsrc_cli.run("sync", "--group", "group1")

        assert (
            workspace_path / "foo/foo.txt"
        ).exists(), "foo should have been updated (in group1 group)"
        assert (
            workspace_path / "bar/bar.txt"
        ).exists(), "bar  should have been updated (in group1 group)"
        assert not (
            workspace_path / "baz/baz.txt"
        ).exists(), "baz should not have been updated (not in group1 group)"
        assert not (
            workspace_path / "top.txt"
        ).exists(), "top.txt should not have been copied (not in group1 group)"
        assert not (
            workspace_path / "quux"
        ).exists(), "quux should not have been cloned (not in group1 group)"
Esempio n. 13
0
def test_foreach_error_when_using_missing_groups(
    tsrc_cli: CLI, git_server: GitServer, message_recorder: MessageRecorder
) -> None:
    """
    * Create a manifest containing:
       * a group named `foo` with repos `bar` and `baz`,
       * a group named `spam` with repos `eggs` and `beacon`
    * Initialize a workspace from this manifest, using the `foo` group
    * Check that `tsrc foreach ---groups foo spam --ls` fails
    """
    git_server.add_group("foo", ["bar", "baz"])
    git_server.add_group("spam", ["eggs", "beacon"])

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "--group", "foo")

    message_recorder.reset()
    tsrc_cli.run_and_fail("foreach", "--groups", "foo", "spam", "--", "ls")
Esempio n. 14
0
def test_foreach_with_explicit_groups(
        tsrc_cli: CLI, git_server: GitServer,
        message_recorder: MessageRecorder) -> None:
    git_server.add_group("foo", ["bar", "baz"])
    git_server.add_group("spam", ["eggs", "beacon"])
    git_server.add_repo("other")

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "--groups", "foo", "spam")

    cmd = get_cmd_for_foreach_test(shell=False)

    message_recorder.reset()
    tsrc_cli.run("foreach", "-g", "foo", *cmd)

    assert message_recorder.find("bar\n")
    assert message_recorder.find("baz\n")
    assert not message_recorder.find("eggs\n")
    assert not message_recorder.find("other\n")
Esempio n. 15
0
    def test_group_not_cloned(tsrc_cli: CLI, git_server: GitServer,
                              workspace_path: Path) -> None:
        """Scenario:
        * Create a manifest contaning :
          * a group named 'group1'  containing the repo 'foo'
          * a group named 'group2'  containing the repo 'bar'
        * Initialize a workspace from this manifest using the 'group1'
        * Check that `tsrc sync --group group2` adds the 'bar' repo
        """
        git_server.add_group("group1", ["foo"])
        git_server.add_group("group2", ["bar"])

        tsrc_cli.run("init", git_server.manifest_url, "--group", "group1")

        tsrc_cli.run("sync", "--group", "group2")

        assert (
            workspace_path /
            "bar").exists(), "bar should have been cloned when syncing group2"
Esempio n. 16
0
def test_missing_repos_from_given_group(
        tsrc_cli: CLI, git_server: GitServer,
        message_recorder: MessageRecorder) -> None:
    """
    Scenario:
    * Create a manifest with two disjoint groups, group1 and group2
    * For each repo, create  v0.1 tag
    * Initialize a workspace from this manifest using group1
    * Run `tsrc log --from v0.1 --groups group1 group2`
    * Check it fails
    """
    git_server.add_group("group1", ["foo"])
    git_server.add_group("group2", ["bar"])
    git_server.tag("foo", "v0.1")
    git_server.tag("bar", "v0.1")
    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "--group", "group1")

    message_recorder.reset()
    tsrc_cli.run_and_fail("log", "--from", "v0.1", "--groups", "group1",
                          "group2")
Esempio n. 17
0
def test_use_given_group(tsrc_cli: CLI, git_server: GitServer) -> None:
    """
    Scenario:
    * Create a manifest containing:
      * a group named 'group1' containing the repo 'foo'
      * a group named 'group2' containing the repo 'bar'
    * Initialize a workspace from this manifest using the 'group1' and
    'group2' groups
    * Create a tag named v0.1 on foo
    * Run `tsrc --log --from v0.1 --group group1`
    """

    git_server.add_group("group1", ["foo"])
    git_server.add_group("group2", ["bar"])

    manifest_url = git_server.manifest_url
    git_server.tag("foo", "v0.1")
    git_server.push_file("foo", "foo.txt", message="new foo!")

    tsrc_cli.run("init", manifest_url, "--groups", "group1", "group2")
    tsrc_cli.run("log", "--from", "v0.1", "--group", "group1")
Esempio n. 18
0
def test_use_non_cloned_group(
    tsrc_cli: CLI,
    git_server: GitServer,
    workspace_path: Path,
    message_recorder: MessageRecorder,
) -> None:
    """Scenario:
    * Create a manifest with two disjoint groups,
      group1 and group2
    * Initialize a workspace from this manifest using
      the group 'group1'
    * Run `tsrc status --group group2`
    * Check that it does not crash
    """
    git_server.add_group("group1", ["foo"])
    git_server.add_group("group2", ["bar"])

    manifest_url = git_server.manifest_url
    tsrc_cli.run("init", manifest_url, "--groups", "group1")

    message_recorder.reset()
    tsrc_cli.run("status", "--group", "group2")
Esempio n. 19
0
def test_sync_uses_group_from_config_by_default(tsrc_cli: CLI,
                                                git_server: GitServer,
                                                workspace_path: Path) -> None:
    """Scenario:
    * Create a manifest containing:
      * a group named 'foo'  containing the repos 'bar'  and 'baz'
      * a repo named 'other' not in any group
    * Initialize a workspace from this manifest using the `foo` group
    * Check that bar and baz are cloned
    * Check that `other` is not cloned
    """
    git_server.add_group("foo", ["bar", "baz"])
    git_server.add_repo("other")

    tsrc_cli.run("init", git_server.manifest_url, "--group", "foo")

    tsrc_cli.run("sync")

    assert (workspace_path /
            "bar").exists(), "bar should have been cloned (in foo group)"
    assert (workspace_path /
            "baz").exists(), "baz should have been cloned (in foo group)"
    assert not (workspace_path / "other").exists(
    ), "other should not have been cloned (not in foo group)"
Esempio n. 20
0
    def test_honors_new_included_groups(
        tsrc_cli: CLI, git_server: GitServer, workspace_path: Path
    ) -> None:
        """Scenario:
        * Create a manifest containing:
          * a group named 'group1'  containing the repos 'foo'  and 'bar'
          * a group named 'group2' containing the repo 'baz'
        * Initialize a workspace from this manifest using the 'group1' and 'group2' groups
        * Create a new group 'inc' containing the repo 'quux'
        * Update 'group1' group to include 'inc'
        * Run `tsrc sync --group 'group1'
        * Check that `quux` is cloned
        """
        git_server.add_group("group1", ["foo", "bar"])
        git_server.add_group("group2", ["baz"])
        tsrc_cli.run("init", git_server.manifest_url, "--groups", "group1", "group2")
        git_server.add_group("inc", ["quux"])
        git_server.manifest.configure_group("group1", ["foo", "bar"], includes=["inc"])

        tsrc_cli.run("sync", "--group", "group1")
        assert (
            workspace_path / "quux"
        ).exists(), "quux should have been cloned - included in the 'group1 group"