Skip to content

Conditional directory generated as empty when non-conditional directory of same name exists and is excluded #2402

@Virtlink

Description

@Virtlink

Describe the problem

I have a template project that has its own .github/workflows/workflow.yaml file while also conditionally providing one for the project generated from the template. Of course, I exclude the repository's own .github/ directory, as I only want the generated one in new projects.

This is the structure:

📁 your_template
├── 📄 copier.yml
├── 📁 .github
│   └── 📁 workflows
│       └── 📄 deploy-docs.yml
└── 📁 {% if ci == 'GitHub' %}.github{% endif %}
    └── 📁 workflows
        └── 📄 ci.yml

Generating a project from my template gives the following output. Note that the output states identical .github for the directory it just created.

🎤 Which Git platform will you use?
   GitHub

Copying from template version None
    create  .github
 identical  .github

And creates this project structure:

📁 showproblem
└── 📁 .github

Note the absence of any contents in the .github directory, it is completely empty.

Template

copier-problem.zip

To Reproduce

My directory structure is as follows:

📁 your_template
├── 📄 copier.yml
├── 📁 .github
│   └── 📁 workflows
│       └── 📄 deploy-docs.yml
└── 📁 {% if ci == 'GitHub' %}.github{% endif %}
    └── 📁 workflows
        └── 📄 ci.yml

The contents of the workflow YAML files doesn't matter and can be different, and their filenames can also be different. The copier.yml contains:

---
_exclude:
  - .github/
  - copier.yml
  - .git

ci:
  type: str
  help: "Which Git platform will you use?"
  choices:
    - GitHub
    - GitLab
    - Other
  default: GitHub

Note that I added .github/ to _exclude: to exclude the repository's own .github/ from ending up in the generated project. Invoking this command and answering using the defaults:

rm -rf ../showproblem/ && copier copy . ../showproblem/

Outputs:

Copying from template version None
    create  .github
 identical  .github

Logs

Expected behavior

I expected the contents of the conditional .github directory to appear in the generated project.

Screenshots/screencasts/logs

No response

Operating system

Linux

Operating system distribution and version

Ubuntu 24.04

Copier version

copier 9.10.3

Python version

Python 3.12.11

Installation method

uvx+pypi

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtriageTrying to make sure if this is valid or not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions