def test_tags_are_skipped_when_not_clean_tags( tsrc_cli: CLI, git_server: GitServer, workspace_path: Path ) -> None: """Scenario: * Create a manifest with a foo repo, frozen at the v0.1 tag * Initialize a workspace from this manifest * Push a new file to the foo repo * Create a new v0.2 tag on the foo repo * Configure the manifest so that foo is frozen at the v0.2 tag * Create an untracked file in the foo repo * Check that `tsrc sync` fails and that foo is not updated """ git_server.add_repo("foo") git_server.tag("foo", "v0.1") git_server.manifest.set_repo_tag("foo", "v0.1") tsrc_cli.run("init", git_server.manifest_url) (workspace_path / "foo/untracked.txt").write_text("") git_server.push_file("foo", "new.txt") git_server.tag("foo", "v0.2") git_server.manifest.set_repo_tag("foo", "v0.2") 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_with_force( tsrc_cli: CLI, git_server: GitServer, workspace_path: Path ) -> None: """ Scenario: * Create a manifest with one repo, foo * Create a tag `latest` on foo * Initialize a workspace from this manifest * Delete and re-create the `latest` tag * Run tsrc sync --force * Check that the clone was reset to the correct revision (aka, `git fetch --force` was called). """ git_server.add_repo("foo") git_server.push_file("foo", "latest.txt", contents="1") git_server.tag("foo", "latest") tsrc_cli.run("init", git_server.manifest_url) git_server.push_file("foo", "latest.txt", contents="2") git_server.tag("foo", "latest", force=True) tsrc_cli.run("sync", "--force") foo_path = workspace_path / "foo" assert ( foo_path / "latest.txt" ).read_text() == "2", "foo should have been reset to the latest tag"
def test_tags_are_updated_when_clean( tsrc_cli: CLI, git_server: GitServer, workspace_path: Path ) -> None: """Scenario: * Create a manifest with a foo repo, frozen at the v0.1 tag * Initialize a workspace from this manifest * Push a new file to the foo repo * Create a new v0.2 tag on the foo repo * Configure the manifest so that `foo` is frozen at the v0.2 tag * Run `tsrc sync` * Check that foo has been updated to the `v0.2` tag """ git_server.add_repo("foo") git_server.tag("foo", "v0.1") git_server.manifest.set_repo_tag("foo", "v0.1") tsrc_cli.run("init", git_server.manifest_url) git_server.push_file("foo", "new.txt") git_server.tag("foo", "v0.2") git_server.manifest.set_repo_tag("foo", "v0.2") tsrc_cli.run("sync") foo_path = workspace_path / "foo" assert ( foo_path / "new.txt" ).exists(), "foo should have been updated to the v0.2 tag"
def test_happy(tsrc_cli: CLI, git_server: GitServer, message_recorder: MessageRecorder) -> None: """ Scenario: * Create a manifest with two repos, foo and bar * Initialize a workspace from this manifest * Create a tag named v0.1 on foo and bar * Run `tsrc log --from v0.1 """ git_server.add_repo("foo") git_server.add_repo("spam") git_server.push_file("foo", "bar.txt", message="boring bar") git_server.tag("foo", "v0.1") git_server.tag("spam", "v0.1") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) git_server.push_file("foo", "foo.txt", message="new foo!") tsrc_cli.run("sync") message_recorder.reset() tsrc_cli.run("log", "--from", "v0.1") assert message_recorder.find("new foo!") message_recorder.reset() tsrc_cli.run("log", "--from", "v0.1", "--to", "v0.1") assert not message_recorder.find("new foo!")
def test_sync_with_force(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: git_server.add_repo("foo") git_server.push_file("foo", "latest.txt", contents="1") git_server.tag("foo", "latest") tsrc_cli.run("init", git_server.manifest_url) git_server.push_file("foo", "latest.txt", contents="2") git_server.tag("foo", "latest", force=True) tsrc_cli.run("sync", "--force")
def test_tags_are_not_updated(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: git_server.add_repo("foo") git_server.tag("foo", "v0.1") git_server.manifest.set_repo_tag("foo", "v0.1") tsrc_cli.run("init", git_server.manifest_url) git_server.push_file("foo", "new.txt") tsrc_cli.run("sync") foo_path = workspace_path / "foo" assert not (foo_path / "new.txt").exists()
def test_resets_to_tag(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: git_server.add_repo("foo") git_server.tag("foo", "v1.0") git_server.push_file("foo", "2.txt", message="Working on v2") git_server.manifest.set_repo_tag("foo", "v1.0") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) foo_path = workspace_path / "foo" _, expected_ref = tsrc.git.run_captured(foo_path, "rev-parse", "v1.0") _, actual_ref = tsrc.git.run_captured(foo_path, "rev-parse", "HEAD") assert expected_ref == actual_ref
def test_tags_are_skipped_when_not_clean_tags(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: git_server.add_repo("foo") git_server.tag("foo", "v0.1") git_server.manifest.set_repo_tag("foo", "v0.1") tsrc_cli.run("init", git_server.manifest_url) (workspace_path / "foo/untracked.txt").write_text("") git_server.push_file("foo", "new.txt") git_server.tag("foo", "v0.2") git_server.manifest.set_repo_tag("foo", "v0.2") tsrc_cli.run("sync", expect_fail=True) foo_path = workspace_path / "foo" assert not (foo_path / "new.txt").exists()
def test_happy(tsrc_cli: CLI, git_server: GitServer, message_recorder: MessageRecorder) -> None: git_server.add_repo("foo") git_server.add_repo("spam") git_server.push_file("foo", "bar.txt", message="boring bar") git_server.tag("foo", "v0.1") git_server.tag("spam", "v0.1") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) git_server.push_file("foo", "foo.txt", message="new foo!") tsrc_cli.run("sync") message_recorder.reset() tsrc_cli.run("log", "--from", "v0.1") assert message_recorder.find("new foo!") message_recorder.reset() tsrc_cli.run("log", "--from", "v0.1", "--to", "v0.1") assert not message_recorder.find("new foo!")
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_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")
def test_resets_to_tag(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: """Scenario: * Create a repository containing a v1.0 tag * Add a commit on top of the v1.0 tag * Configure the manifest to specify that the repo should be reset at the v1.0 tag * Run `tsrc init` * Check the repo was cloned at the correct revision """ git_server.add_repo("foo") git_server.tag("foo", "v1.0") git_server.push_file("foo", "2.txt", message="Working on v2") git_server.manifest.set_repo_tag("foo", "v1.0") manifest_url = git_server.manifest_url tsrc_cli.run("init", manifest_url) foo_path = workspace_path / "foo" _, expected_ref = tsrc.git.run_captured(foo_path, "rev-parse", "v1.0") _, actual_ref = tsrc.git.run_captured(foo_path, "rev-parse", "HEAD") assert expected_ref == actual_ref
def test_tags_are_not_updated(tsrc_cli: CLI, git_server: GitServer, workspace_path: Path) -> None: """Scenario: * Create a manifest with a foo repo, frozen at the `v0.1` tag * Initialize a workspace from this manifest * Push a new file to the foo repo * Run `tsrc sync` * Check that foo was not updated """ git_server.add_repo("foo") git_server.tag("foo", "v0.1") git_server.manifest.set_repo_tag("foo", "v0.1") tsrc_cli.run("init", git_server.manifest_url) git_server.push_file("foo", "new.txt") tsrc_cli.run("sync") foo_path = workspace_path / "foo" assert not (foo_path / "new.txt").exists( ), "foo should not have been updated (frozen at v0.1 tag)"
def test_git_server_tag(workspace_path: Path, git_server: GitServer) -> None: foo_url = git_server.add_repo("foo") git_server.tag("foo", "v0.1") _, out = tsrc.git.run_captured(workspace_path, "ls-remote", foo_url) assert "refs/tags/v0.1" in out
def test_tag(workspace_path: Path, git_server: GitServer) -> None: foo_url = git_server.add_repo("foo") git_server.tag("foo", "v0.1", branch="master") _, out = run_git_captured(workspace_path, "ls-remote", foo_url) assert "refs/tags/v0.1" in out