diff --git a/CHANGELOG.md b/CHANGELOG.md index 222ccb906..23d2e0196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Summary: complicated anyway (warn added to docs). - Changed `--force` to be the same as `--defaults --overwrite`. - Copied files will reflect permissions on the same files in the template. +- Copier now uses `git clone --filter=blob:none` when cloning, to be faster. ### Deprecated diff --git a/README.md b/README.md index 54c5002e6..2fc3c125a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ A library and CLI app for rendering project templates. ## Installation 1. Install Python 3.6.1 or newer (3.8 or newer if you're on Windows). -1. Install Git 2.24 or newer. +1. Install Git 2.27 or newer. 1. To use as a CLI app: `pipx install copier` 1. To use as a library: `pip install copier` diff --git a/copier/vcs.py b/copier/vcs.py index e828ca0a8..957482f55 100644 --- a/copier/vcs.py +++ b/copier/vcs.py @@ -5,6 +5,7 @@ from pathlib import Path from packaging import version +from packaging.version import Version from plumbum import TF, ProcessExecutionError, colors, local from plumbum.cmd import git @@ -13,6 +14,7 @@ GIT_PREFIX = ("git@", "git://", "git+") GIT_POSTFIX = (".git",) +GIT_VERSION = Version(git("version").split()[-1].replace(".windows", "+windows")) REPLACEMENTS = ( (re.compile(r"^gh:/?(.*\.git)$"), r"https://github.com/\1"), (re.compile(r"^gh:/?(.*)$"), r"https://github.com/\1.git"), @@ -117,7 +119,11 @@ def clone(url: str, ref: OptStr = None) -> str: Reference to checkout. For Git repos, defaults to `HEAD`. """ location = tempfile.mkdtemp(prefix=f"{__name__}.clone.") - git("clone", "--no-checkout", url, location) + _clone = git["clone", "--no-checkout", url, location] + # Faster clones if possible + if GIT_VERSION >= Version("2.27"): + _clone = _clone["--filter=blob:none"] + _clone() with local.cwd(location): git("checkout", ref or "HEAD") git("submodule", "update", "--checkout", "--init", "--recursive", "--force")