feat: pushing to both remotes
This commit is contained in:
115
push-to-remote.ps1
Normal file
115
push-to-remote.ps1
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
# 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!"
|
||||||
104
push-to-remote.sh
Normal file
104
push-to-remote.sh
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Push to Remote - Choose between GitHub and Gitea
|
||||||
|
# This script lets you choose which remote to push to
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
|
||||||
|
echo -e "${BLUE}║ Portfolio - Push to Remote ║${NC}"
|
||||||
|
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Get current branch
|
||||||
|
CURRENT_BRANCH=$(git branch --show-current)
|
||||||
|
echo -e "${CYAN}Current branch: ${CURRENT_BRANCH}${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check available remotes
|
||||||
|
echo -e "${BLUE}Available remotes:${NC}"
|
||||||
|
git remote -v | grep -E "(origin|gitea)" | head -4
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Ask which remote to push to
|
||||||
|
echo -e "${YELLOW}Where do you want to push?${NC}"
|
||||||
|
echo " 1) GitHub (origin) - https://github.com/denshooter/portfolio.git"
|
||||||
|
echo " 2) Gitea (gitea) - https://git.dk0.dev/denshooter/portfolio.git"
|
||||||
|
echo " 3) Both"
|
||||||
|
echo ""
|
||||||
|
read -p "Choose (1/2/3): " -n 1 -r REMOTE_CHOICE
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
case $REMOTE_CHOICE in
|
||||||
|
1)
|
||||||
|
REMOTE_NAME="origin"
|
||||||
|
REMOTE_DESC="GitHub"
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
REMOTE_NAME="gitea"
|
||||||
|
REMOTE_DESC="Gitea"
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
REMOTE_NAME="both"
|
||||||
|
REMOTE_DESC="Both (GitHub and Gitea)"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "${RED}✗ Invalid choice${NC}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}📋 Pushing to ${REMOTE_DESC}...${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Function to push to a remote
|
||||||
|
push_to_remote() {
|
||||||
|
local remote=$1
|
||||||
|
local desc=$2
|
||||||
|
|
||||||
|
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
echo -e "${BLUE}🚀 Pushing to ${desc} (${remote})...${NC}"
|
||||||
|
|
||||||
|
if git push "$remote" "$CURRENT_BRANCH"; then
|
||||||
|
echo -e "${GREEN}✓ Successfully pushed to ${desc}!${NC}"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo -e "${RED}✗ Push to ${desc} failed${NC}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Push based on choice
|
||||||
|
SUCCESS=true
|
||||||
|
if [ "$REMOTE_NAME" = "both" ]; then
|
||||||
|
push_to_remote "origin" "GitHub" || SUCCESS=false
|
||||||
|
echo ""
|
||||||
|
push_to_remote "gitea" "Gitea" || SUCCESS=false
|
||||||
|
else
|
||||||
|
push_to_remote "$REMOTE_NAME" "$REMOTE_DESC" || SUCCESS=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
if [ "$SUCCESS" = true ]; then
|
||||||
|
echo -e "${GREEN}╔════════════════════════════════════════════════════════════╗${NC}"
|
||||||
|
echo -e "${GREEN}║ Successfully Pushed! 🎉 ║${NC}"
|
||||||
|
echo -e "${GREEN}╚════════════════════════════════════════════════════════════╝${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}📊 Latest commits:${NC}"
|
||||||
|
git log --oneline -3
|
||||||
|
echo ""
|
||||||
|
else
|
||||||
|
echo -e "${RED}✗ Some pushes failed. Check the errors above.${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}✅ Done!${NC}"
|
||||||
Reference in New Issue
Block a user