-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
feat: include local dirty changes by default. fixes #184 #520
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
94e712c
feat: include local dirty changes by default
sabard 4f27e2b
fix: create commit in temporary directory
sabard d925445
fix: add and test DirtyLocalWarning
sabard 75d943d
fix: remove tmp dir in clone
sabard 8c7cddc
style: rebase changes
sabard 15177a8
style: PR changes
sabard b78a85d
fix: remove python 3.7 incomaptiable code and fix CI error
sabard 7f68825
refactor: create new git dir for dirty changes, but do not copy
sabard 32dad69
fix: PR change
sabard 2d072d5
docs: update changelog
sabard 49e4fbd
fix: typo
sabard 1973f52
fix: final small PR changes
sabard 3cb102b
fix: make dirty copy work on update by cloning first
sabard 4c58e62
fix: potential windows CI fix and style
sabard d74ec86
fix: get better error message on windows failing CI
sabard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import os | ||
from pathlib import Path | ||
from shutil import copy2, copytree | ||
|
||
import pytest | ||
from plumbum import local | ||
from plumbum.cmd import git | ||
|
||
import copier | ||
from copier.errors import DirtyLocalWarning | ||
from copier.main import run_copy, run_update | ||
|
||
from .helpers import DATA, PROJECT_TEMPLATE, build_file_tree, filecmp | ||
|
||
|
||
def test_copy(tmp_path_factory): | ||
src, dst = map(tmp_path_factory.mktemp, ("src", "dst")) | ||
|
||
# dirs_exist_ok not available in Python 3.7 | ||
for item in os.listdir(PROJECT_TEMPLATE): | ||
item_src_path = os.path.join(PROJECT_TEMPLATE, item) | ||
item_dst_path = os.path.join(src, item) | ||
if os.path.isdir(item_src_path): | ||
copytree(item_src_path, item_dst_path) | ||
else: | ||
copy2(item_src_path, item_dst_path) | ||
|
||
with local.cwd(src): | ||
git("init") | ||
|
||
with pytest.warns(DirtyLocalWarning): | ||
sabard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
copier.copy(str(src), str(dst), data=DATA, quiet=True) | ||
|
||
generated = (dst / "pyproject.toml").read_text() | ||
control = (Path(__file__).parent / "reference_files" / "pyproject.toml").read_text() | ||
assert generated == control | ||
|
||
# assert template still dirty | ||
with local.cwd(src): | ||
assert bool(git("status", "--porcelain").strip()) | ||
|
||
|
||
def test_update(tmp_path_factory): | ||
src, dst = map(tmp_path_factory.mktemp, ("src", "dst")) | ||
|
||
build_file_tree( | ||
{ | ||
src | ||
/ ".copier-answers.yml.jinja": """\ | ||
# Changes here will be overwritten by Copier | ||
{{ _copier_answers|to_nice_yaml }} | ||
""", | ||
src | ||
/ "copier.yml": """\ | ||
_envops: | ||
"keep_trailing_newline": True | ||
""", | ||
src | ||
/ "aaaa.txt": """ | ||
Lorem ipsum | ||
""", | ||
src | ||
/ "to_delete.txt": """ | ||
yajo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
delete me. | ||
""", | ||
} | ||
) | ||
|
||
with local.cwd(src): | ||
git("init") | ||
git("add", "-A") | ||
git("commit", "-m", "first commit on src") | ||
|
||
run_copy(str(src), dst, defaults=True, overwrite=True) | ||
|
||
with local.cwd(src): | ||
# test adding a file | ||
with open("test_file.txt", "w") as f: | ||
f.write("Test content") | ||
|
||
# test updating a file | ||
with open("aaaa.txt", "a") as f: | ||
f.write("dolor sit amet") | ||
|
||
# test removing a file | ||
os.remove("to_delete.txt") | ||
|
||
# dst must be vcs-tracked to use run_update | ||
with local.cwd(dst): | ||
git("init") | ||
git("add", "-A") | ||
git("commit", "-m", "first commit on dst") | ||
|
||
# make sure changes have not yet propagated | ||
assert not os.path.exists(dst / "test_file.txt") | ||
|
||
p1 = str(src / "aaaa.txt") | ||
p2 = str(dst / "aaaa.txt") | ||
assert not filecmp.cmp(p1, p2) | ||
|
||
assert os.path.exists(dst / "to_delete.txt") | ||
|
||
with pytest.warns(DirtyLocalWarning): | ||
run_update(dst, defaults=True, overwrite=True) | ||
|
||
# make sure changes propagate after update | ||
assert os.path.exists(dst / "test_file.txt") | ||
|
||
p1 = str(src / "aaaa.txt") | ||
p2 = str(dst / "aaaa.txt") | ||
filecmp.clear_cache() | ||
assert filecmp.cmp(p1, p2) | ||
yajo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# HACK https://github.com/copier-org/copier/issues/461 | ||
# TODO test file deletion on update | ||
# assert not os.path.exists(dst / "to_delete.txt") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got the feeling that this block should be done before importing the ditty changes. However, if the test goes green I guess I'm just wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it shouldn't matter if it runs before or after. But if there is no HEAD in the case of a recently intialized repo, then this fails and would need to be called after as well. I also realized that specifying
ref
means that dirty changes won't be considered and so added that to the dirty checking logic.