diff --git a/tasks/git-clone-checkout/task.yaml b/tasks/git-clone-checkout/task.yaml index 89f9e06..cc1f675 100644 --- a/tasks/git-clone-checkout/task.yaml +++ b/tasks/git-clone-checkout/task.yaml @@ -9,11 +9,11 @@ spec: The commit SHA, committer date, and fetched URL are exposed as Task results. params: - - name: repoUrl + - name: url type: string description: The Git repository URL to clone. - - name: revision + - name: ref type: string default: "" description: The branch or commit SHA to check out. If empty, default branch will be used. @@ -169,16 +169,33 @@ spec: fi echo "[INFO] Cloning repository..." - git clone --depth=$(params.depth) $(params.repoUrl) "$CLONE_DIR" + git clone --depth=$(params.depth) $(params.url) "$CLONE_DIR" cd "$CLONE_DIR" if [ -n "$(params.refspec)" ]; then git fetch origin $(params.refspec) fi - if [ -n "$(params.revision)" ]; then - echo "[INFO] Checking out revision: $(params.revision)" - git checkout $(params.revision) || git checkout -b $(params.revision) origin/$(params.revision) || echo "[WARN] Failed to checkout revision" + REF="$(params.ref)" + if [ -n "$REF" ]; then + if echo "$REF" | grep -q '^refs/heads/'; then + BRANCH="${REF#refs/heads/}" + echo "[INFO] Checking out branch: $BRANCH" + git checkout -b "$BRANCH" "origin/$BRANCH" || git checkout "$BRANCH" + elif echo "$REF" | grep -q '^refs/tags/'; then + TAG="${REF#refs/tags/}" + echo "[INFO] Checking out tag: $TAG" + git fetch --tags + git checkout "tags/$TAG" || git checkout "$TAG" + elif git rev-parse --verify "$REF" >/dev/null 2>&1; then + echo "[INFO] Checking out commit SHA: $REF" + git checkout "$REF" + else + echo "[ERROR] Invalid revision: $REF not found as branch, tag, or commit" + exit 1 + fi + else + echo "[INFO] No revision specified, staying on default branch" fi if [ "$(params.submodules)" = "true" ]; then