MCPcopy Create free account
hub / github.com/modelscope/modelscope / _clone_if_needed

Function _clone_if_needed

modelscope/hub/repository.py:34–52  ·  view source on GitHub ↗

Clone *url* into *repo_dir* unless it's already that working copy. Returns ``True`` if a clone was performed, ``False`` if skipped.

(git_wrapper: GitCommandWrapper, base_dir: str,
                     repo_name: str, repo_dir: str, url: str,
                     git_token: Optional[str],
                     revision: Optional[str])

Source from the content-addressed store, hash-verified

32
33
34def _clone_if_needed(git_wrapper: GitCommandWrapper, base_dir: str,
35 repo_name: str, repo_dir: str, url: str,
36 git_token: Optional[str],
37 revision: Optional[str]) -> bool:
38 """Clone *url* into *repo_dir* unless it's already that working copy.
39
40 Returns ``True`` if a clone was performed, ``False`` if skipped.
41 """
42 os.makedirs(repo_dir, exist_ok=True)
43 if os.listdir(repo_dir):
44 try:
45 existing = git_wrapper.get_repo_remote_url(repo_dir)
46 existing = git_wrapper.remove_token_from_url(existing)
47 if existing == url:
48 return False
49 except GitError:
50 pass
51 git_wrapper.clone(base_dir, git_token, url, repo_name, revision)
52 return True
53
54
55class Repository:

Callers 2

__init__Method · 0.85
cloneMethod · 0.85

Calls 3

get_repo_remote_urlMethod · 0.80
remove_token_from_urlMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…