Skip to content

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

@sisp

Description

@sisp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtriageTrying to make sure if this is valid or not

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions