copier
copier copied to clipboard
Cache git templates locally
the fetch that copier does for this case is too slow.
Originally posted by @bburgin in https://github.com/copier-org/copier/discussions/449#discussioncomment-1371169
And it's true. Copier should cache downloaded templates, so next fetches are faster.
Or there might be possible optimizations, like partial clones, or single branch clones:
# clone only the remote primary HEAD (default: origin/master)
git clone <url> --single-branch
# as in:
git clone <url> --branch <branch> --single-branch [<folder>]
If we go with caching: I guess we'll just need to fetch/pull each time we generate/update a project again, and if it fails clone the template repo again, do I understand correctly?
For me copier takes 5.5 seconds when updating from a template stored in a remote git repo vs. 0.7 seconds when the template is checked out locally. I still think caching the template repo makes a lot of sense. The cache could be created in ~/.cache/copier. Can you reopen because this issue was not solved in accordance with the original description. The cache could also be used for quick local development/template fixes before pushing them.
Maybe we can just use https://pypi.org/project/git-autoshare/ behind the scenes automatically.
Two arguments against using git-autoshare:
- It is licensed under GPLv3, which would poison our MIT license.
- It doesn't seem actively maintained.
Fair points. Then we can just cache a local git mirror and use temporary worktrees to speed things up.