copier icon indicating copy to clipboard operation
copier copied to clipboard

Cannot update project rendered from local template

Open jimustafa opened this issue 4 months ago • 4 comments

Describe the problem

Suppose I have a template in a local directory at /path/to/template and create a project from the template:

copier /path/to/template test

When I try to update the project (after cd test):

copier update

I get the following error: Cannot update because cannot obtain old template references from `.copier-answers.yml`.

I commented https://github.com/copier-org/copier/issues/335#issuecomment-3341190268 about this behavior, but I thought creating a separate issue might also be relevant.

Template

template.zip

To Reproduce

No response

Logs


Expected behavior

I expected to be prompted for updated answers.

Screenshots/screencasts/logs

No response

Operating system

Linux

Operating system distribution and version

CentOS 8

Copier version

copier 9.10.1

Python version

Python 3.13.2

Installation method

uvx+pypi

Additional context

No response

jimustafa avatar Oct 24 '25 05:10 jimustafa

I'm afraid I'm not able to reproduce the problem. When I run copier copy with an absolute template path, then the .copier-answers.yml file records the absolute path in _src_path, and copier update works fine when the current working directory is the generated project root.

sisp avatar Oct 24 '25 07:10 sisp

I appreciate you taking a look. After digging a bit more into the issue, it seems to be related to the structure of my templates directory; I am trying to have multiple templates in a single repository (each template is a single file), as shown below:

copier-templates/
├── .git/
│
├── pre-commit/
│   ├── {{ _copier_conf.answers_file }}.j2
│   ├── copier.yaml
│   └── .pre-commit-config.yaml.j2
│
└── pyproject/
    ├── {{ _copier_conf.answers_file }}.j2
    ├── copier.yaml
    └── pyproject.toml.j2

When doing copier copy /path/to/copier-templates/pre-commit ., the .copier-answers.yml files does not contain _commit. If the templates have their own git repository, then it works. Guessing that copier does not look through parents to find a .git directory.

I now understand that this is going against the 1 template = 1 Git repository recommendation, so it may be the case that trying to get this to work would be too hacky. In any case, thanks for your help.

jimustafa avatar Oct 24 '25 15:10 jimustafa

Sorry for the late reply.

You're right, Copier currently doesn't support multiple templates in a single Git repo. There are a few issues with your sketched structure at the moment:

  1. The copier.yaml file must be in the Git repo root. The most promising suggestion to remove this restriction has been made in #1571, but it hasn't been implemented yet.
  2. There is a bug related to changing the location of the answers file; !2186 will probably fix it.
  3. Copier discovers new template versions by sorting Git tags parsed as PEP 440 versions. With multiple templates in the same Git repo, all templates are released under the same version even when nothing has been changed. This is not strictly a Copier problem but one of all Git monorepos. Filtering by tag prefix like [email protected] and [email protected] (applied your example) has been suggested in #2119.

What's your motivation for managing multiple templates in the same Git repo?

sisp avatar Nov 08 '25 19:11 sisp

All good. Thanks for the thorough reply.

I was exploring the possibility of using a set of "atomic" templates rather than a single large template. The idea was that one might want to create individual project files in a modular way, instead of using a monolithic project template; a collection of these modular templates could be maintained in a single repository. Better understanding of the documentation and the issues you referenced makes it clearer why this approach poses difficulties for updating via git tags.

Admittedly, it may have been unrealistic for me to expect that a collection of "atomic" templates would be more convenient than either separate template repositories or a single comprehensive template.

jimustafa avatar Nov 08 '25 20:11 jimustafa