Skip to content

Commit 502a52d

Browse files
committed
feat(sync[git]): Moving to cmd
1 parent 3176cf6 commit 502a52d

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

src/libvcs/sync/git.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
from typing import Any, Optional, Union
2222
from urllib import parse as urlparse
2323

24-
from libvcs._internal.types import StrOrBytesPath, StrPath
24+
from libvcs._internal.types import StrPath
25+
from libvcs.cmd.git import Git
2526
from libvcs.sync.base import (
2627
BaseSync,
2728
VCSLocation,
@@ -300,20 +301,25 @@ def obtain(self, *args: Any, **kwargs: Any) -> None:
300301

301302
url = self.url
302303

303-
cmd: list[StrOrBytesPath] = ["clone", "--progress"]
304-
if self.git_shallow:
305-
cmd.extend(["--depth", "1"])
306-
if self.tls_verify:
307-
cmd.extend(["-c", "http.sslVerify=false"])
308-
cmd.extend([url, self.dir])
309-
310304
self.log.info("Cloning.")
311-
self.run(cmd, log_in_real_time=True)
305+
# todo: log_in_real_time
306+
self.cmd.clone(
307+
url=url,
308+
progress=True,
309+
depth=1 if self.git_shallow else None,
310+
config={"http.sslVerify": False} if self.tls_verify else None,
311+
log_in_real_time=True,
312+
)
312313

313314
self.log.info("Initializing submodules.")
314-
self.run(["submodule", "init"], log_in_real_time=True)
315-
cmd = ["submodule", "update", "--recursive", "--init"]
316-
self.run(cmd, log_in_real_time=True)
315+
self.cmd.submodule.init(
316+
log_in_real_time=True,
317+
)
318+
self.cmd.submodule.update(
319+
init=True,
320+
recursive=True,
321+
log_in_real_time=True,
322+
)
317323

318324
self.set_remotes(overwrite=True)
319325

@@ -590,7 +596,7 @@ def get_git_version(self) -> str:
590596
git version
591597
"""
592598
VERSION_PFX = "git version "
593-
version = self.run(["version"])
599+
version = self.cmd.version()
594600
if version.startswith(VERSION_PFX):
595601
version = version[len(VERSION_PFX) :].split()[0]
596602
else:
@@ -622,7 +628,10 @@ def status(self) -> GitStatus:
622628
branch_behind='0'\
623629
)
624630
"""
625-
return GitStatus.from_stdout(self.run(["status", "-sb", "--porcelain=2"]))
631+
return GitStatus.from_stdout(
632+
self.cmd.status(short=True, branch=True, porcelain="2")
633+
)
634+
# return GitStatus.from_stdout(self.run(["status", "-sb", "--porcelain=2"]))
626635

627636
def get_current_remote_name(self) -> str:
628637
"""Retrieve name of the remote / upstream of currently checked out branch.
@@ -642,3 +651,7 @@ def get_current_remote_name(self) -> str:
642651
return match.branch_upstream
643652

644653
return match.branch_upstream.replace("/" + match.branch_head, "")
654+
655+
@property
656+
def cmd(self, *args: object, **kwargs: object) -> Git:
657+
return Git(dir=self.dir, *args, **kwargs)

0 commit comments

Comments
 (0)