def test_git_detect_root(tmpdir): """Get the root of the repository""" helpers.create_commits(tmpdir, REPO_URL) tmpdir.mkdir("a").mkdir("b").mkdir("c") repo = vcs_git.RepoTool(tmpdir.join("a/b/c"), REPO_URL, search_parent=True) assert repo.get_root_path() == tmpdir
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_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
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_git_status(tmpdir): """Check status of a clean repository""" commits, _ = helpers.create_commits(tmpdir, REPO_URL) repo = vcs_git.RepoTool(tmpdir, REPO_URL) status = repo.get_status() assert not status.is_dirty assert not status.is_detached assert status.active_branch.name == "master" assert status.head == commits[0] assert status.untracked_files == []
def test_git_status_dirty(tmpdir): """Check status of a repository with modified files""" commits, _ = helpers.create_commits(tmpdir, REPO_URL) tmpdir.join("output.txt").write("Edit") repo = vcs_git.RepoTool(tmpdir, REPO_URL) status = repo.get_status() assert status.is_dirty assert not status.is_detached assert status.active_branch.name == "master" assert status.head == commits[0] assert status.untracked_files == []
def test_git_status_detached_head(tmpdir): """Check status of a repository with a detached head""" commits, test_repo = helpers.create_commits(tmpdir, REPO_URL) test_repo.git.checkout(commits[3]) repo = vcs_git.RepoTool(tmpdir, REPO_URL) status = repo.get_status() assert not status.is_dirty assert status.is_detached assert status.active_branch is None assert status.head == commits[3] assert status.untracked_files == []