From 8cb66071ac11dbdd1596431157eb68d3089cbc35 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Thu, 20 Feb 2025 02:52:23 +0300 Subject: [PATCH 1/3] feat(git_utils): enhance git_cmd_clone with depth and single-branch options Signed-off-by: Aleksei Sviridkin --- kiauh/utils/git_utils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kiauh/utils/git_utils.py b/kiauh/utils/git_utils.py index a658607..ac2ae39 100644 --- a/kiauh/utils/git_utils.py +++ b/kiauh/utils/git_utils.py @@ -253,11 +253,16 @@ 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 = 1) -> None: try: - command = ["git", "clone", repo, target_dir.as_posix()] + command = [ + "git", "clone", + "--depth", str(depth), + "--single-branch", + repo, + target_dir.as_posix() + ] run(command, check=True) - Logger.print_ok("Clone successful!") except CalledProcessError as e: error = e.stderr.decode() if e.stderr else "Unknown error" From d5119bc264313b9e3f45d83f6082a45ef4a9551a Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Thu, 20 Feb 2025 02:56:17 +0300 Subject: [PATCH 2/3] fix(git_utils): add a newline for better readability in git_cmd_clone Signed-off-by: Aleksei Sviridkin --- kiauh/utils/git_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kiauh/utils/git_utils.py b/kiauh/utils/git_utils.py index ac2ae39..880f9e5 100644 --- a/kiauh/utils/git_utils.py +++ b/kiauh/utils/git_utils.py @@ -263,6 +263,7 @@ def git_cmd_clone(repo: str, target_dir: Path, depth: int = 1) -> None: target_dir.as_posix() ] run(command, check=True) + Logger.print_ok("Clone successful!") except CalledProcessError as e: error = e.stderr.decode() if e.stderr else "Unknown error" From 2d4c952b4b5ceaa36bb60979a94899303e6cd867 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Fri, 21 Feb 2025 07:36:49 +0300 Subject: [PATCH 3/3] feat(git_utils): enhance git_cmd_clone with optional depth and single-branch parameters Signed-off-by: Aleksei Sviridkin --- kiauh/utils/git_utils.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/kiauh/utils/git_utils.py b/kiauh/utils/git_utils.py index 880f9e5..9e69358 100644 --- a/kiauh/utils/git_utils.py +++ b/kiauh/utils/git_utils.py @@ -253,15 +253,29 @@ def get_remote_commit(repo: Path) -> str | None: return None -def git_cmd_clone(repo: str, target_dir: Path, depth: int = 1) -> 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", - "--depth", str(depth), - "--single-branch", - 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!")