Skip to content

Commit 1ec0205

Browse files
committed
refactor: extract REMOTE_URL_PREFIXES and is_remote_url() to _vcs.py
1 parent 1ce91a1 commit 1ec0205

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

copier/_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
VcsRef,
7171
)
7272
from ._user_data import AnswersMap, Question, load_answersfile_data
73-
from ._vcs import get_git, is_git_available
73+
from ._vcs import get_git, is_git_available, is_remote_url
7474
from .errors import (
7575
ConfigFileError,
7676
CopierAnswersInterrupt,
@@ -372,7 +372,7 @@ def _answers_to_remember(self) -> Mapping[str, Any]:
372372
was_relative = src_path is not None and not src_path.is_absolute()
373373

374374
# If original was relative and it is not a remote Git repo, save as relative to the subproject root
375-
if was_relative and src and not src.startswith(("http://", "https://", "git@", "git+", "gh:", "gl:", "bb:")):
375+
if was_relative and src and not is_remote_url(src):
376376
try:
377377
src_resolved = Path(src).resolve()
378378
dst_resolved = self.subproject.local_abspath.resolve()

copier/_subproject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ._template import Template
1717
from ._types import AbsolutePath, AnyByStrDict, VCSTypes
1818
from ._user_data import load_answersfile_data
19-
from ._vcs import get_git, is_in_git_repo
19+
from ._vcs import get_git, is_in_git_repo, is_remote_url
2020

2121

2222
@dataclass
@@ -77,7 +77,7 @@ def template(self) -> Template | None:
7777
last_ref = self.last_answers.get("_commit")
7878
if last_url:
7979
url = last_url
80-
if not last_url.startswith(("http://", "https://", "git@", "git+", "gh:", "gl:", "bb:")):
80+
if not is_remote_url(last_url):
8181
try:
8282
path = Path(last_url)
8383
if not path.is_absolute():

copier/_vcs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ def is_git_available() -> bool:
6969
(re.compile(r"^gl:/?(.*)$"), r"https://gitlab.com/\1.git"),
7070
)
7171

72+
REMOTE_URL_PREFIXES = ("http://", "https://", "git@", "git+", "gh:", "gl:", "bb:")
73+
74+
75+
def is_remote_url(url: str) -> bool:
76+
return url.startswith(REMOTE_URL_PREFIXES)
77+
7278

7379
def is_git_repo_root(path: StrOrPath) -> bool:
7480
"""Indicate if a given path is a git repo root directory."""

0 commit comments

Comments
 (0)