mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2026-01-04 12:09:39 -06:00
Add automatic branch switching for updates
- Added branch detection and switching logic to both scripts - manage-patchmon-dev.sh: automatically switches instances to dev branch - manage-patchmon.sh: automatically switches instances to main branch - Handles local changes by stashing before branch switch - Creates local branch from origin if it doesn't exist locally - Fixes issue where main branch instances couldn't be updated with dev script
This commit is contained in:
@@ -2335,6 +2335,31 @@ update_single_instance() {
|
||||
|
||||
cd "$app_dir"
|
||||
|
||||
# Check current branch and switch to dev if needed
|
||||
local current_branch=$(git branch --show-current 2>/dev/null || echo "unknown")
|
||||
if [ "$current_branch" != "dev" ]; then
|
||||
print_info "Current branch: $current_branch, switching to dev branch..."
|
||||
|
||||
# Stash any local changes before switching
|
||||
if git status --porcelain | grep -q .; then
|
||||
print_info "Stashing local changes before branch switch..."
|
||||
git stash push -m "Auto-stash before switching to dev branch $(date)"
|
||||
fi
|
||||
|
||||
# Switch to dev branch
|
||||
if git checkout dev 2>/dev/null; then
|
||||
print_status "Successfully switched to dev branch"
|
||||
else
|
||||
# If dev branch doesn't exist locally, create it from origin/dev
|
||||
print_info "Creating local dev branch from origin/dev..."
|
||||
git fetch origin dev
|
||||
git checkout -b dev origin/dev
|
||||
print_status "Created and switched to dev branch"
|
||||
fi
|
||||
else
|
||||
print_info "Already on dev branch"
|
||||
fi
|
||||
|
||||
# Backup database first
|
||||
print_info "Creating database backup..."
|
||||
|
||||
|
||||
@@ -2330,6 +2330,31 @@ update_single_instance() {
|
||||
|
||||
cd "$app_dir"
|
||||
|
||||
# Check current branch and switch to main if needed (for main script)
|
||||
local current_branch=$(git branch --show-current 2>/dev/null || echo "unknown")
|
||||
if [ "$current_branch" != "main" ]; then
|
||||
print_info "Current branch: $current_branch, switching to main branch..."
|
||||
|
||||
# Stash any local changes before switching
|
||||
if git status --porcelain | grep -q .; then
|
||||
print_info "Stashing local changes before branch switch..."
|
||||
git stash push -m "Auto-stash before switching to main branch $(date)"
|
||||
fi
|
||||
|
||||
# Switch to main branch
|
||||
if git checkout main 2>/dev/null; then
|
||||
print_status "Successfully switched to main branch"
|
||||
else
|
||||
# If main branch doesn't exist locally, create it from origin/main
|
||||
print_info "Creating local main branch from origin/main..."
|
||||
git fetch origin main
|
||||
git checkout -b main origin/main
|
||||
print_status "Created and switched to main branch"
|
||||
fi
|
||||
else
|
||||
print_info "Already on main branch"
|
||||
fi
|
||||
|
||||
# Backup database first
|
||||
print_info "Creating database backup..."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user