#!/bin/bash

# hmm - A safety wrapper for git push to prevent accidental pushes to origin
# Version: 1.0.0

git() {
  if [[ "$1" == "push" && "$2" == "origin" && -z "$3" ]]; then

    # ANSI colors
    RED='\033[0;31m'
    YELLOW='\033[1;33m'
    CYAN='\033[0;36m'
    NC='\033[0m' # No Color

    # Different warning messages
    WARNINGS=(
      "${RED}  DANGER: You are pushing to ORIGIN without a branch!${NC}"
      "${YELLOW}  WARNING: This may overwrite or break things on origin!${NC}"
      "${CYAN}  FINAL CHECK: Do you really want to do this?${NC}"
    )

    for i in {1..3}; do
      echo -e "${WARNINGS[$i]}"
      echo -n "Type 'yes' to confirm [$i/3]: "
      read answer
      if [[ "$answer" != "yes" ]]; then
        echo "Push cancelled."
        return 1
      fi
    done
  fi

  # Call the real git
  command git "$@"
}

# Export the function so it's available in the current shell
export -f git

