|
7 | 7 | import pytest |
8 | 8 | from packaging.version import Version |
9 | 9 | from plumbum import local |
| 10 | +from pytest_gitconfig.plugin import GitConfig |
10 | 11 |
|
11 | 12 | from copier import run_copy, run_update |
12 | 13 | from copier._main import Worker |
13 | 14 | from copier._user_data import load_answersfile_data |
14 | 15 | from copier._vcs import checkout_latest_tag, clone, get_git_version, get_repo |
15 | | -from copier.errors import ShallowCloneWarning |
| 16 | +from copier.errors import DirtyLocalWarning, ShallowCloneWarning |
16 | 17 |
|
17 | | -from .helpers import git |
| 18 | +from .helpers import build_file_tree, git, git_save |
18 | 19 |
|
19 | 20 |
|
20 | 21 | def test_get_repo() -> None: |
@@ -88,6 +89,33 @@ def test_local_clone() -> None: |
88 | 89 | shutil.rmtree(local_tmp, ignore_errors=True) |
89 | 90 |
|
90 | 91 |
|
| 92 | +def test_local_dirty_clone( |
| 93 | + tmp_path_factory: pytest.TempPathFactory, gitconfig: GitConfig |
| 94 | +) -> None: |
| 95 | + """ |
| 96 | + When core.fsmonitor is enabled, normal `git checkout` command won't works. |
| 97 | + """ |
| 98 | + |
| 99 | + gitconfig.set({"core.fsmonitor": "true"}) |
| 100 | + src = tmp_path_factory.mktemp("src") |
| 101 | + print(src) |
| 102 | + |
| 103 | + build_file_tree({src / "version.txt": "0.1.0"}) |
| 104 | + git_save(src) |
| 105 | + |
| 106 | + build_file_tree({src / "version.txt": "0.2.0", src / "README.md": "hello world"}) |
| 107 | + |
| 108 | + with pytest.warns(DirtyLocalWarning): |
| 109 | + local_tmp = clone(str(src)) |
| 110 | + |
| 111 | + assert local_tmp |
| 112 | + assert Path(local_tmp, "version.txt").exists() |
| 113 | + assert Path(local_tmp, "version.txt").read_text() == "0.2.0" |
| 114 | + assert Path(local_tmp, "README.md").exists() |
| 115 | + assert Path(local_tmp, "README.md").read_text() == "hello world" |
| 116 | + shutil.rmtree(local_tmp, ignore_errors=True) |
| 117 | + |
| 118 | + |
91 | 119 | @pytest.mark.impure |
92 | 120 | def test_shallow_clone(tmp_path: Path, recwarn: pytest.WarningsRecorder) -> None: |
93 | 121 | # This test should always work but should be much slower if `is_git_shallow_repo()` is not |
|
0 commit comments