stones/push-to-gitea.sh

56 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Script to push changes to Gitea repository
set -e # Exit immediately if a command exits with a non-zero status
# Colors for pretty output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Check if git is installed
if ! command -v git &> /dev/null; then
echo -e "${RED}Error: git is not installed. Please install git first.${NC}"
exit 1
fi
# Check if we're in a git repository
if ! git rev-parse --is-inside-work-tree &> /dev/null; then
echo -e "${RED}Error: Not a git repository. Please run this script from within a git repository.${NC}"
exit 1
fi
# Check if remote already exists
if git remote | grep -q "gitea"; then
echo -e "${YELLOW}Remote 'gitea' already exists.${NC}"
else
echo -e "${YELLOW}Adding 'gitea' remote...${NC}"
git remote add gitea git@git.boilerhaus.org:boiler/stones.git
fi
# Get current branch
CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
echo -e "${YELLOW}Current branch: ${CURRENT_BRANCH}${NC}"
# Check for uncommitted changes
if ! git diff-index --quiet HEAD --; then
echo -e "${YELLOW}You have uncommitted changes.${NC}"
read -p "Do you want to commit them? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "Enter commit message: " COMMIT_MSG
git add .
git commit -m "$COMMIT_MSG"
else
echo -e "${YELLOW}Continuing without committing changes.${NC}"
fi
fi
# Push to Gitea
echo -e "${YELLOW}Pushing to Gitea...${NC}"
git push -u gitea $CURRENT_BRANCH
echo -e "${GREEN}Successfully pushed to Gitea!${NC}"
echo -e "${GREEN}Repository URL: git@git.boilerhaus.org:boiler/stones.git${NC}"
echo -e "${YELLOW}To deploy, run the deploy.sh script on your server.${NC}"