Skip to content

Commit

Permalink
test gitignored file
Browse files Browse the repository at this point in the history
a file in the template but gitignored in the project
should persist in the filesystem
  • Loading branch information
hparfr committed Nov 7, 2023
1 parent 5827d6a commit 9806d75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion copier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,15 @@ def _apply_update(self):
# Try to apply cached diff into final destination
with local.cwd(subproject_top):
apply_cmd = git["apply", "--reject", "--exclude", self.answers_relpath]
ignored_files = git["status", "--ignored", "--porcelain"]()
# returns "!! file1\n !! file2\n"
# extra_exclude will contain: ["file1", file2"]
extra_exclude = [
filename.split("!! ").pop()
for filename in ignored_files.splitlines()
]
for skip_pattern in chain(
self.skip_if_exists, self.template.skip_if_exists
self.skip_if_exists, self.template.skip_if_exists, extra_exclude
):
apply_cmd = apply_cmd["--exclude", skip_pattern]
(apply_cmd << diff)(retcode=None)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_updatediff.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ def test_file_removed(tmp_path_factory: pytest.TempPathFactory) -> None:
Path("dir 3", "subdir 3", "3.txt"): "content 3",
Path("dir 4", "subdir 4", "4.txt"): "content 4",
Path("dir 5", "subdir 5", "5.txt"): "content 5",
"toignore.txt": "should survive update",
}
)
git("init")
Expand Down Expand Up @@ -632,6 +633,7 @@ def test_file_removed(tmp_path_factory: pytest.TempPathFactory) -> None:
assert (dst / "dir 3" / "subdir 3" / "3.txt").is_file()
assert (dst / "dir 4" / "subdir 4" / "4.txt").is_file()
assert (dst / "dir 5" / "subdir 5" / "5.txt").is_file()
assert (dst / "toignore.txt").is_file()
assert (dst / "I.txt").is_file()
assert (dst / "dir II" / "II.txt").is_file()
assert (dst / "dir 3" / "subdir III" / "III.txt").is_file()
Expand All @@ -649,6 +651,9 @@ def test_file_removed(tmp_path_factory: pytest.TempPathFactory) -> None:
git("tag", "2")
# Subproject updates
with local.cwd(dst):
Path(".gitignore").write_text("toignore.txt")
git("add", ".gitignore")
git("commit", "-m", "ignore file")
with pytest.raises(
UserMessageError, match="Enable overwrite to update a subproject."
):
Expand All @@ -661,6 +666,7 @@ def test_file_removed(tmp_path_factory: pytest.TempPathFactory) -> None:
assert (dst / "dir 3" / "subdir III" / "III.txt").is_file()
assert (dst / "dir 4" / "subdir 4" / "IV.txt").is_file()
assert (dst / "6.txt").is_file()
assert (dst / "toignore.txt").is_file()
# Check what must not exist
assert not (dst / "1.txt").exists()
assert not (dst / "dir 2").exists()
Expand Down

0 comments on commit 9806d75

Please sign in to comment.