copier icon indicating copy to clipboard operation
copier copied to clipboard

Cache git templates locally

Open yajo opened this issue 4 years ago • 6 comments

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.

yajo avatar Sep 24 '21 17:09 yajo

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>]

pawamoy avatar Sep 25 '21 09:09 pawamoy

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?

pawamoy avatar Sep 25 '21 09:09 pawamoy

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.

ypid-work avatar Feb 02 '23 18:02 ypid-work

Maybe we can just use https://pypi.org/project/git-autoshare/ behind the scenes automatically.

yajo avatar Feb 03 '23 13:02 yajo

Two arguments against using git-autoshare:

  1. It is licensed under GPLv3, which would poison our MIT license.
  2. It doesn't seem actively maintained.

sisp avatar Apr 07 '24 06:04 sisp

Fair points. Then we can just cache a local git mirror and use temporary worktrees to speed things up.

yajo avatar Apr 07 '24 15:04 yajo