Skip to content

Commit 38823dd

Browse files
committed
feat: use clone to fetch remote repositories
This allows VCS to configure local based on the remote like object format for upcoming Git transition to SHA256. Fixes #16994
1 parent 1e26134 commit 38823dd

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

weblate/trans/models/component.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,10 @@ def sync_git_repo(
30273027
return
30283028
if skip_push is None:
30293029
skip_push = validate
3030+
if not self.is_repo_local and not self.repository.is_valid():
3031+
with self.repository.lock:
3032+
self.repository.clone_from(self.repo)
3033+
30303034
self.configure_repo(validate)
30313035
if not skip_commit and self.id:
30323036
self.commit_pending("sync", None, skip_push=skip_push)

weblate/vcs/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def __init__(
9494
branch: str | None = None,
9595
component: Component | None = None,
9696
local: bool = False,
97-
skip_init: bool = False,
9897
) -> None:
9998
self.path: str = path
10099
if branch is None:
@@ -115,12 +114,9 @@ def __init__(
115114
)
116115
self._config_updated = False
117116
self.local = local
117+
# Create ssh wrapper for possible use
118118
if not local:
119-
# Create ssh wrapper for possible use
120119
SSH_WRAPPER.create()
121-
if not skip_init and not self.is_valid():
122-
with self.lock:
123-
self.create_blank_repository(self.path)
124120

125121
@classmethod
126122
def get_remote_branch(cls, repo: str) -> str: # noqa: ARG003
@@ -347,14 +343,18 @@ def _clone(cls, source: str, target: str, branch: str) -> None:
347343
"""Clone repository."""
348344
raise NotImplementedError
349345

346+
def clone_from(self, source: str) -> None:
347+
"""Clone repository into current one."""
348+
self._clone(source, self.path, self.branch)
349+
350350
@classmethod
351351
def clone(
352352
cls, source: str, target: str, branch: str, component: Component | None = None
353353
) -> Self:
354354
"""Clone repository and return object for cloned repository."""
355-
repo = cls(target, branch=branch, component=component, skip_init=True)
355+
repo = cls(target, branch=branch, component=component)
356356
with repo.lock:
357-
cls._clone(source, target, branch)
357+
repo.clone_from(source)
358358
return repo
359359

360360
def update_remote(self) -> None:

weblate/vcs/git.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,8 @@ def __init__(
696696
branch: str | None = None,
697697
component: Component | None = None,
698698
local: bool = False,
699-
skip_init: bool = False,
700699
) -> None:
701-
super().__init__(
702-
path, branch=branch, component=component, local=local, skip_init=skip_init
703-
)
700+
super().__init__(path, branch=branch, component=component, local=local)
704701
self._fetch_revision: str | None = None
705702

706703
@classmethod
@@ -2166,11 +2163,8 @@ def __init__(
21662163
branch: str | None = None,
21672164
component: Component | None = None,
21682165
local: bool = False,
2169-
skip_init: bool = False,
21702166
) -> None:
2171-
super().__init__(
2172-
path, branch=branch, component=component, local=local, skip_init=skip_init
2173-
)
2167+
super().__init__(path, branch=branch, component=component, local=local)
21742168
self.bb_fork: dict = {}
21752169

21762170
def get_headers(self, credentials: GitCredentials) -> dict[str, str]:

weblate/vcs/tests/test_vcs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ def test_weblate_repo_init(self) -> None:
169169
repo = self._class(
170170
tempdir, branch=self._remote_branch, component=self.get_fake_component()
171171
)
172+
self.assertFalse(repo.is_valid())
172173
with repo.lock:
174+
repo.clone_from(self.get_remote_repo_url())
173175
repo.configure_remote(
174176
self.get_remote_repo_url(),
175177
"",

0 commit comments

Comments
 (0)