def fixture_test_repo_and_workspace(tmpdir): """ Create a repository with a few test commits and a workspace containing a configured manifest :param tmpdir: Directory where to create repo (provided by pytest automatically) :return: Dict with information """ commits, source_repo = helpers.create_commits(tmpdir / "source") workspace = tmpdir / "workspace" workspace.mkdir() helpers.create_manifest( workspace, {"repos": [{ "url": str(tmpdir / "source" / ".git"), "path": "test" }]}) os.chdir(str(workspace)) return { "source_repo": source_repo, "workspace": workspace, "commits": commits, "tmpdir": tmpdir }
def test_sync_different_branch(synced_repo_and_workspace): """If we have a different branch checked out than the tracked branch we should switch to the correct branch even if it is behind""" data = synced_repo_and_workspace # Create a branch in the source repo that is behind master data["source_repo"].create_head("my_branch", data["commits"][5]) # Modify manifest to track the new branch helpers.create_manifest( data["workspace"], { "repos": [{ "url": str(data["tmpdir"] / "source/.git"), "path": "test", "track": "my_branch" }] }, ) # We are currently master assert data["dest_repo"].head.commit == data["commits"][0] assert data["dest_repo"].active_branch.name == "master" # Sync repo result = CliRunner().invoke(metarepo.cli.cli, ["sync"]) assert result.exit_code == 0 # We expect to be at the tracked branch now assert data["dest_repo"].head.commit == data["commits"][5] assert data["dest_repo"].active_branch.name == "my_branch"
def test_list_invalid_manifest(tmpdir): """Manifest is invalid""" helpers.create_manifest(tmpdir, {"whatever": []}) tmpdir.chdir() runner = CliRunner() result = runner.invoke(metarepo.cli.cli, ["list"]) assert result.exit_code == 1 assert "Validation failed" in result.output
def test_list_basic(tmpdir): """List configured repos in manifest""" helpers.create_manifest(tmpdir, {"repos": [{"url": "http://localhost/repo", "path": "the/path"}]}) tmpdir.chdir() runner = CliRunner() result = runner.invoke(metarepo.cli.cli, ["list"]) assert result.exit_code == 0 assert os.path.normpath("the/path") in result.output assert "http://localhost/repo" in result.output
def test_status_not_found(tmpdir): """Configure repo does not exist""" helpers.create_manifest(tmpdir, TEST_MANIFEST) tmpdir.chdir() runner = CliRunner() result = runner.invoke(metarepo.cli.cli, ["status"]) assert result.exit_code == 0 assert "NOT FOUND" in result.output
def test_status_wrong_origin(tmpdir): """Configured repo has the wrong origin""" helpers.create_commits(tmpdir.mkdir("the_repo"), "http://other/origin") helpers.create_manifest(tmpdir, TEST_MANIFEST) tmpdir.chdir() runner = CliRunner() result = runner.invoke(metarepo.cli.cli, ["status"]) assert result.exit_code == 0 assert "ORIGIN MISMATCH" in result.output
def test_status_invalid_repository(tmpdir): """Configured repo is invalid (just an empty folder)""" tmpdir.mkdir("the_repo") helpers.create_manifest(tmpdir, TEST_MANIFEST) tmpdir.chdir() runner = CliRunner() result = runner.invoke(metarepo.cli.cli, ["status"]) assert result.exit_code == 0 assert "INVALID" in result.output
def test_status_in_repo_subdirectory(tmpdir): """Run status in a subdirectory of a repo should still work""" helpers.create_commits(tmpdir) helpers.create_manifest(tmpdir, TEST_MANIFEST) tmpdir.mkdir("some").mkdir("folder").chdir() runner = CliRunner() result = runner.invoke(metarepo.cli.cli, ["status"]) assert result.exit_code == 0 assert "the_repo" in result.output
def test_status_exists(tmpdir): """Configure repo exist and is clean""" helpers.create_commits(tmpdir.join("the_repo"), TEST_MANIFEST_ORIGIN) helpers.create_manifest(tmpdir, TEST_MANIFEST) tmpdir.chdir() runner = CliRunner() result = runner.invoke(metarepo.cli.cli, ["status"]) assert result.exit_code == 0 assert re.search(r"head:.{0,5}master", result.output) assert re.search(r"dirty:.{0,5}False", result.output)
def test_status_no_recurse_on_folder(tmpdir): """Workspace is a repository and the configure repository is just an empty folder Should report the repo as invalid and not recursively search in parents""" helpers.create_commits(tmpdir) helpers.create_manifest(tmpdir, TEST_MANIFEST) tmpdir.chdir() # Repository is just an empty folder tmpdir.mkdir("the_repo") runner = CliRunner() result = runner.invoke(metarepo.cli.cli, ["status"]) assert result.exit_code == 0 assert "INVALID" in result.output