#!/bin/bash

# List of all site branches
all_site_branches=("portableweb" "bufearu" "foodpack" "overtones" "matisz" "ndrhorse")

# Make changes to the master branch
git checkout master

# Prompt the user for branch selection
echo "Which branches do you want to update?"
echo "1. Update all branches"
echo "2. Select specific branches"

read -p "Enter your choice (1/2): " choice

if [ "$choice" == "1" ]; then
  # If the user chooses to update all branches
  site_branches=("${all_site_branches[@]}")
elif [ "$choice" == "2" ]; then
  # If the user chooses to select specific branches
  echo "Enter the branch names you want to update (space-separated):"
  read -a selected_branches

  site_branches=()
  for branch in "${selected_branches[@]}"; do
    if [[ " ${all_site_branches[@]} " =~ " $branch " ]]; then
      site_branches+=("$branch")
    else
      echo "Branch '$branch' not found in the list of site branches."
    fi
  done
else
  echo "Invalid choice. Please enter '1' to update all branches or '2' to select specific branches."
  exit 1
fi

# Make changes to the master branch
git checkout master
# Make your changes here
# git add .
# git commit -m "Your commit message"

for branch in "${site_branches[@]}"; do
  echo "Updating branch $branch..."
  git checkout "$branch"
  git merge master
  # Handle conflicts here if necessary
  git commit -m "Merge changes from master"
done

# Return to the master branch
git checkout master