#!/bin/bash
# File: hooks/post-checkout
# Purpose: Automatically sync main branch when switching to dev branch
# Context: Called after git checkout completes. Ensures main is up-to-date with GitHub.

current_branch=$(git symbolic-ref --short HEAD 2>/dev/null)

if [ "$current_branch" = "dev" ]; then
  echo "📦 Syncing main branch from GitHub..."

  # Fetch main from origin without checking out
  git fetch origin main:main --quiet 2>/dev/null

  if [ $? -eq 0 ]; then
    echo "✅ main branch synced from GitHub (independent of Dropbox)"
  else
    echo "⚠️  Failed to sync main from GitHub - check your network connection"
  fi
fi
