Skip to content

Commit ba4496d

Browse files
committed
fix: distinguish relative refs from branch refs in git validation
Note: Relative refs (HEAD~N) only need the commit to exist; branch refs need merge-base resolution. Also provide minimum fetch-depth in error message.
1 parent b71bff7 commit ba4496d

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

action.yaml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,31 @@ runs:
392392
run: |
393393
set -euo pipefail
394394
395-
# Check for shallow clone (may cause inaccurate change detection)
395+
# Check for shallow clone
396396
if [[ -f .git/shallow ]]; then
397397
echo "::warning::Shallow clone detected. For accurate change detection, use 'fetch-depth: 0' in actions/checkout."
398398
echo "shallow=true" >> "$GITHUB_OUTPUT"
399399
else
400400
echo "shallow=false" >> "$GITHUB_OUTPUT"
401401
fi
402402
403-
# Verify merge-base is resolvable
404-
if ! git merge-base HEAD "$BASE_REF" &>/dev/null; then
405-
echo "::error::Cannot resolve merge-base between HEAD and $BASE_REF. Ensure 'fetch-depth: 0' in actions/checkout."
406-
exit 1
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
406+
if [[ "$BASE_REF" =~ ^HEAD~[0-9]+$ ]]; then
407+
# Relative ref: verify commit exists
408+
if ! git rev-parse "$BASE_REF" &>/dev/null; then
409+
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."
412+
exit 1
413+
fi
414+
else
415+
# Branch ref: verify merge-base is resolvable
416+
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."
418+
exit 1
419+
fi
407420
fi
408421
409422
# Run planner and emit selected output mode

0 commit comments

Comments
 (0)