Skip to content

Commit 7a0d546

Browse files
Jason Barnettclaude
authored andcommitted
feat(git-clone): add clone_args variable for custom git clone arguments
Allow users to pass additional arguments to the git clone command via a new `clone_args` variable. This enables use cases like using a local mirror with `--reference` to speed up cloning large repositories. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e3f8b64 commit 7a0d546

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

registry/coder/modules/git-clone/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,35 @@ module "git-clone" {
199199
}
200200
```
201201

202+
## Custom clone arguments
203+
204+
Pass additional arguments to the git clone command using the `clone_args` variable.
205+
This is useful for scenarios like using a local mirror with `--reference` to speed up cloning.
206+
207+
```tf
208+
module "git-clone" {
209+
count = data.coder_workspace.me.start_count
210+
source = "registry.coder.com/coder/git-clone/coder"
211+
version = "1.2.2"
212+
agent_id = coder_agent.example.id
213+
url = "https://github.com/coder/coder"
214+
clone_args = "--reference /mnt/git-mirrors/coder.git"
215+
}
216+
```
217+
218+
You can also combine multiple arguments:
219+
220+
```tf
221+
module "git-clone" {
222+
count = data.coder_workspace.me.start_count
223+
source = "registry.coder.com/coder/git-clone/coder"
224+
version = "1.2.2"
225+
agent_id = coder_agent.example.id
226+
url = "https://github.com/coder/coder"
227+
clone_args = "--reference /mnt/git-mirrors/coder.git --dissociate"
228+
}
229+
```
230+
202231
## Post-clone script
203232

204233
Run a custom script after cloning the repository by setting the `post_clone_script` variable.

registry/coder/modules/git-clone/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ variable "post_clone_script" {
6868
default = null
6969
}
7070

71+
variable "clone_args" {
72+
description = "Additional arguments to pass to the git clone command (e.g., '--reference /path/to/mirror' for using a local mirror)."
73+
type = string
74+
default = ""
75+
}
76+
7177
locals {
7278
# Remove query parameters and fragments from the URL
7379
url = replace(replace(var.url, "/\\?.*/", ""), "/#.*/", "")
@@ -129,6 +135,7 @@ resource "coder_script" "git_clone" {
129135
BRANCH_NAME : local.branch_name,
130136
DEPTH = var.depth,
131137
POST_CLONE_SCRIPT : local.encoded_post_clone_script,
138+
CLONE_ARGS : var.clone_args,
132139
})
133140
display_name = "Git Clone"
134141
icon = "/icon/git.svg"

registry/coder/modules/git-clone/run.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ BRANCH_NAME="${BRANCH_NAME}"
77
CLONE_PATH="$${CLONE_PATH/#\~/$${HOME}}"
88
DEPTH="${DEPTH}"
99
POST_CLONE_SCRIPT="${POST_CLONE_SCRIPT}"
10+
CLONE_ARGS="${CLONE_ARGS}"
1011

1112
# Check if the variable is empty...
1213
if [ -z "$REPO_URL" ]; then
@@ -39,16 +40,20 @@ if [ -z "$(ls -A "$CLONE_PATH")" ]; then
3940
if [ -z "$BRANCH_NAME" ]; then
4041
echo "Cloning $REPO_URL to $CLONE_PATH..."
4142
if [ "$DEPTH" -gt 0 ]; then
42-
git clone --depth "$DEPTH" "$REPO_URL" "$CLONE_PATH"
43+
# shellcheck disable=SC2086
44+
git clone --depth "$DEPTH" $CLONE_ARGS "$REPO_URL" "$CLONE_PATH"
4345
else
44-
git clone "$REPO_URL" "$CLONE_PATH"
46+
# shellcheck disable=SC2086
47+
git clone $CLONE_ARGS "$REPO_URL" "$CLONE_PATH"
4548
fi
4649
else
4750
echo "Cloning $REPO_URL to $CLONE_PATH on branch $BRANCH_NAME..."
4851
if [ "$DEPTH" -gt 0 ]; then
49-
git clone --depth "$DEPTH" -b "$BRANCH_NAME" "$REPO_URL" "$CLONE_PATH"
52+
# shellcheck disable=SC2086
53+
git clone --depth "$DEPTH" -b "$BRANCH_NAME" $CLONE_ARGS "$REPO_URL" "$CLONE_PATH"
5054
else
51-
git clone "$REPO_URL" -b "$BRANCH_NAME" "$CLONE_PATH"
55+
# shellcheck disable=SC2086
56+
git clone -b "$BRANCH_NAME" $CLONE_ARGS "$REPO_URL" "$CLONE_PATH"
5257
fi
5358
fi
5459
else

0 commit comments

Comments
 (0)