mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-11 17:44:28 +05:00
feat(git_utils): Support for blolbless clone mode in git_cmd_clone (#640)
* feat(git_utils): enhance git_cmd_clone with depth and single-branch options Signed-off-by: Aleksei Sviridkin <f@lex.la> * fix(git_utils): add a newline for better readability in git_cmd_clone Signed-off-by: Aleksei Sviridkin <f@lex.la> * feat(git_utils): enhance git_cmd_clone with optional depth and single-branch parameters Signed-off-by: Aleksei Sviridkin <f@lex.la> * feat(git_utils): update git_cmd_clone to support blolbless cloning option Signed-off-by: Aleksei Sviridkin <f@lex.la> * revert formatting changes Signed-off-by: Aleksei Sviridkin <f@lex.la> * fix another formatting changes Signed-off-by: Aleksei Sviridkin <f@lex.la> * fix(git_utils): correct indentation for improved readability in get_local_tags function Signed-off-by: Aleksei Sviridkin <f@lex.la> * fix(git_utils): rename blolbless parameter to blobless and update documentation for clarity Signed-off-by: Aleksei Sviridkin <f@lex.la> * refactor: enable the blobless clone feature for all regular clones skip checkout step if brach is master or main Signed-off-by: Dominik Willner <th33xitus@gmail.com> --------- Signed-off-by: Aleksei Sviridkin <f@lex.la> Signed-off-by: Dominik Willner <th33xitus@gmail.com> Co-authored-by: dw-0 <th33xitus@gmail.com>
This commit is contained in:
@@ -26,9 +26,10 @@ def git_clone_wrapper(
|
||||
) -> None:
|
||||
"""
|
||||
Clones a repository from the given URL and checks out the specified branch if given.
|
||||
The clone will be performed with the '--filter=blob:none' flag to perform a blobless clone.
|
||||
|
||||
:param repo: The URL of the repository to clone.
|
||||
:param branch: The branch to check out. If None, the default branch will be checked out.
|
||||
:param branch: The branch to check out. If None, master or main, no checkout will be performed.
|
||||
:param target_dir: The directory where the repository will be cloned.
|
||||
:param force: Force the cloning of the repository even if it already exists.
|
||||
:return: None
|
||||
@@ -43,8 +44,11 @@ def git_clone_wrapper(
|
||||
return
|
||||
shutil.rmtree(target_dir)
|
||||
|
||||
git_cmd_clone(repo, target_dir)
|
||||
git_cmd_checkout(branch, target_dir)
|
||||
git_cmd_clone(repo, target_dir, blobless=True)
|
||||
|
||||
if branch not in ("master", "main"):
|
||||
git_cmd_checkout(branch, target_dir)
|
||||
|
||||
except CalledProcessError:
|
||||
log = "An unexpected error occured during cloning of the repository."
|
||||
Logger.print_error(log)
|
||||
@@ -255,11 +259,23 @@ def get_remote_commit(repo: Path) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def git_cmd_clone(repo: str, target_dir: Path) -> None:
|
||||
try:
|
||||
command = ["git", "clone", repo, target_dir.as_posix()]
|
||||
run(command, check=True)
|
||||
def git_cmd_clone(repo: str, target_dir: Path, blobless: bool = False) -> None:
|
||||
"""
|
||||
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 blobless: If True, perform a blobless clone by adding the '--filter=blob:none' flag.
|
||||
"""
|
||||
try:
|
||||
command = ["git", "clone"]
|
||||
|
||||
if blobless:
|
||||
command.append("--filter=blob:none")
|
||||
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user