Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion copier/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,15 @@ def _apply_update(self) -> None: # noqa: C901
# Remove ".rej" suffix
fname = fname[:-4]
# Undo possible non-rejected chunks
git("checkout", "--", fname)
git(
# Ignore hooks to avoid errors from them or
# issues when .pre-commit-config.yaml is changed
"-c",
f"core.hooksPath={os.devnull}",
"checkout",
"--",
fname,
)
# 3-way-merge the file directly
git(
"merge-file",
Expand Down
90 changes: 89 additions & 1 deletion tests/test_updatediff.py
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def test_commit_hooks_respected(tmp_path_factory: pytest.TempPathFactory) -> Non
_templates_suffix: {SUFFIX_TMPL}
_tasks:
- git init
- pre-commit install -t pre-commit -t commit-msg
- pre-commit install
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
- pre-commit run -a || true
what: grog
"""
Expand All @@ -333,6 +333,10 @@ def test_commit_hooks_respected(tmp_path_factory: pytest.TempPathFactory) -> Non
),
".pre-commit-config.yaml": (
r"""
default_install_hook_types: [
pre-commit,
commit-msg,
]
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
repos:
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.0.4
Expand Down Expand Up @@ -480,6 +484,90 @@ def test_commit_hooks_respected(tmp_path_factory: pytest.TempPathFactory) -> Non
assert Path(f"{life}.rej").is_file()


# Checkout test_commit_hooks_respected
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
# FIXME Some generous Windows power user please fix this test!
@pytest.mark.xfail(
condition=platform.system() == "Windows", reason="Git broken on Windows?"
)
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
@pytest.mark.impure
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
def test_post_checkout_hook_ignored(tmp_path_factory: pytest.TempPathFactory) -> None:
"""Ignore post-checkout hook when conflicts are encountered."""
# Prepare source template v1
src, dst1 = map(tmp_path_factory.mktemp, ("src", "dst1"))
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
with local.cwd(src):
build_file_tree(
{
"copier.yml": (
f"""
_envops: {BRACKET_ENVOPS_JSON}
_templates_suffix: {SUFFIX_TMPL}
_tasks:
- git init
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
- git config --local core.hooksPath hooks/
- chmod +x hooks/post-checkout
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
"""
),
"[[ _copier_conf.answers_file ]].tmpl": (
"""
[[ _copier_answers|to_nice_yaml ]]
"""
),
"test.txt": "This is a file",
"hooks/post-checkout": (
r"""
echo "Post-checkout hook executed"
"""
),
}
)
git("init")
git("add", ".")
git("commit", "-m", "feat: commit 1")
git("tag", "v1")
# Copy source template
run_copy(
src_path=str(src),
dst_path=dst1,
defaults=True,
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
overwrite=False,
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
unsafe=True,
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
)
with local.cwd(dst1):
git("add", ".")
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
# Commit initial copy
git("commit", "-am", "feat: copied v1")
# Introduce conflict
Path(f"{dst1}/test.txt").open(mode="w").write("This is a conflicting change")
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
git("add", ".")
git("commit", "-am", "feat: edit test.txt")
# Evolve source template to v2
# No errors should be raised due to post-checkout hook
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
with local.cwd(src):
build_file_tree(
{
"test.txt": "This is a edited file in v2",
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
"hooks/post-checkout": (
r"""
exit 1
"""
),
}
)
git("init")
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
git("add", ".")
git("commit", "-m", "feat: Update post-checkout")
git("tag", "v2")
# Update subproject to v2
run_update(
dst_path=dst1,
defaults=True,
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
overwrite=True,
unsafe=True,
skip_tasks=True,
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
conflict="inline",
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
)


def test_update_from_tagged_to_head(tmp_path_factory: pytest.TempPathFactory) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
# Build a template
Expand Down