Skip to content

Instantly share code, notes, and snippets.

@eduard-un
Created March 26, 2025 13:03
Show Gist options
  • Save eduard-un/96f008dee83f92979448961e38ebebb9 to your computer and use it in GitHub Desktop.
Save eduard-un/96f008dee83f92979448961e38ebebb9 to your computer and use it in GitHub Desktop.
Checkout branches
#!/usr/bin/env bash
set -e
ROOT_DIR=$(pwd)
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
CACHE_DIR="$HOME/Library/Caches/Google/Chrome/Default/Cache"
function green {
printf "\e[32m%s\e[0m\n" "${1}"
}
# Array of paths and their corresponding names
declare -A REPOS=(
["/"]="ROOT"
["/ai-app/"]="AI"
["/cloud/"]="CLOUD"
["/common/"]="COMMON"
["/core/"]="CORE"
["/epanel/"]="EPANEL"
["/includes/builder/"]="BUILDER"
["/includes/builder-5/"]="BUILDER5"
)
read -p "Enter branch name: " BRANCH
BRANCH=${BRANCH:-master} # Default to master if none entered
echo -e "\n${BOLD}Pulling latest changes from ${BRANCH} branch in all repos:${NORMAL}\n"
# Function to process each repository
process_repo() {
local path=$1
local name=$2
echo -e "\nProcessing ${BOLD}${name}${NORMAL} at ${ROOT_DIR}${path}"
repo_path="${ROOT_DIR}${path}"
if [ ! -d "${repo_path}" ]; then
echo "Directory ${repo_path} does not exist. Skipping..."
return
fi
# Change directory explicitly for clarity
cd "${repo_path}"
# Skip stash if no changes
if ! git diff --quiet; then
echo "Stashing local changes..."
git stash
git stash drop || echo "No stash entries found"
fi
echo "Fetching and checking branch ${BRANCH}..."
git fetch --quiet origin
# Checkout branch if exists locally or remotely
if git show-ref --verify --quiet "refs/heads/${BRANCH}"; then
git checkout "${BRANCH}" --quiet
elif git ls-remote --heads origin "${BRANCH}" &> /dev/null; then
git checkout -b "${BRANCH}" origin/"${BRANCH}" --quiet
else
echo "Branch ${BRANCH} does not exist in ${name}"
return
fi
git pull --quiet || echo "Failed to pull latest changes in ${name}"
echo "${BOLD}${name}${NORMAL} updated to branch ${BRANCH}."
}
# Run all repository processing in parallel
for path in "${!REPOS[@]}"; do
process_repo "$path" "${REPOS[$path]}" &
done
# Wait for all background tasks to finish
wait
# Delete the et-cache folder
ET_CACHE_PATH="/Users/ed/Herd/d5/wp-content/et-cache"
if [ -d "$ET_CACHE_PATH" ]; then
echo -e "\nDeleting et-cache folder at $ET_CACHE_PATH..."
rm -rf "$ET_CACHE_PATH"
green "et-cache folder deleted successfully!"
else
echo -e "\net-cache folder does not exist at $ET_CACHE_PATH."
fi
# Clear WordPress caches
echo -e "\nClearing WordPress caches..."
wp cache flush --quiet
wp transient delete --all --quiet
# Call Divi's comprehensive cache clearing function
echo -e "Clearing Divi and third-party caches..."
wp eval 'et_core_clear_wp_cache();'
green "All caches cleared successfully!"
wp plugin activate svg-support
wp plugin deactivate svg-support
# Clear Chrome cache
if [ -d "$CACHE_DIR" ]; then
rm -rf "$CACHE_DIR"/*
echo "Chrome cache cleared."
else
echo "Chrome cache folder not found."
fi
green "${BOLD}All tasks completed!"
cd "$ROOT_DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment