<#
.SYNOPSIS
  Git commit + push to Gitea (no sensitive data; credentials come from git config or env).

.DESCRIPTION
  Stages all changes, commits with a timestamp message, and force-pushes to origin/main.
  Run from the repo root or any subdirectory.

  Remote URL is whatever `git remote get-url origin` returns — configure it once:
    git remote set-url origin https://<user>@<host>/arash/audio-voice-converter.git

.PARAMETER Message
  Optional commit message. Defaults to "chore: sync extension files <timestamp>".

.PARAMETER DryRun
  Show what would be committed/pushed without actually doing it.

.EXAMPLE
  .\deploy\scripts\push.ps1
  .\deploy\scripts\push.ps1 -Message "feat: update popup UI"
  .\deploy\scripts\push.ps1 -DryRun
#>
[CmdletBinding()]
param(
    [string]$Message,
    [switch]$DryRun
)

$ErrorActionPreference = "Stop"

# Navigate to repo root (2 levels up from deploy/scripts/)
$repoRoot = Split-Path (Split-Path $PSScriptRoot)
Set-Location $repoRoot

$status = git status --porcelain
if (-not $status) {
    Write-Host "Nothing to commit."
    exit 0
}

$msg = if ($Message) { $Message } else { "chore: sync extension files $(Get-Date -Format 'yyyy-MM-dd HH:mm')" }

Write-Host "Changes to commit:"
git status --short

if ($DryRun) {
    Write-Host "[DryRun] Would commit: $msg"
    Write-Host "[DryRun] Would push: origin main (force)"
    exit 0
}

git add .
git commit -m $msg
git push --force origin main

Write-Host "Push complete."
