116 lines
3.8 KiB
PowerShell
116 lines
3.8 KiB
PowerShell
# Push to Remote - Choose between GitHub and Gitea
|
|
# PowerShell script for Windows
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Write-ColorOutput($ForegroundColor) {
|
|
$fc = $host.UI.RawUI.ForegroundColor
|
|
$host.UI.RawUI.ForegroundColor = $ForegroundColor
|
|
if ($args) {
|
|
Write-Output $args
|
|
}
|
|
$host.UI.RawUI.ForegroundColor = $fc
|
|
}
|
|
|
|
Write-ColorOutput Cyan "╔════════════════════════════════════════════════════════════╗"
|
|
Write-ColorOutput Cyan "║ Portfolio - Push to Remote ║"
|
|
Write-ColorOutput Cyan "╚════════════════════════════════════════════════════════════╝"
|
|
Write-Output ""
|
|
|
|
# Get current branch
|
|
$currentBranch = git branch --show-current
|
|
Write-ColorOutput Cyan "Current branch: $currentBranch"
|
|
Write-Output ""
|
|
|
|
# Check available remotes
|
|
Write-ColorOutput Cyan "Available remotes:"
|
|
git remote -v | Select-String -Pattern "(origin|gitea)" | Select-Object -First 4
|
|
Write-Output ""
|
|
|
|
# Ask which remote to push to
|
|
Write-ColorOutput Yellow "Where do you want to push?"
|
|
Write-Output " 1) GitHub (origin) - https://github.com/denshooter/portfolio.git"
|
|
Write-Output " 2) Gitea (gitea) - https://git.dk0.dev/denshooter/portfolio.git"
|
|
Write-Output " 3) Both"
|
|
Write-Output ""
|
|
$remoteChoice = Read-Host "Choose (1/2/3)"
|
|
|
|
switch ($remoteChoice) {
|
|
"1" {
|
|
$remoteName = "origin"
|
|
$remoteDesc = "GitHub"
|
|
}
|
|
"2" {
|
|
$remoteName = "gitea"
|
|
$remoteDesc = "Gitea"
|
|
}
|
|
"3" {
|
|
$remoteName = "both"
|
|
$remoteDesc = "Both (GitHub and Gitea)"
|
|
}
|
|
default {
|
|
Write-ColorOutput Red "✗ Invalid choice"
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
Write-Output ""
|
|
Write-ColorOutput Cyan "📋 Pushing to $remoteDesc..."
|
|
Write-Output ""
|
|
|
|
# Function to push to a remote
|
|
function Push-ToRemote {
|
|
param(
|
|
[string]$Remote,
|
|
[string]$Desc
|
|
)
|
|
|
|
Write-ColorOutput Cyan "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
Write-ColorOutput Cyan "🚀 Pushing to $Desc ($Remote)..."
|
|
|
|
try {
|
|
git push $Remote $currentBranch
|
|
Write-ColorOutput Green "✓ Successfully pushed to $Desc!"
|
|
return $true
|
|
}
|
|
catch {
|
|
Write-ColorOutput Red "✗ Push to $Desc failed"
|
|
Write-Output $_.Exception.Message
|
|
return $false
|
|
}
|
|
}
|
|
|
|
# Push based on choice
|
|
$success = $true
|
|
if ($remoteName -eq "both") {
|
|
if (-not (Push-ToRemote -Remote "origin" -Desc "GitHub")) {
|
|
$success = $false
|
|
}
|
|
Write-Output ""
|
|
if (-not (Push-ToRemote -Remote "gitea" -Desc "Gitea")) {
|
|
$success = $false
|
|
}
|
|
}
|
|
else {
|
|
if (-not (Push-ToRemote -Remote $remoteName -Desc $remoteDesc)) {
|
|
$success = $false
|
|
}
|
|
}
|
|
|
|
Write-Output ""
|
|
if ($success) {
|
|
Write-ColorOutput Green "╔════════════════════════════════════════════════════════════╗"
|
|
Write-ColorOutput Green "║ Successfully Pushed! 🎉 ║"
|
|
Write-ColorOutput Green "╚════════════════════════════════════════════════════════════╝"
|
|
Write-Output ""
|
|
Write-ColorOutput Cyan "📊 Latest commits:"
|
|
git log --oneline -3
|
|
Write-Output ""
|
|
}
|
|
else {
|
|
Write-ColorOutput Red "✗ Some pushes failed. Check the errors above."
|
|
exit 1
|
|
}
|
|
|
|
Write-ColorOutput Green "✅ Done!"
|