57 Commits

Author SHA1 Message Date
Sigurd Spieckermann
ef5ea4b212 refactor: rename internal modules with a _ prefix 2025-04-22 13:52:51 +02:00
Sigurd Spieckermann
b078959972 fix(updating): ignore last answer of when: false questions
A recorded answer may exist when the question's `when` value gets switched from `when: true` to `when: false`, e.g. when the value is templated or changes across Copier template versions.
2025-04-03 06:40:19 +02:00
David Linke
ca764db9c6
fix: explicitly specify file encoding for windows (#2007)
* Test for #2006; conflict in unicode content on windows

* Read files in binary mode to avoid encoding problems
2025-03-09 21:12:41 +00:00
Sigurd Spieckermann
ede686561d test: use helper function to load answers file data 2025-03-07 12:21:36 +01:00
Axel H.
33485117f5 test(migrations): use the new migration format in the test to avoid warnings 2025-03-03 14:37:27 +01:00
Sigurd Spieckermann
21b486ce75 fix: decode answers file content explicitly as UTF-8 2025-02-17 15:49:50 +01:00
Don
9ccabd4f12
fix(updating): don't crash when file is removed from template's .gitignore file (#1886) 2024-12-21 22:24:08 +01:00
Sigurd Spieckermann
89ecc2fd2b test: add test case for updating a Git submodule 2024-10-25 11:16:58 +02:00
Sigurd Spieckermann
b2f584d1a4 fix(updating): don't validate computed values 2024-10-21 19:29:35 +02:00
Timothée Mazzucotelli
f1cb4a2c9c
fix: Don't mark files without conflict markers as unmerged (#1813)
Co-authored-by: Jairo Llopis <973709+yajo@users.noreply.github.com>
2024-10-19 08:51:42 +01:00
Sigurd Spieckermann
04dc88165f fix: parse new answer when --skip-answered is used 2024-09-21 06:55:04 +01:00
Sigurd Spieckermann
9c1b86d4f9 perf(updating): avoid creating subproject copy 2024-08-29 19:49:02 +02:00
jeanluc
5ac93ee199
fix(updating): do not recreate deleted paths on update (#1719)
Previously, paths that matched a pattern in `skip_if_exists` and that were deleted in the generated project were recreated during each update. This was expected, because the file now didn't exist, and thus it's considered new. However, it might be surprising to some, so docs are updated and a test now makes that an officially supported use case.

For the rest of files, they shouldn't be recreated, even if the template changed. A user that deletes the file is kind of expressing their will to ignore that file from now on. To recover it, they can just recopy the template.

BREAKING CHANGE: If you delete a file in your subproject, it will not be recreated if it changes in the template and you update the subproject. Recopy if you need it back.
2024-08-17 08:44:09 +02:00
Sigurd Spieckermann
0258635da7 fix: support Git config without user identity 2024-07-30 13:40:17 +02:00
Sigurd Spieckermann
b4801b692e fix(updating): yield merge conflict when both template and project add same file 2024-04-18 15:26:49 +02:00
danieleades
878c4d4f40
style: add 'flake-future-annotations' lint group (#1506)
* add ruff 'flake8-future-annotations' (FA) lint group
2024-02-22 06:19:17 +00:00
Timothée Mazzucotelli
48d0c39629 feat: Conflicts on updates now appear as git merge conflicts, also on VSCode 2023-11-22 15:34:24 +00:00
Hpar
436b528c38
fix: keep git-ignored files on update (#1373) 2023-11-15 14:06:33 +01:00
Axel H
9ea980f713 build: test and advertise Python 3.12 support 2023-10-28 13:18:36 +02:00
Sigurd Spieckermann
a82c0ad6bf
refactor: drop support for Python 3.7 (#1252) 2023-07-18 19:59:05 +01:00
Sigurd Spieckermann
83f44cb4b6
feat: disable unsafe features by default and add --UNSAFE switch (#1171)
I've disabled the use of unsafe features (Jinja extensions, migrations, and tasks) by default and added a new CLI switch `--UNSAFE` which enables them. Templates that don't use unsafe features are unaffected by this change. But Copier will raise an error for templates that do use unsafe features unless the `--UNSAFE` flag is passed.

I've not added an interactive prompt that asks for consent for using unsafe features because I think it's not clear how to distinguish between interactive prompting and raising an error when `--UNSAFE` is not passed. For this, I think Copier would need a switch that clearly states whether interactive or non-interactive mode is desired. Currently, `--defaults` implies this for questions.

Fixes https://github.com/copier-org/copier/issues/1137

BREAKING CHANGE: Copier raises an error when a template uses unsafe features unless the `--UNSAFE` switch is passed
2023-06-01 18:22:40 +00:00
Jairo Llopis
6dde037423 refactor: overwrite always on updates
Updates not only overwrite files when actually updating, but also when applying the git diff.

Since only git-tracked subprojects can be updated, in reality there's no problem when overwriting. I find myself always overwriting and later fixing stuff with git tools.

BREAKING CHANGE: Updates will overwrite existing files always. If you need to select only some files, just use `git mergetool` or `git difftool` after updating.

BREAKING CHANGE: Flag `--overwrite/-w` disappeared from `copier update`. It is now implicit.

BREAKING CHANGE: To update via API, `overwrite=True` is now required.

Fix https://github.com/copier-org/copier/issues/741.
2023-05-30 07:34:22 +01:00
Jairo Llopis
2c5ff9e9b7 refactor(update): default to inline markers and 3 lines of context
Now that the inline mode is out of experimental, it turns out to provide a better default behavior than the good old rej mode. Mostly when context is increased to 3 lines or more.

BREAKING CHANGE: The default update conflict mode is now `inline` instead of `rej`.

BREAKING CHANGE: By default, updates now consider 3 lines of context instead of just 1.
2023-05-17 11:56:13 +01:00
Jairo Llopis
6996b9cc7a feat: add recopy command and function
This new command allows to reapply a template, keeping old answers but discarding subproject evolution.

It is useful when there are bugs replaying an old version of the template, or when the subproject has drifted too much from the template and you need to reset it.

BREAKING CHANGE: All CLI calls to Copier must now include the subcommand as the 1st argument. For example, `copier` must become now `copier update`; also `copier ./tpl ./dst` must become `copier copy ./tpl ./dst`.

BREAKING CHANGE: All flags must go after the subcommand now. For example, `copier -r HEAD update ./dst` must now become `copier update -r HEAD ./dst` or `copier update ./dst -r HEAD`.

BREAKING CHANGE: Automatic mode removed. Since now subcommands are required, the automatic mode is removed.

BREAKING CHANGE: Deprecated `copier.copy` function is removed. Use `copier.run_copy`, `copier.run_update` or `copier.run_recopy` explicitly as needed.

Fix https://github.com/copier-org/copier/issues/1081
Close https://github.com/copier-org/copier/issues/1082
2023-05-17 11:56:13 +01:00
Jairo Llopis
af628d9977
test: cover and fix the case of context lines through CLI calls too (#1104) 2023-04-17 12:59:21 +00:00
Jairo Llopis
1709d677ee feat: customizable update accuracy
Until today, the updatediff algorithm always used just 1 line of context when detecting conflicts. This was because:

- Solving conflicts wasn't very ergonomic with those `.rej` files around.
- More lines meant too many conflicts usually.

However, it made the diff detection less accurate.

With this change, we allow the users to configure that algorithm. Since they have now the `--context inline` option, more conflicts isn't so much of a problem.

@moduon MT-2638
2023-04-17 12:59:28 +01:00
Jairo Llopis
8987339e34 fix: properly support diffs over updates with new interactive answers
Just like 802d0f96548c3c8a0bf1128f8f18da4cf5ca05ad, but this time we make sure that interactive answers also work as expected.

Basically, I moved the creation of the updated and clean worker after the copying of the real destination worker. With this change, we can ask the user for answers and make sure we use them when producing the clean and updated copy.

@moduon MT-1075
2023-03-31 14:30:21 +01:00
Sigurd Spieckermann
b352841046 test: add return type hints 2023-03-31 06:27:36 +01:00
Sigurd Spieckermann
44bfafbbc3
feat: properly support update in repo subdirectory (#1069) 2023-03-31 06:15:41 +01:00
Sigurd Spieckermann
5295b9ef63
fix: ignore Git hooks during project update (#1066)
* add --no-verify to 2nd "dumb commit"

-> disable pre-commit-like checks to ensure that there won't be any more conflicts concerning this commit.

* test: extend test case

* style: reorder git commit flags

Fix https://github.com/copier-org/copier/issues/871

Co-authored-by: Nicolas <118367154+NicMar01@users.noreply.github.com>
2023-03-31 05:14:34 +00:00
Jairo Llopis
802d0f9654 fix: properly support diffs over updates with new answers
These answers could come from new user decisions or new template questions.

Before this patch, these answers were not being respected. The problem was even more evident with iline conflicts.

Possibly a regression produced in 504301c28eb4294fbb18473d759047c2db63b425. Or maybe it was there before and I didn't notice because `--conflict=inline` makes it more obvious.

@moduon MT-2675
2023-03-30 13:49:35 +01:00
Sigurd Spieckermann
5029b6e7a9
test: add type hints and clean up (#985)
* refactor(tests): add type hints and clean up

* fix: import `Protocol` from `typing-extensions` when using Python 3.7

* fix: import `Literal` from `typing-extensions` when using Python 3.7

* refactor(tests): create template and subproject directory using `tmp_path_factory` fixture

* refactor(tests): use OS-agnostic file path separator

* refactor(tests): use `/` separator for `skip_if_exists` paths

* style: fix formatting error

* refactor(tests): expect POSIX path for local repo URL
2023-03-21 16:31:11 +00:00
Sigurd Spieckermann
85fc136ce3 refactor(tests): remove unknown timeout marker 2023-02-27 18:41:57 +01:00
Jairo Llopis
67cc4ffde3
feat: nix support
- Provide a dev shell.
- Provide a nix package.
- Provide a nix flake.
- Development environment based on direnv.
- Docs.
- Configure Gitpod to use direnv and nix.
- Configure Cachix out of the box, and document how to use it.
- Add direnv and nix to CI.
- Satisfy some linters that came from Precommix, even when Precommix was later discarded.
- Mark some tests as impure.
- Run only pure tests when building Copier with Nix.
- Add poetry loader to direnv.
- Update contribution guide.
2023-01-18 09:40:08 +00:00
Barry Hart
504301c28e
feat: experimental inline conflict markers when updating
Fixes #613 

Based on #627, but:

* Supports both old (`.rej` files) and new (inline markers) conflict behavior

* Update a test to test both rej and inline conflict resolution

* Update some tests to explicitly specify "rej" conflict mode

* Add documentation for the two conflict modes

* keeping only 3-way merge

Co-authored-by: Oleh Prypin <oprypin@users.noreply.github.com>
Co-authored-by:
Thierry Guillemot <tguillemot@users.noreply.github.com>
Co-authored-by: Barry Hart <barry.hart@zoro.com>
Co-authored-by: Jairo Llopis <yajo.sk8@gmail.com>
Co-authored-by: Timothée Mazzucotelli <pawamoy@pm.me>
2022-11-14 05:09:23 +00:00
Jairo Llopis
db9a81d088 fix: wrong detection of untagged commits
I was wrongly using `.dev`. Use `.post`, just like dunamai.

Fixes https://github.com/copier-org/copier/issues/603.
2022-04-13 20:44:02 +01:00
Jairo Llopis
23dd5dbf8f fix: remove files on update
When a template gets updated and a file gets deleted within, subproject updates should delete that file automatically too.

Fix https://github.com/copier-org/copier/issues/461
2022-04-13 19:53:53 +01:00
Yajo
eb1425e5fc test: fix outdated prettier hook 2021-12-02 07:59:23 +00:00
Jairo Llopis
7bbd0406b8 feat: do not ask for overwriting copier answers file
The copier answers file (`.copier-answers.yml` by default) should be updated always, and everybody is almost excessively warned to NOT touch that file by hand and let Copier handle it. Thus, it makes no sense to ask users whether it should be updated on conflict.

Fixes https://github.com/copier-org/copier/issues/325.
2021-07-02 16:28:57 +01:00
Dennis Roche
a1fcccf906 test: Replace force=True with defaults=True, overwrite=True 2021-07-02 15:34:51 +01:00
Jairo Llopis
60f916017b fix: consider template skip_if_exists when updating
Fixes https://github.com/copier-org/copier/issues/369, which was a regression from the refactor.
2021-05-10 17:41:07 +01:00
Timothée Mazzucotelli
bd83f15bd6
feat: Add extensions option allowing to load additional Jinja2 extensions (#370)
Co-authored-by: Jairo Llopis <Yajo@users.noreply.github.com>
2021-03-27 22:07:56 +00:00
Jairo Llopis
f0a9d91b03
wip 2021-03-05 17:39:43 +00:00
Jairo Llopis
1482de4972
wip 2021-03-05 17:33:11 +00:00
Jairo Llopis
0441b86f0c
Refactor (#314)
* Refactor
* Fix #110.
* Rewrite test_config_exclude, test_config_exclude_overridden and test_config_include. These tests were badly designed, using a monkeypatch that would never happen in the real world, and actually producing false positives. I moved them to test_exclude.py and rewritten to test the what and not the how.
* Fix #214 by removing skip option. Relevant tests use the better skip_if_exists=["**"].
* Remove subdirectory flag from API/CLI. It was confusing and could lead to bad maintenance situations. Fixes #315.
* Remove extra_paths and fix #321
* Remember that you cannot use _copier_conf.src_path as a path now
* use dataclasses
* Create errors module, simplify some tests, fix many others
* Fix some tests, complete EnvOps removal
* Fix #214 and some tests related to it
* Reorder code
* Update docs and imports
* Modularize test_complex_questions
* Interlink worker and questionary a bit better
* Removal of Questionary class, which only had 1 meaningful method that is now merged into Worker to avoid circular dependencies.
* Fix #280 in a simple way: only user answers are type-casted inside API, and CLI transforms all `--data` using YAML always. Predictable.
* Use prereleases correctly.
* Reorder AnswersMap to have a more significative repr.
* Simpler cache for old `Question.get_choices()` method (renamed now).
* fix wrong test
* Fix test_subdirectory
* Fix test_tasks (and remove tests/demo_tasks)
* Fix path filter tests, and move it to test_exclude, where it belongs
* Make test_config pass
* Fix more wrongly designed tests
* Use cached_property backport if needed
* xfail test known to fail on mac
* force posix paths on windows
* Add typing_extensions for python < 3.8
* Sort dependencies in pyproject.toml
* Support python 3.6 str-to-datetime conversion
* Workaround https://bugs.python.org/issue43095
* xfail test_path_filter on windows
* Upgrade mkdocs and other dependencies to fix https://github.com/pawamoy/mkdocstrings/issues/222
* Add missing reference docs.
* Add workaround for https://github.com/pawamoy/mkdocstrings/pull/209
* Docs.
* Remove validators module
* Add workaround for https://github.com/pawamoy/mkdocstrings/issues/225
* Restore docs autorefs as explained in https://github.com/pawamoy/mkdocstrings/issues/226#issuecomment-775413562.
* Workaround https://github.com/pawamoy/pytkdocs/issues/86
2021-02-09 18:22:47 +00:00
Jairo Llopis
9f63d5075f Allow updating a shallow-cloned repo
Before this patch, if the repo you were updating was shallow, Copier failed to update it.

Now it should update any repo, no matter its depth. We only need to fetch 1 commit from it, after all.
2020-11-11 09:53:06 +00:00
Jairo Llopis
cda93273c1
Enhanced user input (#260)
* use a new toolkit for user prompting: questionary (patched).
* multiline questions.
* conditional questions.
* new toolkit for ui tests: pexpect.
* fix lots of tests.
* fix windows builds with newer poetry-dynamic-versioning.
* linters and mypy are now tests, to have faster ci.
* update deprecated ci commands.
* removed dependencies from old times.
* Remove toml 0.5+ syntax (dotted keys)
* Use powershell where syntax is compatible
* Change skip to xfail
* xfail pexpect tests on windows. I'm tired of trying to make it work
* more docs
* possibly something more.
2020-10-12 08:56:46 +01:00
Jairo Llopis
56bddd080e Remove --only-diff flag
This flag was not working fine, after all.

Also, the only difference between `copier copy` and `copier update` is that copying should ignore subproject history, while updating should respect it.

Thus, the real CLI reflection of the `only_diff` option is whether you're using `copier copy` or `copier update`. Well, that's how it is now.

Besides all this, the real behavior of `only_diff=False` wasn't being tested. Fixed also, and updated docs.

Fixes #270.
2020-09-18 11:21:04 +00:00
Jairo Llopis
9bd9400580 Windows fixes
- Ignore errors when executing `shutil.rmtree()`, because it seems like it's common to fail when deleting git repos on Windows, and since these are temp files, we don't really care that much there's garbage left. Any good OS should clean the temp folders automatically.
- Always find Jinja templates in `PosixPath` mode.
- Ignore `OSError` when trying to enter a possibly git root directory. This is yielded by Windows when the path is a URL and we don't really care about it.
- Fix some tests with non-windows hardcoded stuff.
- Fix a test that was using a Bash script. Modified to be Python, which should work fine cross-system.
- Remove external python dependencies (yaml, plumbum) from test task/migration files. These are available on Linux because it gets the python env from the venv, but on Windows, it uses the main python interpreter and breaks. After all, that's not very important here.
- Do not modify EOL in CI.
- Use python executable in tests instead of python3.
- Update pre-commit versions to include https://github.com/pre-commit/pre-commit-hooks/pull/509.
- Disable autorebasing.
- Disable pre-commit on CI on Windows.
- Require python 3.8 on Windows, where `tempfile` supports autoremoving directories with read-only files.
2020-08-08 15:27:56 +00:00
Jairo Llopis
823f3a1935 Remove dst fixture
This is redundant with pytest's native `tmp_path` fixture, so we use that one instead now.
2020-06-23 07:58:03 +00:00