def test_update_and_check_real_repo(tmpdir): tmpdir.chdir() repo = Repo.clone_from("https://github.com/timothycrosley/cruft", str(tmpdir)) repo.head.reset(commit="86a6e6beda8095690414ff7652c15b7ae36e6128", working_tree=True) with open(os.path.join(tmpdir, ".cruft.json")) as cruft_file: cruft_state = json.load(cruft_file) cruft_state["skip"] = ["cruft/__init__.py", "tests"] with open(os.path.join(tmpdir, ".cruft.json"), "w") as cruft_file: json.dump(cruft_state, cruft_file) repo_dir = Path(tmpdir) assert not cruft.check(repo_dir) # Update should fail since we have an unclean git repo assert not cruft.update(repo_dir) # Commit the changes so that the repo is clean run( [ "git", "-c", "user.name='test'", "-c", "user.email='*****@*****.**'", "commit", "-am", "test", ], cwd=repo_dir, ) assert cruft.update(repo_dir, skip_apply_ask=True)
def test_diff_git_subdir(capfd, tmpdir): tmpdir.chdir() temp_dir = Path(tmpdir) Repo.clone_from("https://github.com/cruft/cookiecutter-test", temp_dir) # Create something deeper in the git tree project_dir = cruft.create( "https://github.com/cruft/cookiecutter-test", Path("tmpdir/foo/bar"), directory="dir", checkout="master", ) # not added & committed assert not cruft.update(project_dir) # Add & commit the changes so that the repo is clean run(["git", "add", "."], cwd=temp_dir) run( [ "git", "-c", "user.name='test'", "-c", "user.email='*****@*****.**'", "commit", "-am", "test", ], cwd=temp_dir, ) assert cruft.update(project_dir, checkout="updated")
def test_update_allows_untracked_files_option(tmpdir): tmpdir.chdir() Repo.clone_from("https://github.com/timothycrosley/cruft", str(tmpdir)) with open(os.path.join(tmpdir, "untracked.txt"), "w") as new_file: new_file.write("hello, world!\n") repo_dir = Path(tmpdir) # update should fail since repo is now unclean (has a tracked file) assert not cruft.update(repo_dir) # update should work if allow_untracked_files is True assert cruft.update(repo_dir, allow_untracked_files=True)
def test_update_stores_checkout_value(value, tmpdir): tmpdir.chdir() cruft.create( "https://github.com/timothycrosley/cookiecutter-python", Path(tmpdir), checkout="ea8f733f85e7089df338d41ace199d3f4d397e29", ) project_dir = tmpdir / "python_project_name" cruft.update(Path(project_dir), checkout=value) assert json.load((project_dir / ".cruft.json").open("r"))["checkout"] == value
def test_directory_and_checkout(tmpdir): output_path = cruft.create( "https://github.com/samj1912/cookiecutter-test", output_dir=Path(tmpdir), directory="dir", checkout="initial", ) cruft_file = get_cruft_file(output_path) assert cruft_file.exists() assert cruft.check(output_path, checkout="initial") assert not cruft.check(output_path, checkout="updated") assert cruft.update(output_path, checkout="updated") assert cruft.check(output_path, checkout="updated") cruft_file.unlink() assert not cruft_file.exists() assert cruft.link( "https://github.com/samj1912/cookiecutter-test", project_dir=output_path, directory="dir", checkout="updated", ) assert cruft.check(output_path, checkout="updated") # Add checks for strictness where master is an older # version than updated assert not cruft.check(output_path, strict=True) assert cruft.check(output_path, strict=False)