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

'copier recopy' doesn't delete removed files or directories #1867

Open
usrme opened this issue Nov 22, 2024 · 0 comments
Open

'copier recopy' doesn't delete removed files or directories #1867

usrme opened this issue Nov 22, 2024 · 0 comments
Labels
bug triage Trying to make sure if this is valid or not

Comments

@usrme
Copy link

usrme commented Nov 22, 2024

Describe the problem

Running copier recopy --force doesn't delete files or directories that were removed from the source.

Template

$ mkdir -p copier-template/work/work/{new,old}-dir/
$ touch copier-template/work/work/{new,old}-dir/file.txt
$ cat << EOF > copier-template/work/{{_copier_conf.answers_file}}.jinja
{{ _copier_answers|to_nice_yaml -}}
EOF
$ cat << EOF > copier-template/copier.yml
_subdirectory: "{{ sub }}"

_min_copier_version: "9.2.0"

sub:
  type: str
  help: What kind of subdirectory do you want to create?
  choices:
    - work
EOF

To Reproduce

$ mkdir copier-target
$ cd copier-target
$ copier copy -d 'sub=work' ../copier-template/ .

Copying from template version None
    create  .copier-answers.yml
    create  work
    create  work/old-dir
    create  work/old-dir/file.txt
    create  work/new-dir
    create  work/new-dir/file.txt

$ rm -rf ../copier-template/work/work/old-dir/
$ copier recopy --force

Copying from template version None
 identical  .copier-answers.yml
 identical  work
 identical  work/new-dir
 identical  work/new-dir/file.txt

$ tree -a
.
├── .copier-answers.yml
└── work
    ├── new-dir
    │   └── file.txt
    └── old-dir
        └── file.txt

$ tree ../copier-template/
../copier-template/
├── copier.yml
└── work
    ├── work
    │   └── new-dir
    │       └── file.txt
    └── {{_copier_conf.answers_file}}.jinja

Logs

No response

Expected behavior

I would expect recopy to remove what was once managed by Copier and anything that wasn't managed by Copier to be left alone. If a new file/directory gets added to the target then running recopy shouldn't remove it, but if a file/directory was in the source and no longer is, then it should be removed.

Screenshots/screencasts/logs

No response

Operating system

macOS

Operating system distribution and version

Sequoia 15.1

Copier version

9.4.1

Python version

3.13.0

Installation method

pipx+pypi

Additional context

The reproduction case is done with local templates, but the same issue is present for Git-based templates. The reproduction showed how the removed directory isn't detected, but the same applies for files. The reproduction doesn't require the top-level directories to be named identically (i.e. work/work) and is just accidental, they could be renamed as one wants.

I'm assuming all of this isn't intentional, but if it is then I'd be curious to know of any workarounds to this.

@usrme usrme added bug triage Trying to make sure if this is valid or not labels Nov 22, 2024
@usrme usrme changed the title 'copier recopy' doesn't delete removed directories 'copier recopy' doesn't delete removed files or directories Nov 22, 2024
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

1 participant