#!/bin/bash # Sync script for pushing to both Hugging Face and Azure DevOps repositories # Usage: ./sync_repos.sh [commit_message] set -e # Exit on any error # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}🔄 Starting repository sync...${NC}" # Check if we're in a git repository if ! git rev-parse --git-dir > /dev/null 2>&1; then echo -e "${RED}❌ Error: Not in a git repository${NC}" exit 1 fi # Check for uncommitted changes if ! git diff-index --quiet HEAD --; then echo -e "${YELLOW}⚠️ You have uncommitted changes. Please commit them first.${NC}" echo -e "${YELLOW} Run: git add . && git commit -m \"your message\"${NC}" exit 1 fi # Get commit message from argument or use default COMMIT_MSG=${1:-"Auto-sync: $(date '+%Y-%m-%d %H:%M:%S')"} echo -e "${GREEN}📝 Commit message: ${COMMIT_MSG}${NC}" # Add all changes and commit echo -e "${GREEN}📦 Adding and committing changes...${NC}" git add . git commit -m "$COMMIT_MSG" # Push to Hugging Face (origin) echo -e "${GREEN}🚀 Pushing to Hugging Face (origin)...${NC}" if git push origin main; then echo -e "${GREEN}✅ Successfully pushed to Hugging Face${NC}" else echo -e "${RED}❌ Failed to push to Hugging Face${NC}" exit 1 fi # Push to Azure DevOps (azure) echo -e "${GREEN}🚀 Pushing to Azure DevOps (azure)...${NC}" if git push azure main; then echo -e "${GREEN}✅ Successfully pushed to Azure DevOps${NC}" else echo -e "${YELLOW}⚠️ Failed to push to Azure DevOps, trying force push...${NC}" if git push azure main --force; then echo -e "${GREEN}✅ Successfully force pushed to Azure DevOps${NC}" else echo -e "${RED}❌ Failed to push to Azure DevOps${NC}" exit 1 fi fi echo -e "${GREEN}🎉 Repository sync completed successfully!${NC}" echo -e "${GREEN}📊 Remotes configured:${NC}" git remote -v