Skip to content

fix(vcs): git checkout after clone must contains -- . #2151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion copier/_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion tests/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down