Skip to content

Commit 5a612d0

Browse files
Merge pull request #238 from baloise/shallow
feat: use shallow clone with depth 1
2 parents d6d37bc + eb5d0c6 commit 5a612d0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

gitopscli/git_api/git_repo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_clone_url(self) -> str:
4343
def clone(self, branch: str | None = None) -> None:
4444
self.__delete_tmp_dir()
4545
self.__tmp_dir = create_tmp_dir()
46-
git_options = []
46+
git_options = ["--depth=1"]
4747
url = self.get_clone_url()
4848
if branch:
4949
logging.info("Cloning repository: %s (branch: %s)", url, branch)

tests/git_api/test_git_repo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ def test_clone_unknown_url(self, logging_mock):
166166
self.assertEqual("Error cloning 'invalid_url'", str(ex.value))
167167
logging_mock.info.assert_called_once_with("Cloning repository: %s", self.__mock_repo_api.get_clone_url())
168168

169+
def test_clone_with_depth_1(self):
170+
with GitRepo(self.__mock_repo_api) as testee:
171+
testee.clone()
172+
173+
# Verify that the repository was cloned with depth 1
174+
repo = Repo(testee.get_full_file_path("."))
175+
# A shallow clone with depth 1 should only have the latest commit
176+
commits = list(repo.iter_commits("master"))
177+
self.assertEqual(1, len(commits), "Clone should be shallow with depth 1")
178+
169179
def test_get_full_file_path(self):
170180
with GitRepo(self.__mock_repo_api) as testee:
171181
testee.clone()

0 commit comments

Comments
 (0)