Skip to content

Commit b954ff1

Browse files
Jason Barnettclaude
authored andcommitted
refactor(git-clone): simplify run.sh using POSIX argument building
Replace nested conditionals with a single git clone call that builds arguments dynamically using POSIX-compatible `set --` and `$@`. This reduces code duplication and makes the script easier to maintain. Also switched shebang from bash to sh for better portability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 3210f76 commit b954ff1

File tree

1 file changed

+20
-18
lines changed
  • registry/coder/modules/git-clone

1 file changed

+20
-18
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
22

33
REPO_URL="${REPO_URL}"
44
CLONE_PATH="${CLONE_PATH}"
@@ -37,25 +37,27 @@ fi
3737
# Check if the directory is empty
3838
# and if it is, clone the repo, otherwise skip cloning
3939
if [ -z "$(ls -A "$CLONE_PATH")" ]; then
40-
if [ -z "$BRANCH_NAME" ]; then
41-
echo "Cloning $REPO_URL to $CLONE_PATH..."
42-
if [ "$DEPTH" -gt 0 ]; then
43-
# shellcheck disable=SC2086
44-
git clone --depth "$DEPTH" $CLONE_ARGS "$REPO_URL" "$CLONE_PATH"
45-
else
46-
# shellcheck disable=SC2086
47-
git clone $CLONE_ARGS "$REPO_URL" "$CLONE_PATH"
48-
fi
49-
else
40+
if [ -n "$BRANCH_NAME" ]; then
5041
echo "Cloning $REPO_URL to $CLONE_PATH on branch $BRANCH_NAME..."
51-
if [ "$DEPTH" -gt 0 ]; then
52-
# shellcheck disable=SC2086
53-
git clone --depth "$DEPTH" -b "$BRANCH_NAME" $CLONE_ARGS "$REPO_URL" "$CLONE_PATH"
54-
else
55-
# shellcheck disable=SC2086
56-
git clone -b "$BRANCH_NAME" $CLONE_ARGS "$REPO_URL" "$CLONE_PATH"
57-
fi
42+
else
43+
echo "Cloning $REPO_URL to $CLONE_PATH..."
5844
fi
45+
46+
# Build the git clone command arguments
47+
set --
48+
if [ -n "$DEPTH" ] && [ "$DEPTH" -gt 0 ]; then
49+
set -- "$@" --depth "$DEPTH"
50+
fi
51+
if [ -n "$BRANCH_NAME" ]; then
52+
set -- "$@" -b "$BRANCH_NAME"
53+
fi
54+
# shellcheck disable=SC2086
55+
if [ -n "$CLONE_ARGS" ]; then
56+
set -- "$@" $CLONE_ARGS
57+
fi
58+
set -- "$@" "$REPO_URL" "$CLONE_PATH"
59+
60+
git clone "$@"
5961
else
6062
echo "$CLONE_PATH already exists and isn't empty, skipping clone!"
6163
fi

0 commit comments

Comments
 (0)