You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to copier. I'm trying to develop test units so that I can test changes I'm implementing.
Project generation (aka. copy) works well. My problem relates to testing changes from a dirty git repo, with uncommitted changes, and potentially new files.
In my first test, I'm trying to run an update using the same state of the (dirty) git repo that generated a copy. Here is a sketch of I'm trying to do:
Create a git repo called foo, with the following contents:
a) A file called copier.yml:
_min_copier_version: '9'_exclude:
- .git
- copier.ymlproject_name:
type: strdefault: new-foohelp: A short (slug-style) name for your project
b) a file called {{ _copier_conf.answers_file}}.jinja:
_min_copier_version: '9'_exclude:
- .git
- copier.ymlproject_name:
type: strdefault: new-foohelp: Help for project-name
Initialize a git repo on foo and commit all files.
Slightly modify a file, say copier.yml so that the repository becomes dirty.
Go back to the parent directory cd ..
Create a new copy by calling copier copy --defaults $(PWD)/foo --vcs-ref=HEAD new-foo, observe that Dirty template changes included automatically. correctly appears indicating copier is aware of the dirty repo.
Change dir to new-foo and initialize a git repo: git init . && git add . && git commit -m 'Initial commit' -a
Go back to the parent directory and try an update with: copier update --defaults --vcs-ref=HEAD new-foo (that should result in no changes as the dirty changes where not modified). I observe that Dirty template changes included automatically. appears, however, this exercise results in the following exception being raised:
/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/vcs.py:209: DirtyLocalWarning: Dirty template changes included automatically.
warn(
No git tags found in template; using HEAD as ref
Traceback (most recent call last):
File "/Users/andre/.local/share/pixi/envs/python/bin/copier", line 10, in <module>
sys.exit(CopierApp.run())
~~~~~~~~~~~~~^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/plumbum/cli/application.py", line 640, in run
inst, retcode = subapp.run(argv, exit=False)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/plumbum/cli/application.py", line 635, in run
retcode = inst.main(*tailargs)
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/cli.py", line 425, in main
return _handle_exceptions(inner)
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/cli.py", line 70, in _handle_exceptions
method()
~~~~~~^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/cli.py", line 415, in inner
with self._worker(
~~~~~~~~~~~~^
dst_path=destination_path,
^^^^^^^^^^^^^^^^^^^^^^^^^^
...<4 lines>...
overwrite=True,
^^^^^^^^^^^^^^^
) as worker:
^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/main.py", line 237, in __exit__
raise value
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/cli.py", line 423, in inner
worker.run_update()
~~~~~~~~~~~~~~~~~^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/main.py", line 872, in run_update
self._check_unsafe("update")
~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/main.py", line 256, in _check_unsafe
if self.subproject.template.jinja_extensions:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/functools.py", line 1039, in __get__
val = self.func(instance)
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/template.py", line 337, in jinja_extensions
return tuple(self.config_data.get("jinja_extensions", ()))
^^^^^^^^^^^^^^^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/functools.py", line 1039, in __get__
val = self.func(instance)
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/template.py", line 300, in config_data
result = filter_config(self._raw_config)[0]
^^^^^^^^^^^^^^^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/functools.py", line 1039, in __get__
val = self.func(instance)
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/template.py", line 257, in _raw_config
for p in self.local_abspath.glob("copier.*")
^^^^^^^^^^^^^^^^^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/functools.py", line 1039, in __get__
val = self.func(instance)
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/template.py", line 555, in local_abspath
result = Path(clone(self.url_expanded, self.ref))
~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/copier/vcs.py", line 215, in clone
git("checkout", "-f", ref or "HEAD")
~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/plumbum/commands/base.py", line 115, in __call__
return self.run(args, **kwargs)[1]
~~~~~~~~^^^^^^^^^^^^^^^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/plumbum/commands/base.py", line 254, in run
return p.run()
~~~~~^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/plumbum/commands/base.py", line 217, in runner
return run_proc(p, retcode, timeout)
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/plumbum/commands/processes.py", line 330, in run_proc
return _check_process(proc, retcode, timeout, stdout, stderr)
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/plumbum/commands/processes.py", line 19, in _check_process
proc.verify(retcode, timeout, stdout, stderr)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/andre/.local/share/pixi/envs/python/lib/python3.13/site-packages/plumbum/machines/base.py", line 29, in verify
raise ProcessExecutionError(
getattr(self, "argv", None), self.returncode, stdout, stderr
)
plumbum.commands.processes.ProcessExecutionError: Unexpected exit code: 1
Command line: | /Users/andre/.local/share/pixi/envs/python/bin/git checkout -f bce5732
Stderr: | error: pathspec 'bce5732' did not match any file(s) known to git
Of course, the commit bce5732 does not exist, but I guess copier created that on a separate clone. The problem I'm observing is that, somehow, it cannot "re-create" that commit/hash upon an update.
How can I make the update from a dirty repo work as described above?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm new to copier. I'm trying to develop test units so that I can test changes I'm implementing.
Project generation (aka. copy) works well. My problem relates to testing changes from a dirty git repo, with uncommitted changes, and potentially new files.
In my first test, I'm trying to run an update using the same state of the (dirty) git repo that generated a copy. Here is a sketch of I'm trying to do:
foo
, with the following contents:a) A file called
copier.yml
:b) a file called
{{ _copier_conf.answers_file}}.jinja
:foo
and commit all files.copier.yml
so that the repository becomes dirty.cd ..
copier copy --defaults $(PWD)/foo --vcs-ref=HEAD new-foo
, observe thatDirty template changes included automatically.
correctly appears indicating copier is aware of the dirty repo.new-foo
and initialize a git repo:git init . && git add . && git commit -m 'Initial commit' -a
copier update --defaults --vcs-ref=HEAD new-foo
(that should result in no changes as the dirty changes where not modified). I observe thatDirty template changes included automatically.
appears, however, this exercise results in the following exception being raised:Of course, the commit
bce5732
does not exist, but I guess copier created that on a separate clone. The problem I'm observing is that, somehow, it cannot "re-create" that commit/hash upon an update.How can I make the update from a dirty repo work as described above?
Beta Was this translation helpful? Give feedback.
All reactions