#!/bin/bash

# Check Backup Location Script

PROJECT_DIR="/var/www/html/erp_codearya"
cd "$PROJECT_DIR"

echo "=== Git Backup Location Information ==="
echo ""

# Current directory
echo "📁 Project Directory:"
echo "   $(pwd)"
echo ""

# Git repository location
echo "💾 Backup Storage Location:"
echo "   $(pwd)/.git/"
echo ""

# Backup size
if [ -d ".git" ]; then
    BACKUP_SIZE=$(du -sh .git | cut -f1)
    echo "📊 Backup Size:"
    echo "   $BACKUP_SIZE"
    echo ""
    
    # Number of commits
    COMMIT_COUNT=$(git rev-list --all --count 2>/dev/null || echo "0")
    echo "📝 Number of Commits:"
    echo "   $COMMIT_COUNT"
    echo ""
    
    # Number of build tags
    BUILD_TAG_COUNT=$(git tag -l "build-*" | wc -l | tr -d ' ')
    echo "🏷️  Number of Build Tags:"
    echo "   $BUILD_TAG_COUNT"
    echo ""
    
    # Remote backup status
    echo "🌐 Remote Backup Status:"
    if git remote | grep -q .; then
        echo "   ✅ Remote configured:"
        git remote -v | sed 's/^/      /'
        echo ""
        echo "   Last push status:"
        if git log origin/master -1 >/dev/null 2>&1; then
            LAST_PUSH=$(git log origin/master -1 --format="%ai" 2>/dev/null)
            echo "      Last pushed: $LAST_PUSH"
        else
            echo "      ⚠️  No remote backup found"
        fi
    else
        echo "   ⚠️  No remote backup configured"
        echo "   📖 See SETUP_REMOTE_BACKUP.md for setup instructions"
    fi
    echo ""
    
    # Recent builds
    echo "📋 Recent Builds:"
    ./list-builds.sh 2>/dev/null | tail -10 || echo "   No builds found"
else
    echo "   ❌ Git repository not initialized!"
fi

echo ""
echo "=== Backup Information Complete ==="
