Files
atlas/scripts/push-to-repo.sh
2025-12-23 07:50:08 +00:00

114 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
#
# Script to push Atlas changes to repository
# This script commits all changes, updates version, and pushes to remote
#
# Usage: ./scripts/push-to-repo.sh [commit message] [--skip-version]
#
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$REPO_ROOT"
# Check if git is available
if ! command -v git &>/dev/null; then
echo -e "${RED}Error: git is not installed${NC}"
exit 1
fi
# Check if we're in a git repository
if ! git rev-parse --git-dir &>/dev/null; then
echo -e "${RED}Error: Not in a git repository${NC}"
exit 1
fi
# Get commit message from argument or use default
COMMIT_MSG="${1:-Update Atlas with VTL features and improvements}"
# Check if --skip-version flag is set
SKIP_VERSION=false
if [[ "$*" == *"--skip-version"* ]]; then
SKIP_VERSION=true
fi
echo -e "${GREEN}Preparing to push changes to repository...${NC}"
# Check for uncommitted changes
if git diff --quiet && git diff --cached --quiet; then
echo -e "${YELLOW}No changes to commit${NC}"
exit 0
fi
# Show status
echo -e "${GREEN}Current git status:${NC}"
git status --short
# Ask for confirmation
read -p "Continue with commit and push? (y/n) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}Aborted${NC}"
exit 0
fi
# Update version if not skipped
if [[ "$SKIP_VERSION" == false ]]; then
echo -e "${GREEN}Updating version...${NC}"
# You can add version update logic here if needed
# For example, update a VERSION file or tag
fi
# Stage all changes
echo -e "${GREEN}Staging all changes...${NC}"
git add -A
# Commit changes
echo -e "${GREEN}Committing changes...${NC}"
git commit -m "$COMMIT_MSG" || {
echo -e "${YELLOW}No changes to commit${NC}"
exit 0
}
# Get current branch
CURRENT_BRANCH=$(git branch --show-current)
echo -e "${GREEN}Current branch: $CURRENT_BRANCH${NC}"
# Check if remote exists
if ! git remote | grep -q origin; then
echo -e "${YELLOW}Warning: No 'origin' remote found${NC}"
read -p "Do you want to set up a remote? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "Enter remote URL: " REMOTE_URL
git remote add origin "$REMOTE_URL"
else
echo -e "${YELLOW}Skipping push (no remote configured)${NC}"
exit 0
fi
fi
# Push to remote
echo -e "${GREEN}Pushing to remote repository...${NC}"
if git push origin "$CURRENT_BRANCH"; then
echo -e "${GREEN}✓ Successfully pushed to repository${NC}"
else
echo -e "${RED}✗ Push failed${NC}"
echo "You may need to:"
echo " 1. Set upstream: git push -u origin $CURRENT_BRANCH"
echo " 2. Pull first: git pull origin $CURRENT_BRANCH"
exit 1
fi
echo -e "${GREEN}Done!${NC}"