#!/bin/bash
set -e

if ! git rev-parse --abbrev-ref --symbolic-full-name '@{u}' >/dev/null 2>&1; then
  echo "No upstream found, skipping diff-based checks"
  exit 0
fi

if ! git diff '@{u}..HEAD' --quiet -- '*.rs' Cargo.toml Cargo.lock; then
  cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings
fi

if ! git diff '@{u}..HEAD' --quiet -- '*.js' '*.jsx' '*.ts' '*.tsx' '*.json' '*.css' '*.scss' '*.html'; then
  corepack pnpm typecheck
  corepack pnpm lint
fi
