Files
sovereign_ai/SovereignAI-Starter/push.ps1
T

45 lines
1.2 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$repoPath = Split-Path -Parent $MyInvocation.MyCommand.Path
$expectedOrigin = 'https://git.intaleqapp.com/Hamza/sovereign_ai.git'
$message = if ($args.Count -gt 0) { $args -join ' ' } else { 'Update SovereignAI project' }
Push-Location $repoPath
try {
$origin = git remote get-url origin
if ($LASTEXITCODE -ne 0) {
throw 'Could not read the origin remote.'
}
if ($origin.Trim() -ne $expectedOrigin) {
throw "Unexpected origin '$origin'; expected '$expectedOrigin'."
}
$branch = git branch --show-current
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($branch)) {
throw 'Cannot push from a detached HEAD or unreadable branch.'
}
git add -A
if ($LASTEXITCODE -ne 0) {
throw 'git add failed.'
}
git diff --cached --quiet
$diffExitCode = $LASTEXITCODE
if ($diffExitCode -eq 1) {
git commit -m $message
if ($LASTEXITCODE -ne 0) {
throw 'git commit failed.'
}
} elseif ($diffExitCode -ne 0) {
throw 'Could not inspect the staged changes.'
}
git push --set-upstream origin $branch
if ($LASTEXITCODE -ne 0) {
throw 'git push failed.'
}
} finally {
Pop-Location
}