From dae536e96b9585e0a2fb956944a2a09d0a86ffb5 Mon Sep 17 00:00:00 2001 From: Muhammad Ibrahim Date: Tue, 28 Oct 2025 19:21:11 +0000 Subject: [PATCH] fix: handle non-git installations in update mode - Added fallback to re-initialize git repository if .git directory missing - Automatically detects current version from package.json - Attempts to match to correct release branch - Falls back to main branch if version detection fails - Prevents update failures for legacy installations --- setup.sh | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/setup.sh b/setup.sh index 4bd50a7..c45de2b 100755 --- a/setup.sh +++ b/setup.sh @@ -2918,11 +2918,37 @@ update_installation() { print_info "Installation directory: $instance_dir" print_info "Service name: $service_name" - # Verify it's a git repository + # Verify it's a git repository, if not, initialize it if [ ! -d "$instance_dir/.git" ]; then - print_error "Installation directory is not a git repository" - print_error "Cannot perform git-based update" - exit 1 + print_warning "Installation directory is not a git repository" + print_info "Attempting to re-initialize as git repository..." + + cd "$instance_dir" || exit 1 + + # Initialize git repository + git init + git remote add origin https://github.com/PatchMon/PatchMon.git + + # Fetch all branches + git fetch origin + + # Try to determine current version from package.json or default to main + local current_branch="main" + if [ -f "$instance_dir/backend/package.json" ]; then + local pkg_version=$(grep '"version"' "$instance_dir/backend/package.json" | head -1 | sed 's/.*"version": "\(.*\)".*/\1/') + if [ -n "$pkg_version" ]; then + # Check if there's a release branch for this version + if git ls-remote --heads origin | grep -q "release/$(echo $pkg_version | sed 's/\./-/g')"; then + current_branch="release/$(echo $pkg_version | sed 's/\./-/g')" + fi + fi + fi + + # Reset to the determined branch + git reset --hard "origin/$current_branch" + git checkout -B "$current_branch" "origin/$current_branch" + + print_success "Repository initialized successfully" fi # Add git safe.directory to avoid ownership issues when running as root