Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
72 changes: 72 additions & 0 deletions tests/test_updatediff.py
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import platform
import stat
from pathlib import Path
from shutil import rmtree
from textwrap import dedent
Expand Down Expand Up @@ -480,6 +481,77 @@ def test_commit_hooks_respected(tmp_path_factory: pytest.TempPathFactory) -> Non
assert Path(f"{life}.rej").is_file()


@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, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
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
"""
),
"[[ _copier_conf.answers_file ]].tmpl": (
"""
[[ _copier_answers|to_nice_yaml ]]
"""
),
"test.txt": "This is a file",
}
)
git("init")
git("add", ".")
git("commit", "-m", "feat: commit 1")
git("tag", "v1")
# Copy source template
run_copy(
src_path=str(src),
dst_path=dst,
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(dst):
git("add", ".")
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
# Commit initial copy
git("commit", "-am", "feat: copied v1")
# Introduce conflict
Path(dst / "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")
# Add post-checkout hook that fails
hook_file = dst / ".git" / "hooks" / "post-checkout"
Comment thread
TheSuperiorStanislav marked this conversation as resolved.
Outdated
hook_file.write_text("exit 1")
hook_file.chmod(hook_file.stat().st_mode | stat.S_IXUSR)
# Evolve source template to v2
with local.cwd(src):
build_file_tree(
{
"test.txt": "This is an edited file in v2",
}
)
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
# No errors should be raised due to post-checkout hook
run_update(
dst_path=dst,
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