Skip to content

Commit 5ec9043

Browse files
bsaussayBrice Saussay
andauthored
operations.git.repo: add depth support (#1656)
Co-authored-by: Brice Saussay <brice.saussay@navya.tech>
1 parent e7c2236 commit 5ec9043

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/pyinfra/operations/git.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def repo(
9393
ssh_keyscan=False,
9494
update_submodules=False,
9595
recursive_submodules=False,
96+
depth: int | None = None,
9697
):
9798
"""
9899
Clone/pull git repositories.
@@ -107,6 +108,7 @@ def repo(
107108
+ ssh_keyscan: keyscan the remote host if not in known_hosts before clone/pull
108109
+ update_submodules: update any git submodules
109110
+ recursive_submodules: update git submodules recursively
111+
+ depth: create a shallow clone with a history truncated to the specified number of commits
110112
111113
**Example:**
112114
@@ -141,12 +143,14 @@ def repo(
141143

142144
# Cloning new repo?
143145
if not is_repo:
146+
options: list[str | QuoteString] = []
147+
if depth is not None:
148+
options.extend(["--depth", str(depth)])
144149
if branch:
145-
git_commands.append(
146-
StringCommand("clone", QuoteString(src), "--branch", QuoteString(branch), ".")
147-
)
148-
else:
149-
git_commands.append(StringCommand("clone", QuoteString(src), "."))
150+
options.extend(["--branch", QuoteString(branch)])
151+
152+
git_commands.append(StringCommand("clone", QuoteString(src), *options, "."))
153+
150154
# Ensuring existing repo
151155
else:
152156
is_tag = False

0 commit comments

Comments
 (0)