Skip to content

Commit 6254480

Browse files
committed
fix: handle null SHA on first push or force push
GitHub sets `github.event.before` to `0000...0000` on first push to a new branch or force push. This caused cargo-rail to fail with: fatal: bad object 0000000000000000000000000000000000000000 Now detects null SHAs and falls back to auto-detection (origin/main, origin/master, or HEAD~1).
1 parent eec017f commit 6254480

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

action.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,18 @@ runs:
242242
id: base
243243
shell: bash
244244
run: |
245-
if [[ -n "${{ inputs.since }}" ]]; then
246-
echo "ref=${{ inputs.since }}" >> "$GITHUB_OUTPUT"
247-
echo "Using provided base: ${{ inputs.since }}"
245+
INPUT_SINCE="${{ inputs.since }}"
246+
247+
# Handle null SHA (first push on new branch or force push)
248+
# GitHub sets before to 0000...0000 in these cases
249+
if [[ "$INPUT_SINCE" =~ ^0+$ ]]; then
250+
echo "Null SHA detected (first push or force push), falling back to auto-detect"
251+
INPUT_SINCE=""
252+
fi
253+
254+
if [[ -n "$INPUT_SINCE" ]]; then
255+
echo "ref=$INPUT_SINCE" >> "$GITHUB_OUTPUT"
256+
echo "Using provided base: $INPUT_SINCE"
248257
elif [[ -n "$GITHUB_BASE_REF" ]]; then
249258
echo "ref=origin/$GITHUB_BASE_REF" >> "$GITHUB_OUTPUT"
250259
echo "PR detected, using: origin/$GITHUB_BASE_REF"

0 commit comments

Comments
 (0)