Fix resources isues 31
This commit is contained in:
@@ -24,7 +24,7 @@ spec:
|
||||
- name: depth
|
||||
type: string
|
||||
description: Git clone depth (0 for full history, minimum 2 for change detection)
|
||||
default: "2"
|
||||
default: "10"
|
||||
results:
|
||||
- name: commit-sha
|
||||
description: The commit SHA that was checked out
|
||||
@@ -66,6 +66,7 @@ spec:
|
||||
git config --global --add safe.directory "$OUTPUT_PATH"
|
||||
|
||||
# Clone with depth for faster checkout
|
||||
# Note: We need at least 2 commits for change detection (current + parent)
|
||||
if [ "$DEPTH" = "0" ]; then
|
||||
echo "Cloning full repository..."
|
||||
git clone "$URL" "$OUTPUT_PATH"
|
||||
@@ -76,15 +77,42 @@ spec:
|
||||
|
||||
cd "$OUTPUT_PATH"
|
||||
|
||||
# Fetch the specific revision if needed
|
||||
if [ "$REVISION" != "main" ] && [ "$REVISION" != "master" ]; then
|
||||
echo "Fetching revision: $REVISION"
|
||||
git fetch --depth 1 origin "$REVISION" 2>/dev/null || true
|
||||
# If revision is a specific commit SHA (40 hex chars), we need special handling
|
||||
if echo "$REVISION" | grep -qE '^[0-9a-f]{40}$'; then
|
||||
echo "Revision is a commit SHA: $REVISION"
|
||||
|
||||
# Check if commit is already in the clone
|
||||
if ! git cat-file -e "$REVISION" 2>/dev/null; then
|
||||
echo "Commit not in shallow clone, fetching with history..."
|
||||
# Fetch more history to include the specific commit
|
||||
git fetch --deepen="$DEPTH" origin main 2>/dev/null || true
|
||||
git fetch origin "$REVISION" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Ensure we have the parent commit for change detection
|
||||
PARENT_SHA=$(git rev-parse "$REVISION^" 2>/dev/null || echo "")
|
||||
if [ -z "$PARENT_SHA" ]; then
|
||||
echo "Parent commit not available, deepening history..."
|
||||
git fetch --deepen=10 origin 2>/dev/null || true
|
||||
fi
|
||||
elif [ "$REVISION" != "main" ] && [ "$REVISION" != "master" ]; then
|
||||
echo "Fetching branch/tag: $REVISION"
|
||||
git fetch --depth "$DEPTH" origin "$REVISION" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Checkout the revision
|
||||
echo "Checking out: $REVISION"
|
||||
git checkout "$REVISION" 2>/dev/null || git checkout "origin/$REVISION"
|
||||
git checkout "$REVISION" 2>/dev/null || git checkout "origin/$REVISION" 2>/dev/null || git checkout FETCH_HEAD
|
||||
|
||||
# Verify we have enough history for change detection
|
||||
COMMIT_COUNT=$(git rev-list --count HEAD 2>/dev/null || echo "0")
|
||||
echo "Commits available after checkout: $COMMIT_COUNT"
|
||||
if [ "$COMMIT_COUNT" -lt 2 ]; then
|
||||
echo "Warning: Not enough history, fetching more..."
|
||||
git fetch --deepen=10 origin 2>/dev/null || true
|
||||
COMMIT_COUNT=$(git rev-list --count HEAD 2>/dev/null || echo "0")
|
||||
echo "Commits available after deepen: $COMMIT_COUNT"
|
||||
fi
|
||||
|
||||
# Get commit info
|
||||
COMMIT_SHA=$(git rev-parse HEAD)
|
||||
|
||||
Reference in New Issue
Block a user