diff --git a/copier/_vcs.py b/copier/_vcs.py index 33c454455..3d3438ac3 100644 --- a/copier/_vcs.py +++ b/copier/_vcs.py @@ -212,7 +212,7 @@ def clone(url: str, ref: str | None = None) -> str: ) with local.cwd(location): - git("checkout", "-f", ref or "HEAD") + git("checkout", "-f", ref or "HEAD", "--", location) git("submodule", "update", "--checkout", "--init", "--recursive", "--force") return location diff --git a/tests/test_vcs.py b/tests/test_vcs.py index cd7dff14e..5606fdaf7 100644 --- a/tests/test_vcs.py +++ b/tests/test_vcs.py @@ -12,7 +12,7 @@ from copier._main import Worker from copier._user_data import load_answersfile_data from copier._vcs import checkout_latest_tag, clone, get_git_version, get_repo -from copier.errors import ShallowCloneWarning +from copier.errors import DirtyLocalWarning, ShallowCloneWarning from .helpers import git @@ -88,6 +88,26 @@ def test_local_clone() -> None: shutil.rmtree(local_tmp, ignore_errors=True) +@pytest.mark.impure +def test_local_dirty_clone() -> None: + tmp = clone("https://github.com/copier-org/autopretty.git") + assert tmp + assert Path(tmp, "copier.yml").exists() + + with local.cwd(tmp): + Path("unknown.txt").write_text("hello world") + Path("README.md").write_text("override string!!") + + with pytest.warns(DirtyLocalWarning): + local_tmp = clone(tmp) + + assert local_tmp + assert Path(local_tmp, "unknown.txt").exists() + assert Path(local_tmp, "README.md").exists() + assert Path(local_tmp, "copier.yaml").exists() + shutil.rmtree(local_tmp, ignore_errors=True) + + @pytest.mark.impure def test_shallow_clone(tmp_path: Path, recwarn: pytest.WarningsRecorder) -> None: # This test should always work but should be much slower if `is_git_shallow_repo()` is not