def test_add(repo): """`metagit add` tracks a project.""" runner = CliRunner() with runner.isolated_filesystem(): git_repo = git_repo_for_metagit_repo(repo) project = MetagitProject.for_path(git_repo.git_dir) assert project not in repo.projects() result = runner.invoke(cli.main, ["-C", repo.path(), "add", git_repo.git_dir]) assert result.exit_code == 0 assert result.output == "" assert project in repo.projects()
def test_status_untracked(repo): """`metagit status` produces output if there is an untracked project.""" runner = CliRunner() with runner.isolated_filesystem(): git_repo = git_repo_for_metagit_repo(repo) result = runner.invoke(cli.main, ["-C", repo.path(), "status"]) assert result.exit_code == 0 assert "Changes" not in result.output assert "Untracked" in result.output assert any( str(parent) in result.output for parent in Path(git_repo.git_dir).parents )
def nonempty_repo(tmp_path_factory): """Get a MetagitRepo that tracks at least one project (in addition to .metagit).""" repo = metagit.MetagitRepo.init( tmp_path_factory.mktemp("nonempty_projects")) repo.add_project(git_repo_for_metagit_repo(repo).git_dir) return repo
def test_repo_restore_untracked(empty_repo, project_type): """MetagitRepo.restore_project does NOT overwrite changes to untracked projects.""" git_repo = git_repo_for_metagit_repo(empty_repo) with pytest.raises(api.UntrackedProjectError, match=git_repo.git_dir): empty_repo.restore_project(project_type(git_repo.git_dir))
def test_repo_restore_project_invalid_repo(tmp_path, project_type): """MetagitRepo.restore_project raises an exception if the repo is invalid.""" repo = api.MetagitRepo(tmp_path / api.MetagitRepo.METAGIT_DIR_NAME) git_repo = git_repo_for_metagit_repo(repo) with pytest.raises(api.InvalidRepoError, match=str(repo.metagit_dir)): repo.restore_project(project_type(git_repo.git_dir))
def test_repo_diff_project_untracked(repo, tmp_path, project_type): """MetagitRepo.diff_project raises an exception for an untracked project.""" git_repo = git_repo_for_metagit_repo(repo) with pytest.raises(api.UntrackedProjectError, match=git_repo.git_dir): repo.diff_project(project_type(git_repo.git_dir))
def test_repo_diff_project_not_in_repo(repo, tmp_path, project_type): """MetagitRepo.diff_project raises an exception if a project is not in the repo.""" git_repo = git_repo_for_metagit_repo( api.MetagitRepo(tmp_path / api.MetagitRepo.METAGIT_DIR_NAME), ) with pytest.raises(api.NotInRepoError, match=str(tmp_path)): repo.diff_project(project_type(git_repo.git_dir))