def test_repo_restore_project_deleted(nonempty_repo, project_type): """MetagitRepo.restore_project re-creates deleted projects.""" project = non_metagit_dir_project(nonempty_repo) config = project.get_config() rm_rf(project.path) nonempty_repo.restore_project(project_type(project.path)) assert config == project.get_config()
def test_repo_remove_project_nongit(nonempty_repo, project_type): """MetagitRepo.remove_project stops tracking projects that aren't Git repos.""" project = non_metagit_dir_project(nonempty_repo) rm_rf(project.path) project.path.mkdir() nonempty_repo.remove_project(project_type(project.path)) assert project not in nonempty_repo.projects()
def test_repo_status_deleted(nonempty_repo): """MetagitRepo.status discovers deleted projects.""" project = non_metagit_dir_project(nonempty_repo) rm_rf(project.path) deleted, modified, untracked = nonempty_repo.status() assert project in deleted assert len(deleted) == 1 assert not modified assert not untracked
def test_repo_status_deleted_nongit(nonempty_repo): """MetagitRepo.status discovers projects that are no longer Git repos.""" project = non_metagit_dir_project(nonempty_repo) rm_rf(project.path) project.path.mkdir() deleted, modified, untracked = nonempty_repo.status() assert project in deleted assert len(deleted) == 1 assert not modified assert not untracked
def test_diff_dirty(nonempty_repo): """`metagit diff` produces output in a dirty repository.""" runner = CliRunner() with runner.isolated_filesystem(): repo_path = nonempty_repo.path() project = non_metagit_dir_project(nonempty_repo) rm_rf(project.path) result = runner.invoke(cli.main, ["-C", repo_path, "diff"]) assert result.exit_code == 0 assert project.path.name in result.output
def test_status_modified(nonempty_repo): """`metagit status` produces output if a project has been modified.""" runner = CliRunner() with runner.isolated_filesystem(): repo_path = nonempty_repo.path() project = non_metagit_dir_project(nonempty_repo) rm_rf(project.path / ".git" / "config") result = runner.invoke(cli.main, ["-C", repo_path, "status"]) assert result.exit_code == 0 assert "Changes" in result.output assert "deleted" not in result.output assert "modified" in result.output assert project.path.name in result.output assert "Untracked" not in result.output
def test_restore(nonempty_repo): """`metagit restore` overwrites un-added changes to a project.""" runner = CliRunner() with runner.isolated_filesystem(): project = non_metagit_dir_project(nonempty_repo) rm_rf(project.path) assert nonempty_repo.diff_project(project) result = runner.invoke( cli.main, ["-C", nonempty_repo.path(), "restore", str(project.path)], ) assert result.exit_code == 0 assert result.output == "" assert not nonempty_repo.diff_project(project)
def test_repo_status_deleted_nongit_config(nonempty_repo, tmp_path): """MetagitRepo.status discovers non-Git projects that have a .git/config.""" project = non_metagit_dir_project(nonempty_repo) git_dir = Path(git.Repo(project.path).git_dir) tmp_config = tmp_path / "config" git_dir_config = git_dir / "config" os.link(git_dir_config, tmp_config) rm_rf(git_dir) git_dir.mkdir() tmp_config.rename(git_dir_config) deleted, modified, untracked = nonempty_repo.status() assert project in deleted assert len(deleted) == 1 assert not modified assert not untracked
def test_restore_relative(nonempty_repo): """`metagit restore` restores a project specified by relative path.""" runner = CliRunner() with runner.isolated_filesystem(): project = non_metagit_dir_project(nonempty_repo) rm_rf(project.path) assert nonempty_repo.diff_project(project) with runner.isolated_filesystem(): result = runner.invoke( cli.main, ["-C", nonempty_repo.path(), "restore", os.path.relpath(project.path)], ) assert result.exit_code == 0 assert result.output == "" assert not nonempty_repo.diff_project(project)
def test_repo_remove_project_nonexistent(nonempty_repo, project_type): """MetagitRepo.remove_project stops tracking projects that don't exist anymore.""" project = non_metagit_dir_project(nonempty_repo) rm_rf(project.path) nonempty_repo.remove_project(project_type(project.path)) assert project not in nonempty_repo.projects()
def test_repo_projects_deleted(nonempty_repo): """MetagitRepo.projects includes tracked projects that have been deleted.""" projects = set(nonempty_repo.projects()) rm_rf(non_metagit_dir_project(nonempty_repo).path) assert projects == set(nonempty_repo.projects())