From eb5d0c6f9c37268bcc494d554c807a312b7812eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20K=C3=B6nig?= Date: Fri, 21 Nov 2025 15:37:45 +0100 Subject: [PATCH] use shallow clone with depth 1 --- gitopscli/git_api/git_repo.py | 2 +- tests/git_api/test_git_repo.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gitopscli/git_api/git_repo.py b/gitopscli/git_api/git_repo.py index b3b5f94..f6ead29 100644 --- a/gitopscli/git_api/git_repo.py +++ b/gitopscli/git_api/git_repo.py @@ -43,7 +43,7 @@ def get_clone_url(self) -> str: def clone(self, branch: str | None = None) -> None: self.__delete_tmp_dir() self.__tmp_dir = create_tmp_dir() - git_options = [] + git_options = ["--depth=1"] url = self.get_clone_url() if branch: logging.info("Cloning repository: %s (branch: %s)", url, branch) diff --git a/tests/git_api/test_git_repo.py b/tests/git_api/test_git_repo.py index 4b01648..9286e1d 100644 --- a/tests/git_api/test_git_repo.py +++ b/tests/git_api/test_git_repo.py @@ -166,6 +166,16 @@ def test_clone_unknown_url(self, logging_mock): self.assertEqual("Error cloning 'invalid_url'", str(ex.value)) logging_mock.info.assert_called_once_with("Cloning repository: %s", self.__mock_repo_api.get_clone_url()) + def test_clone_with_depth_1(self): + with GitRepo(self.__mock_repo_api) as testee: + testee.clone() + + # Verify that the repository was cloned with depth 1 + repo = Repo(testee.get_full_file_path(".")) + # A shallow clone with depth 1 should only have the latest commit + commits = list(repo.iter_commits("master")) + self.assertEqual(1, len(commits), "Clone should be shallow with depth 1") + def test_get_full_file_path(self): with GitRepo(self.__mock_repo_api) as testee: testee.clone()