copier icon indicating copy to clipboard operation
copier copied to clipboard

`copier update` on dst_path that's **not** the root of the repository doesn't merge gracefully

Open mhoeger opened this issue 2 years ago • 4 comments

Whenever I create a copier project not at the repository root level of the, update doesn't work as I would expect (changes I made locally just get overwritten).

Behavior with answers file at root dir (what I expect):

  1. copier "gh:my/repo" .
  2. Add minor change and commit change locally
  3. copier update
  4. Conflict found in changed file, but on overwriting, no change is actually made

Behavior when answers file not at root (what I don't expect):

  1. copier "gh:my/repo" project
  2. Add minor change and commit change locally
  3. copier update project
  4. Conflict found in change, and contents I added are completely overwritten

This is for 6.0.0 and 5.1.0

I'd like to be able to run copier update project where project is a directory checked into the repo because I'm trying to use copier to generate projects in a monorepo.

mhoeger avatar May 21 '22 02:05 mhoeger

@yajo - I think too at a bare minimum, it would be great for *.rej files to be generated instead of contents being completely overwritten to be whatever the latest template's contents are!

Also - would this not be fixed any time soon because it's a breaking change?

mhoeger avatar May 23 '22 19:05 mhoeger

Sorry for not answering before! I'm having trouble to understand the use case. 🤔

Would you be able to provide some steps that reproduce it on any machine, so I can test it and see the problem?

Thanks!

yajo avatar May 26 '22 16:05 yajo

We have a similar use case. Our application repo should contains out of different copier projects:

application_repo
│── .git
├── temp1  # created via copier path/template1 temp1
│   │── .copier-answers.yml
│   ├── config.conf
│   └── main.py
└── temp2  # created via copier path/template2 temp2
    │── .copier-answers.yml
    └── main.py

With copier 6.1.0 we are not able to update these templates (temp1, temp2).

I tried the following commands to update the template 1:

pqraus@dev:~/application_repo$ copier update /temp1
Updating is only supported in git-tracked subprojects.

pqraus@dev:~/application_repo$ copier -a temp1/.copier-answers.yml update
No git tags found in template; using HEAD as ref
Updating to template version 0.0.0.post6.dev0+ed53ccf
Traceback (most recent call last):
...
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/copier.main.update_diff._fz_mxkf/temp1/.copier-answers.yml'

pQraus avatar Jul 19 '22 07:07 pQraus

OK I understand.

A workaround would be:

  1. Specify a different answers file path when copying.
  2. Support a templated dir name subfolder in the template itself.

I guess you'd be able to work with 6.1 if you do those 2 things. However indeed this is a valid issue.

yajo avatar Aug 06 '22 15:08 yajo

I've submitted a PR that should fix this problem, @mhoeger @pQraus. See #1069.

sisp avatar Mar 30 '23 14:03 sisp