def test_sha1s_are_skipped_when_not_clean( tsrc_cli: CLI, git_server: GitServer, workspace_path: Path ) -> None: """Scenario: * Create a manifest with a foo repo, frozen at an initial revision * Initialize a workspace from this manifest * Push a new file to the foo repo * Configure the manifest so that foo is frozen at the new revision * Create an untracked file in the foo repo * Run `tsrc sync` * Check that `tsrc sync` fails and that foo is not updated """ git_server.add_repo("foo") initial_sha1 = git_server.get_sha1("foo") git_server.manifest.set_repo_sha1("foo", initial_sha1) tsrc_cli.run("init", git_server.manifest_url) (workspace_path / "foo/untracked.txt").write_text("") git_server.push_file("foo", "new.txt") new_sha1 = git_server.get_sha1("foo") git_server.manifest.set_repo_sha1("foo", new_sha1) tsrc_cli.run_and_fail("sync") foo_path = workspace_path / "foo" assert not ( foo_path / "new.txt" ).exists(), "foo should not have been updated (untracked files)"
def test_sync_not_on_master( tsrc_cli: CLI, git_server: GitServer, workspace_path: Path, message_recorder: MessageRecorder, ) -> None: """ " Scenario: * Create a manifest with two repos, foo and bar * Initialize a workspace from this manifest * Checkout a different branch on foo, tracking an existing remote * Run `tsrc sync` * Check that: * foo is updated * but the command fails because foo was not an the expected branch """ git_server.add_repo("foo") git_server.add_repo("bar") git_server.push_file("foo", "devel.txt", branch="devel") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) foo_path = workspace_path / "foo" tsrc.git.run(foo_path, "checkout", "-B", "devel") tsrc.git.run(foo_path, "branch", "--set-upstream-to", "origin/devel") tsrc_cli.run_and_fail("sync") assert (foo_path / "devel.txt").exists(), "foo should have been updated" assert message_recorder.find("not on the correct branch")
def test_sync_with_errors( tsrc_cli: CLI, git_server: GitServer, workspace_path: Path, message_recorder: MessageRecorder, ) -> None: """ " Scenario: * Create a manifest with two repos (foo and bar) * Initialize a workspace from this manifest * Push a new file to the foo repo * Create a merge conflict in the foo repo * Run `tsrc sync` * Check that it fails and contains the proper error message """ git_server.add_repo("foo") git_server.add_repo("bar") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) git_server.push_file("foo", "conflict.txt", contents="this is red") foo_src = workspace_path / "foo" (foo_src / "conflict.txt").write_text("this is green") tsrc_cli.run_and_fail("sync") assert message_recorder.find("Failed to synchronize workspace") assert message_recorder.find(r"\* foo")
def test_empty_repo(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: """Scenario: * Create a manifest containing an empty repo * Check that `tsrc init` fails but does not crash """ git_server.add_repo("foo", empty=True) git_server.add_repo("bar") manifest_url = git_server.manifest_url tsrc_cli.run_and_fail("init", manifest_url)
def test_log_error(tsrc_cli: CLI, git_server: GitServer) -> None: """ Scenario: * Create a manifest with one repo, foo * Initialize a workspace from this manifest * Check that `tsrc log --from v0.1` fails (the `v0.1` tag does not exist) """ git_server.add_repo("foo") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) tsrc_cli.run_and_fail("log", "--from", "v0.1")
def test_shallow_with_fix_ref( tsrc_cli: CLI, git_server: GitServer, workspace_path: Path, message_recorder: MessageRecorder, ) -> None: git_server.add_repo("foo") initial_sha1 = git_server.get_sha1("foo") git_server.push_file("foo", "one.c") git_server.manifest.set_repo_sha1("foo", initial_sha1) manifest_url = git_server.manifest_url tsrc_cli.run_and_fail("init", "--shallow", manifest_url) assert message_recorder.find("Cannot use --shallow with a fixed sha1")
def test_foreach_with_errors(tsrc_cli: CLI, git_server: GitServer, message_recorder: MessageRecorder) -> None: """Scenario: * Create a repo 'foo' * Create a repo 'bar' containing 'stuff.txt' Check that tsr foreach -- ls stuff.txt fails, and prints the failing repo in the list of error """ git_server.add_repo("foo") git_server.add_repo("bar") git_server.push_file("bar", "stuff.txt", contents="some stuff") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) tsrc_cli.run_and_fail("foreach", "ls", "stuff.txt") assert message_recorder.find("Command failed") assert message_recorder.find(r"\* foo")
def test_copy_files_source_does_not_exist( tsrc_cli: CLI, git_server: GitServer, workspace_path: Path, message_recorder: MessageRecorder, ) -> None: """Scenario: * Crate a manifest with a 'top' repo * Configure the 'top' repo with a file copy from 'top.cmake' to 'CMakeLists.txt' * Check that `tsrc init` fails (the `top.cmake` file is missing from the 'top' repo) """ manifest_url = git_server.manifest_url git_server.add_repo("top") git_server.manifest.set_file_copy("top", "top.cmake", "CMakeLists.txt") tsrc_cli.run_and_fail("init", manifest_url) assert message_recorder.find("Failed to perform")
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")
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")
def test_changing_branch( tsrc_cli: CLI, git_server: GitServer, workspace_path: Path, message_recorder: MessageRecorder, ) -> None: """Scenario: * Create a manifest with a foo repo * Initialize a workspace from this manifest * Create a new branch named `next` on the foo repo * Update foo branch in the manifest * Run `tsrc sync` * Check that the command fails because `foo` is no longer on the expected branch """ git_server.add_repo("foo") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) git_server.push_file("foo", "next.txt", branch="next") git_server.manifest.set_repo_branch("foo", "next") tsrc_cli.run_and_fail("sync") assert message_recorder.find("not on the correct branch")
def test_cannot_init_twice(tsrc_cli: CLI, git_server: GitServer) -> None: manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) tsrc_cli.run_and_fail("init", manifest_url)
def test_cannot_start_cmd(tsrc_cli: CLI, git_server: GitServer) -> None: git_server.add_repo("foo") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) tsrc_cli.run_and_fail("foreach", "no-such")