#!/bin/bash
set -eu

# run inside the repo folder (where this script exists)
cd "$(dirname "$0")"

BRANCH="970566006067"
REMOTE="origin"
SSH_KEY_FILE="$HOME/.ssh/id_ed25519"

# SSH setup (minimal)
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
touch "$HOME/.ssh/known_hosts"
chmod 600 "$HOME/.ssh/known_hosts"
ssh-keygen -F github.com >/dev/null 2>&1 || ssh-keyscan github.com >> "$HOME/.ssh/known_hosts" 2>/dev/null

[ -d ".git" ] || { echo "ERROR: Not a git repository in $(pwd)"; exit 1; }
[ -f "$SSH_KEY_FILE" ] || { echo "ERROR: SSH key not found: $SSH_KEY_FILE"; exit 1; }

export GIT_SSH_COMMAND="ssh -i $SSH_KEY_FILE -o StrictHostKeyChecking=no"

# fetch remote branch
git fetch "$REMOTE" "$BRANCH"

# hard sync with remote branch
git reset --hard "$REMOTE/$BRANCH"
git clean -fd
echo "OK: synced $(pwd) to $REMOTE/$BRANCH"
