Skip to content

Commit 2029b49

Browse files
committed
Add 'depth' argument to gitea_api.Repo.clone() and clone_or_update()
1 parent 84ee652 commit 2029b49

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

osc/gitea_api/git.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def fetch_pull_request(
205205
*,
206206
remote: Optional[str] = None,
207207
commit: Optional[str] = None,
208+
depth: Optional[int] = None,
208209
force: bool = False,
209210
):
210211
"""
@@ -220,6 +221,8 @@ def fetch_pull_request(
220221
remote = self.get_current_remote()
221222

222223
cmd = ["fetch", remote, f"pull/{pull_number}/head:{target_branch}"]
224+
if depth:
225+
cmd += ["--depth", str(depth)]
223226
if force:
224227
cmd += [
225228
"--force",

osc/gitea_api/repo.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def clone(
9696
cache_directory: Optional[str] = None,
9797
reference: Optional[str] = None,
9898
reference_if_able: Optional[str] = None,
99+
depth: Optional[int] = None,
99100
ssh_private_key_path: Optional[str] = None,
100101
ssh_strict_host_key_checking: bool = True,
101102
) -> str:
@@ -183,6 +184,9 @@ def clone(
183184
# we want to make the newly cloned repo to be independent, this stops borrowing the objects
184185
cmd += ["--dissociate"]
185186

187+
if depth:
188+
cmd += ["--depth", str(depth)]
189+
186190
if quiet:
187191
cmd += ["--quiet"]
188192

@@ -222,6 +226,7 @@ def clone_or_update(
222226
cache_directory: Optional[str] = None,
223227
reference: Optional[str] = None,
224228
reference_if_able: Optional[str] = None,
229+
depth: Optional[int] = None,
225230
remote: Optional[str] = None,
226231
ssh_private_key_path: Optional[str] = None,
227232
):
@@ -237,6 +242,7 @@ def clone_or_update(
237242
cache_directory=cache_directory,
238243
reference=reference,
239244
reference_if_able=reference_if_able,
245+
depth=depth,
240246
ssh_private_key_path=ssh_private_key_path,
241247
)
242248

@@ -250,7 +256,7 @@ def clone_or_update(
250256
# without it, ``git submodule status`` is broken and returns old data
251257
git.reset()
252258
# checkout the pull request and check if HEAD matches head/sha from Gitea
253-
pr_branch = git.fetch_pull_request(pr_number, commit=commit, force=True)
259+
pr_branch = git.fetch_pull_request(pr_number, commit=commit, depth=depth, force=True)
254260
git.switch(pr_branch)
255261
head_commit = git.get_branch_head()
256262
assert (

0 commit comments

Comments
 (0)