Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(clone): clone faster without blobs #472

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
8 changes: 7 additions & 1 deletion copier/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"),
Expand Down Expand Up @@ -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")
Expand Down