@@ -383,41 +383,52 @@ runs:
383383 echo "::warning::No remote branch found, using HEAD~1"
384384 fi
385385
386- # Validate git state for reliable change detection
387- - name : Validate git state
386+ # Ensure git history is available for change detection
387+ - name : Ensure git history
388388 id : validate
389389 shell : bash
390390 env :
391391 BASE_REF : ${{ steps.base.outputs.ref }}
392392 run : |
393393 set -euo pipefail
394394
395- # Check for shallow clone
395+ # Track if we're in a shallow clone
396396 if [[ -f .git/shallow ]]; then
397- echo "::warning::Shallow clone detected. For accurate change detection, use 'fetch-depth: 0' in actions/checkout."
398397 echo "shallow=true" >> "$GITHUB_OUTPUT"
399398 else
400399 echo "shallow=false" >> "$GITHUB_OUTPUT"
401400 fi
402401
403- # Validate base ref exists and is resolvable
404- # Relative refs (HEAD~N) just need the commit to exist
405- # Branch refs need merge-base to find common ancestor
402+ # Check if base ref is resolvable; if not, fetch needed history
406403 if [[ "$BASE_REF" =~ ^HEAD~[0-9]+$ ]]; then
407- # Relative ref: verify commit exists
404+ # Relative ref: check if commit exists
408405 if ! git rev-parse "$BASE_REF" &>/dev/null; then
409406 depth="${BASE_REF#HEAD~}"
410- min_depth=$((depth + 1))
411- echo "::error::Cannot resolve $BASE_REF. Shallow clone lacks history. Use 'fetch-depth: $min_depth' or 'fetch-depth: 0' in actions/checkout."
407+ fetch_depth=$((depth + 1))
408+ echo "Fetching $fetch_depth commits for $BASE_REF..."
409+ git fetch --depth="$fetch_depth" origin HEAD
410+ fi
411+ else
412+ # Branch ref: check if merge-base is resolvable
413+ if ! git merge-base HEAD "$BASE_REF" &>/dev/null; then
414+ echo "Fetching history for merge-base with $BASE_REF..."
415+ git fetch --unshallow origin || git fetch origin "$BASE_REF"
416+ fi
417+ fi
418+
419+ # Final verification
420+ if [[ "$BASE_REF" =~ ^HEAD~[0-9]+$ ]]; then
421+ if ! git rev-parse "$BASE_REF" &>/dev/null; then
422+ echo "::error::Cannot resolve $BASE_REF after fetch. Check repository state."
412423 exit 1
413424 fi
414425 else
415- # Branch ref: verify merge-base is resolvable
416426 if ! git merge-base HEAD "$BASE_REF" &>/dev/null; then
417- echo "::error::Cannot resolve merge-base between HEAD and $BASE_REF. Ensure ' fetch-depth: 0' in actions/checkout ."
427+ echo "::error::Cannot resolve merge-base with $BASE_REF after fetch. Check repository state ."
418428 exit 1
419429 fi
420430 fi
431+ echo "Base ref $BASE_REF verified"
421432
422433 # Run planner and emit selected output mode
423434 - name : Run cargo-rail plan
0 commit comments