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

Class GitCommandWrapper

modelscope/hub/git.py:35–200  ·  view source on GitHub ↗

Backward-compatible Git wrapper. Wraps :class:`modelscope_hub._git.GitCommand` to expose the legacy instance-method API (``clone``, ``push``, ``pull``, ``tag``…) used by callers that pre-date the SDK refactor.

Source from the content-addressed store, hash-verified

33
34
35class GitCommandWrapper(metaclass=Singleton):
36 """Backward-compatible Git wrapper.
37
38 Wraps :class:`modelscope_hub._git.GitCommand` to expose the legacy
39 instance-method API (``clone``, ``push``, ``pull``, ``tag``…) used
40 by callers that pre-date the SDK refactor.
41 """
42
43 default_git_path = 'git'
44
45 def __init__(self, path: Optional[str] = None):
46 self.git_path = path or self.default_git_path
47 _GitCommand.set_git_path(self.git_path)
48
49 # ------------------------------------------------------------------
50 # Low-level subprocess passthrough (legacy contract)
51 # ------------------------------------------------------------------
52 def _run_git_command(self, *args):
53 """Run a git subcommand, raising :class:`GitError` on failure."""
54 try:
55 return _GitCommand._run(*[a for a in args if a])
56 except Exception as exc: # _git.GitError → legacy GitError
57 raise GitError(str(exc)) from exc
58
59 # ------------------------------------------------------------------
60 # URL / token helpers
61 # ------------------------------------------------------------------
62 def _add_git_token(self, git_token: str, url: str) -> str:
63 return _GitCommand._inject_token(url, git_token)
64
65 def remove_token_from_url(self, url: str) -> str:
66 return _GitCommand.strip_token_from_url(url)
67
68 # ------------------------------------------------------------------
69 # LFS
70 # ------------------------------------------------------------------
71 def is_lfs_installed(self) -> bool:
72 return _GitCommand.is_lfs_available()
73
74 def git_lfs_install(self, repo_dir: str) -> bool:
75 try:
76 _GitCommand.lfs_install(Path(repo_dir))
77 return True
78 except Exception:
79 return False
80
81 def list_lfs_files(self, repo_dir: str) -> List[str]:
82 rsp = self._run_git_command('-C', repo_dir, 'lfs', 'ls-files')
83 return [
84 line.split(' ')[-1] for line in rsp.stdout.strip().splitlines()
85 if line
86 ]
87
88 # ------------------------------------------------------------------
89 # Auth / user config
90 # ------------------------------------------------------------------
91 def config_git_token(self, repo_dir: str, git_token: str) -> None:
92 url = self.get_repo_remote_url(repo_dir)

Callers 5

get_model_id_from_cacheFunction · 0.90
test_push_allMethod · 0.90
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by 2

test_push_allMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…