Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printed actions of copier update are incorrect in some cases #1263

Closed
sisp opened this issue Jul 20, 2023 · 4 comments
Closed

Printed actions of copier update are incorrect in some cases #1263

sisp opened this issue Jul 20, 2023 · 4 comments
Labels
bug triage Trying to make sure if this is valid or not
Milestone

Comments

@sisp
Copy link
Member

sisp commented Jul 20, 2023

Describe the problem

When updating a project that involves removed files in the template or the project, the actions printed to the terminal aren't correct.

Template

See reproducible example below.

To Reproduce

$ mkdir src

$ echo '{{ _copier_answers | to_yaml }}' > 'src/{{ _copier_conf.answers_file }}.jinja'
$ touch src/file_1.txt
$ touch src/file_2.txt
$ git -C src init
$ git -C src add .
$ git -C src commit -m v1
$ git -C src tag v1

$ copier copy src dst
Copying from template version 1
    create  .
    create  file_2.txt
    create  file_1.txt
    create  .copier-answers.yml

$ rm dst/file_1.txt
$ git -C dst init
$ git -C dst add .
$ git -C dst commit -m v1

$ rm src/file_2.txt
$ git -C src add .
$ git -C src commit -m v2
$ git -C src tag v2

$ copier update dst
Updating to template version 2

Copying from template version 2
 identical  .
    create  file_1.txt
  conflict  .copier-answers.yml
 overwrite  .copier-answers.yml

$ tree -a -I .git dst
dst
└── .copier-answers.yml

Logs

No response

Expected behavior

There should be two changes in the output:

  • The action create file_1.txt should not be printed because file_1.txt was removed in the project.
  • An action indicating the removal of file_2.txt is missing because file_2.txt was removed in the template.

Specifically, the output should be this:

 $ copier update dst
 Updating to template version 2

 Copying from template version 2
  identical  .
-    create  file_1.txt
+    remove  file_2.txt
   conflict  .copier-answers.yml
  overwrite  .copier-answers.yml

Screenshots/screencasts/logs

No response

Operating system

Linux

Operating system distribution and version

Ubuntu 20.04

Copier version

8.1.0

Python version

CPython 3.9

Installation method

pipx+pypi

Additional context

I think there's no easy fix with the current update algorithm implementation. It might be necessary to extend the copy and update implementations to comprise 2 stages:

  1. Planning
  2. Execution

Then, the update plan would be constructed by getting the copy plan and modifying it. For instance, in this example the _remove_old_files() function would add an action remove file_2.txt and some analysis of the changes incurred by applying the diff of the user changes on top of the project generated from the old template version would remove the action create file_1.txt from the plan.

This certainly needs some careful thinking and extensive testing to get right.

@sisp sisp added enhancement bug triage Trying to make sure if this is valid or not and removed enhancement labels Jul 20, 2023
@pawamoy
Copy link
Contributor

pawamoy commented Jul 20, 2023

A partial, easier, maybe temporary alternative would be to also print out the re-applied diff changes:

Updating to template version 2

Copying from template version 2
 identical  .
    create  file_1.txt
  conflict  .copier-answers.yml
 overwrite  .copier-answers.yml

Re-applying diff
    remove  file_1.txt

Partial because that does not solve the missing "remove file_2.txt" line.

@yajo
Copy link
Member

yajo commented Jul 20, 2023

In #1156 I was trying to just remove the report. Some tests failed and I didn't have time to finish it yet. It's not nice, but it's a fix.

@yajo yajo added this to the Soon milestone Jul 20, 2023
@debo
Copy link

debo commented Dec 20, 2023

@yajo just to clarify and understand. Is it normal that in the current stable version when I run a copier update I don't see any detailed output of what's happening?

It would also appear that an update will blindly overwrite diverged files without warning and when I say overwrite I mean discard changes introduced in the destination path, is that currently intended or a bug? If the latter, would you like me to open an issue for it? Scrap that it seems to work now.

@yajo
Copy link
Member

yajo commented Dec 25, 2023

Is it normal that in the current stable version when I run a copier update I don't see any detailed output of what's happening?

Yes. Since detecting the changes is hard, I removed the report. After all, only git-tracked repos can be updated, so you can use your favorite git diff tool to review the changes.

This landed in 8.2.0 IIRC, so closing.

@yajo yajo closed this as completed Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Trying to make sure if this is valid or not
Projects
None yet
Development

No branches or pull requests

4 participants