#!/bin/bash # Smart Git Push Script - Token-efficient commits # Usage: ./git_push.sh [optional custom message] set -e # Exit on any error # Create log file with timestamp LOG_FILE="git_push.log" echo "=== Git Push Log - $(date) ===" >> "$LOG_FILE" # Colors for output GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' NC='\033[0m' # No Color echo -e "${BLUE}🚀 Smart Git Push${NC}" # Check if we're in a git repo if ! git rev-parse --git-dir > /dev/null 2>&1; then echo -e "${RED}❌ Not in a git repository${NC}" echo "ERROR: Not in a git repository" >> "$LOG_FILE" exit 1 fi # Check if there are any changes (including untracked files) if git diff --quiet && git diff --staged --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then echo -e "${GREEN}✅ No changes to commit${NC}" echo "INFO: No changes to commit" >> "$LOG_FILE" exit 0 fi # Auto-detect change types (include untracked files) MODIFIED_FILES=$(git diff --name-only HEAD 2>/dev/null; git diff --name-only --staged 2>/dev/null; git ls-files --others --exclude-standard 2>/dev/null | head -10) CHANGE_TYPES=() if echo "$MODIFIED_FILES" | grep -q "\.py$"; then CHANGE_TYPES+=("Python code") fi if echo "$MODIFIED_FILES" | grep -q "webserver\.py\|\.html$\|\.css$"; then CHANGE_TYPES+=("web interface") fi if echo "$MODIFIED_FILES" | grep -q "database\.py\|\.sql$"; then CHANGE_TYPES+=("database") fi if echo "$MODIFIED_FILES" | grep -q "modules/"; then CHANGE_TYPES+=("bot modules") fi if echo "$MODIFIED_FILES" | grep -q "\.json$\|config/"; then CHANGE_TYPES+=("configuration") fi if echo "$MODIFIED_FILES" | grep -q "\.md$\|README\|\.txt$"; then CHANGE_TYPES+=("documentation") fi if echo "$MODIFIED_FILES" | grep -q "\.sh$\|\.py$" && echo "$MODIFIED_FILES" | grep -q "test\|fix\|bug"; then CHANGE_TYPES+=("bug fixes") fi # Generate commit message if [ $# -gt 0 ]; then # Use provided message COMMIT_MSG="$*" else # Auto-generate message if [ ${#CHANGE_TYPES[@]} -eq 0 ]; then COMMIT_MSG="Update project files" elif [ ${#CHANGE_TYPES[@]} -eq 1 ]; then COMMIT_MSG="Update ${CHANGE_TYPES[0]}" else # Join array elements with commas IFS=', ' COMMIT_MSG="Update ${CHANGE_TYPES[*]}" unset IFS fi # Add timestamp for auto-generated messages COMMIT_MSG="$COMMIT_MSG - $(date '+%Y-%m-%d %H:%M')" fi # Add footer COMMIT_MSG="$COMMIT_MSG 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude " # Log the operation details echo "Files changed: $MODIFIED_FILES" >> "$LOG_FILE" echo "Commit message: $COMMIT_MSG" >> "$LOG_FILE" # Stage all changes echo -e "${BLUE}📦 Staging changes...${NC}" git add . 2>> "$LOG_FILE" # Commit echo -e "${BLUE}💾 Committing...${NC}" git commit -m "$COMMIT_MSG" >> "$LOG_FILE" 2>&1 # Push echo -e "${BLUE}⬆️ Pushing to origin...${NC}" git push origin main >> "$LOG_FILE" 2>&1 echo -e "${GREEN}✅ Successfully pushed to git!${NC}" # Show summary (minimal) CHANGED_COUNT=$(echo "$MODIFIED_FILES" | wc -l) echo -e "${GREEN}📊 Pushed $CHANGED_COUNT file(s)${NC}" # Log success echo "SUCCESS: Push completed at $(date)" >> "$LOG_FILE" echo "" >> "$LOG_FILE"