57 Commits

Author SHA1 Message Date
Jairo Llopis
6d7ab7f941
Update diff fixes
- Do not produce contextless diff (`--unified=0`), as it leads to weird results sometimes. `.rej` files provide a saner output. Actually https://git-scm.com/docs/git-apply#Documentation/git-apply.txt---unidiff-zero recommends not using contextless patches.
- Ask `git diff` to *never* join 2 code hunks, even if they are only separated by 1 line (`--inter-hunk-context=-1`). This gives Copier most chances to reduce the amount of rejected hunks.
- When a template is to be reformatted by a pre-commit hook after copy, make sure git hooks are respected, so the updated diff matches reality more closely.
- Add and use a new helper to comfortably build a file tree from a test, to provide a way to avoid having dangling sample trees and git samples.

@Tecnativa TT20357
2020-04-08 11:51:44 +01:00
Jairo Llopis
80105bb86c
Fix base copy answers
When somebody calls `copier update` to reapply a template, respecting subproject evolution, but just to apply some changes to some answers, the updatediff system reverted those changes.

Now they are respected, so if calling `copier update` with new data, that new data will be applied to the subproject.

The basic fix is that when creating the temporary copy in the old commit (the one used to compare), it is created using last answers obtained from the subproject, excluding any new answers passed by the user.

#169 improved the situation but certainly it didn't fix it completely. This hardened test proves it works better now.
2020-04-06 13:46:42 +01:00
Jairo Llopis
a00624eaa8
Fix updates getting diffed without proper answers
There was a bug in how update diff was computed. As you can see, the temporary copy that was made to produce that diff didn't get the same answers as the current project. Thus, every time the user answered something different, a diff was generated and a `.rej` file was created.

Just try this and you'll see:

```bash
copier -f update
git add .
git commit -m updated
copier -f update
git status
```

The 2nd time you update, all files should be identical and untouched. However, that wasn't the case.

I took the chance to update this test's fixture from `dst` to `tmpdir`, which is more standard and comfortable to debug.

@Tecnativa TT20357
2020-03-27 12:36:04 +00:00
Jairo Llopis
17939b1d6a
Supply the copier binary and install it in CI
Fix #133.
2020-02-27 10:54:42 +00:00
Jairo Llopis
6bf0cedd3a
Add migrations support
This commit fixes #119. Summary:

- Depend on packaging to get a good implementation of PEP 440.
- Document new behaviors.
- Add support for migrations.
- Checkout by default the most modern git tag available in the template.
- Reuse `run_tasks` to run migrations too.
- Use `git describe --tags --always` to obtain template commit, to get a version parseable by PEP 440.
- Update `test_updatediff` to with new behaviors.

@Tecnativa TT20357
2020-02-21 13:52:35 +00:00
Jairo Llopis
f3b95d8bcd
Sort answers file
This way it will be more readable and it will produce less diff if the template copier.yml file is updated.

@Tecnativa TT20357
2020-01-31 10:38:12 +00:00
Jairo Llopis
1f2ce1ed25
Updates respecting evolved git history
Fix #88 the easiest way possible. Changes summary:

- A new `--vcs-ref` flag that indicates which commit/ref you want to copy, and only applies when the source directory is git-versioned.
- A new `--no-diff` flag to `copier update` skips the smartypants diff behavior.

What it does?

- Checks you are updating a git-versioned destination from a git-versioned source.
- Clones the destination into temp dir.
- Does a `copier copy -f tmp_src tmp_dst` (yes, a temp dir also).
- Gets the git diff between `tmp_dst` and `dst_path`.
- Performs a normal `copier update dst_path`.
- Applies the git diff at the end, to try to respect downstream project evolution.

@Tecnativa TT20357
2020-01-23 12:38:57 +00:00