From 8cb66071ac11dbdd1596431157eb68d3089cbc35 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Thu, 20 Feb 2025 02:52:23 +0300 Subject: [PATCH 1/8] 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/8] 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/8] 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!") From 0a08c4fb3fabf760c20427cf70ba1650ef1950b7 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Mon, 10 Mar 2025 16:27:37 +0300 Subject: [PATCH 4/8] feat(git_utils): update git_cmd_clone to support blolbless cloning option Signed-off-by: Aleksei Sviridkin --- kiauh/utils/git_utils.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/kiauh/utils/git_utils.py b/kiauh/utils/git_utils.py index 9e69358..08a2f78 100644 --- a/kiauh/utils/git_utils.py +++ b/kiauh/utils/git_utils.py @@ -81,8 +81,10 @@ def get_repo_name(repo: Path) -> Tuple[str, str]: return "-", "-" try: - cmd = ["git", "-C", repo.as_posix(), "config", "--get", "remote.origin.url"] - result: str = check_output(cmd, stderr=DEVNULL).decode(encoding="utf-8") + cmd = ["git", "-C", repo.as_posix(), "config", "--get", + "remote.origin.url"] + result: str = check_output( + cmd, stderr=DEVNULL).decode(encoding="utf-8") substrings: List[str] = result.strip().split("/")[-2:] orga: str = substrings[0] if substrings[0] else "-" @@ -133,7 +135,7 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]: tags: List[str] = result.split("\n")[:-1] return sorted(tags, key=lambda x: [int(i) if i.isdigit() else i for i in - re.split(r'(\d+)', x)]) + re.split(r'(\d+)', x)]) except CalledProcessError: return [] @@ -185,7 +187,8 @@ def get_latest_unstable_tag(repo_path: str) -> str: """ try: if ( - len(unstable_tags := [t for t in get_remote_tags(repo_path) if "-" in t]) + len(unstable_tags := [ + t for t in get_remote_tags(repo_path) if "-" in t]) > 0 ): return unstable_tags[0] @@ -253,31 +256,24 @@ def get_remote_commit(repo: Path) -> str | None: return None -def git_cmd_clone(repo: str, target_dir: Path, depth: int = 0, single_branch: bool = False) -> None: +def git_cmd_clone(repo: str, target_dir: Path, blolbless: bool = False) -> None: """ - Clones a repository with optional depth and single-branch parameters. + Clones a repository with optional blolbless clone. :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 + :param blolbless: If True, perform a blolbless clone by adding the '--blolbless' flag. """ try: 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") + # Добавляем флаг для blolbless clone, если требуется + if blolbless: + command.append("--blolbless") command += [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" @@ -317,7 +313,8 @@ def rollback_repository(repo_dir: Path, instance: Type[InstanceType]) -> None: instances = get_instances(instance) - Logger.print_warn("Do not continue if you have ongoing prints!", start="\n") + Logger.print_warn( + "Do not continue if you have ongoing prints!", start="\n") Logger.print_warn( f"All currently running {instance.__name__} services will be stopped!" ) From acb4d0398f56785cc1fc5971f34b5db2d44b5f7d Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Mon, 10 Mar 2025 16:31:23 +0300 Subject: [PATCH 5/8] revert formatting changes Signed-off-by: Aleksei Sviridkin --- kiauh/utils/git_utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kiauh/utils/git_utils.py b/kiauh/utils/git_utils.py index 08a2f78..87c6593 100644 --- a/kiauh/utils/git_utils.py +++ b/kiauh/utils/git_utils.py @@ -81,10 +81,8 @@ def get_repo_name(repo: Path) -> Tuple[str, str]: return "-", "-" try: - cmd = ["git", "-C", repo.as_posix(), "config", "--get", - "remote.origin.url"] - result: str = check_output( - cmd, stderr=DEVNULL).decode(encoding="utf-8") + cmd = ["git", "-C", repo.as_posix(), "config", "--get", "remote.origin.url"] + result: str = check_output(cmd, stderr=DEVNULL).decode(encoding="utf-8") substrings: List[str] = result.strip().split("/")[-2:] orga: str = substrings[0] if substrings[0] else "-" @@ -135,7 +133,7 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]: tags: List[str] = result.split("\n")[:-1] return sorted(tags, key=lambda x: [int(i) if i.isdigit() else i for i in - re.split(r'(\d+)', x)]) + re.split(r'(\d+)', x)]) except CalledProcessError: return [] From 3a2574f24e8f1a9a7b6edb673b60e04eb9c3cff0 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Mon, 10 Mar 2025 16:33:53 +0300 Subject: [PATCH 6/8] fix another formatting changes Signed-off-by: Aleksei Sviridkin --- kiauh/utils/git_utils.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/kiauh/utils/git_utils.py b/kiauh/utils/git_utils.py index 87c6593..f17638a 100644 --- a/kiauh/utils/git_utils.py +++ b/kiauh/utils/git_utils.py @@ -185,8 +185,7 @@ def get_latest_unstable_tag(repo_path: str) -> str: """ try: if ( - len(unstable_tags := [ - t for t in get_remote_tags(repo_path) if "-" in t]) + len(unstable_tags := [t for t in get_remote_tags(repo_path) if "-" in t]) > 0 ): return unstable_tags[0] @@ -265,7 +264,6 @@ def git_cmd_clone(repo: str, target_dir: Path, blolbless: bool = False) -> None: try: command = ["git", "clone"] - # Добавляем флаг для blolbless clone, если требуется if blolbless: command.append("--blolbless") @@ -311,8 +309,7 @@ def rollback_repository(repo_dir: Path, instance: Type[InstanceType]) -> None: instances = get_instances(instance) - Logger.print_warn( - "Do not continue if you have ongoing prints!", start="\n") + Logger.print_warn("Do not continue if you have ongoing prints!", start="\n") Logger.print_warn( f"All currently running {instance.__name__} services will be stopped!" ) From 66c0757be1b45d7e7ef440d1284bde03e1f0eb7d Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Mon, 10 Mar 2025 16:34:51 +0300 Subject: [PATCH 7/8] fix(git_utils): correct indentation for improved readability in get_local_tags function Signed-off-by: Aleksei Sviridkin --- kiauh/utils/git_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiauh/utils/git_utils.py b/kiauh/utils/git_utils.py index f17638a..4cca992 100644 --- a/kiauh/utils/git_utils.py +++ b/kiauh/utils/git_utils.py @@ -133,7 +133,7 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]: tags: List[str] = result.split("\n")[:-1] return sorted(tags, key=lambda x: [int(i) if i.isdigit() else i for i in - re.split(r'(\d+)', x)]) + re.split(r'(\d+)', x)]) except CalledProcessError: return [] From 7e4ba0d8cd94bedc97238d7f0e071598bc4282ea Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Mon, 10 Mar 2025 22:42:42 +0300 Subject: [PATCH 8/8] fix(git_utils): rename blolbless parameter to blobless and update documentation for clarity Signed-off-by: Aleksei Sviridkin --- kiauh/utils/git_utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kiauh/utils/git_utils.py b/kiauh/utils/git_utils.py index 4cca992..6acba23 100644 --- a/kiauh/utils/git_utils.py +++ b/kiauh/utils/git_utils.py @@ -253,19 +253,19 @@ def get_remote_commit(repo: Path) -> str | None: return None -def git_cmd_clone(repo: str, target_dir: Path, blolbless: bool = False) -> None: +def git_cmd_clone(repo: str, target_dir: Path, blobless: bool = False) -> None: """ - Clones a repository with optional blolbless clone. + Clones a repository with optional blobless clone. :param repo: URL of the repository to clone. :param target_dir: Path where the repository will be cloned. - :param blolbless: If True, perform a blolbless clone by adding the '--blolbless' flag. + :param blobless: If True, perform a blobless clone by adding the '--filter=blob:none' flag. """ try: command = ["git", "clone"] - if blolbless: - command.append("--blolbless") + if blobless: + command.append("--filter=blob:none") command += [repo, target_dir.as_posix()]