diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5db0582..d9f5dfa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,8 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + # Fetch tags and refs to get full history including force-pushed commits + fetch-tags: true - name: Set up Python uses: actions/setup-python@v5 @@ -83,6 +85,13 @@ jobs: echo "First push -- linting HEAD commit only" python lint_local.py --last 1 --model qwen2.5:0.5b else - echo "Linting commits ${BEFORE:0:8}..${AFTER:0:8}" - python lint_local.py --range "${BEFORE}..${AFTER}" --model qwen2.5:0.5b + # Check if the BEFORE commit exists (could be missing after force push) + if git cat-file -t "$BEFORE" >/dev/null 2>&1; then + echo "Linting commits ${BEFORE:0:8}..${AFTER:0:8}" + python lint_local.py --range "${BEFORE}..${AFTER}" --model qwen2.5:0.5b + else + echo "WARNING: Base commit $BEFORE does not exist (possibly force-pushed)." + echo "Falling back to linting the last commit only." + python lint_local.py --last 1 --model qwen2.5:0.5b + fi fi diff --git a/lint_local.py b/lint_local.py index 6b30e9b..ffd1f88 100644 --- a/lint_local.py +++ b/lint_local.py @@ -199,7 +199,27 @@ def git_log(revision_range: str | None = None, last_n: int | None = None) -> lis else: cmd.extend(["-n", "5"]) - result = subprocess.run(cmd, capture_output=True, text=True, check=True) + try: + result = subprocess.run(cmd, capture_output=True, text=True, check=True) + except subprocess.CalledProcessError as exc: + # Common issue: base commit doesn't exist (force push, wrong branch, etc.) + if revision_range and exc.returncode == 128: + stderr = exc.stderr.strip() + print( + f"ERROR: git log failed for range '{revision_range}'.\n" + f"Git error: {stderr}\n" + f"\n" + f"Common causes:\n" + f" - The base commit was force-pushed over and no longer exists\n" + f" - Shallow clone in CI (need fetch-depth: 0)\n" + f" - The base commit is from a different branch\n" + f"\n" + f"Suggestion: Check if the base commit exists with:\n" + f" git cat-file -t {revision_range.split('..')[0] if '..' in revision_range else 'BASE_SHA'}\n", + file=sys.stderr + ) + raise + raw = result.stdout.strip() if not raw: return []