Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(git_utils): Allow configurable shallow clone depth in git_cmd_clone #640

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions kiauh/utils/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,29 @@ def get_remote_commit(repo: Path) -> str | None:
return None


def git_cmd_clone(repo: str, target_dir: Path) -> None:
def git_cmd_clone(repo: str, target_dir: Path, depth: int = 0, single_branch: bool = False) -> None:
"""
Clones a repository with optional depth and single-branch parameters.

:param repo: URL of the repository to clone.
:param target_dir: Path where the repository will be cloned.
:param depth: Clone depth. If 0, the depth option will be omitted.
:param single_branch: Clone only a single branch if True.
:return: None
"""
try:
command = ["git", "clone", repo, target_dir.as_posix()]
command = ["git", "clone"]

# Add --depth flag if depth > 0
if depth > 0:
command += ["--depth", str(depth)]

# Add --single-branch flag if single_branch is True
if single_branch:
command.append("--single-branch")

command += [repo, target_dir.as_posix()]

run(command, check=True)

Logger.print_ok("Clone successful!")
Expand Down