diff --git a/advanced-github-plugin-installer.php b/advanced-github-plugin-installer.php index 13e42c8..14612a5 100644 --- a/advanced-github-plugin-installer.php +++ b/advanced-github-plugin-installer.php @@ -342,7 +342,7 @@ function install_update_github_plugin($repo_url, $access_token, $selected_versio // Validate version before checkout if (!empty($selected_version)) { - $update_command = "cd " . escapeshellarg($plugin_dir) . " && git fetch --all && git checkout " . escapeshellarg($selected_version) . " 2>&1"; + $update_command = "cd " . escapeshellarg($plugin_dir) . " && git fetch --all && git reset --hard && git clean -fd && git checkout " . escapeshellarg($selected_version) . " 2>&1"; exec($update_command, $output, $return_var); if ($return_var !== 0) { @@ -354,8 +354,8 @@ function install_update_github_plugin($repo_url, $access_token, $selected_versio wp_die('Failed to update the plugin. Error: ' . implode("\n", $output)); } } else { - // If no version specified, just fetch and pull the default branch - $update_command = "cd " . escapeshellarg($plugin_dir) . " && git fetch --all && git pull 2>&1"; + // If no version specified, just fetch and reset to remote branch (overwrites local changes) + $update_command = "cd " . escapeshellarg($plugin_dir) . " && git fetch origin && git reset --hard @{u} && git clean -fd 2>&1"; exec($update_command, $output, $return_var); if ($return_var !== 0) { @@ -633,7 +633,7 @@ function sync_github_project() { // Update existing plugin - validate version before checkout if (!empty($version)) { - $update_command = "cd " . escapeshellarg($plugin_dir) . " && git fetch --all && git checkout " . escapeshellarg($version) . " 2>&1"; + $update_command = "cd " . escapeshellarg($plugin_dir) . " && git fetch --all && git reset --hard && git clean -fd && git checkout " . escapeshellarg($version) . " 2>&1"; exec($update_command, $output, $return_var); if ($return_var !== 0) { @@ -645,8 +645,8 @@ function sync_github_project() { wp_send_json_error('Synchronisierung fehlgeschlagen: ' . implode("\n", $output)); } } else { - // If no version specified, just fetch and pull the default branch - $update_command = "cd " . escapeshellarg($plugin_dir) . " && git fetch --all && git pull 2>&1"; + // If no version specified, just fetch and reset to remote branch (overwrites local changes) + $update_command = "cd " . escapeshellarg($plugin_dir) . " && git fetch origin && git reset --hard @{u} && git clean -fd 2>&1"; exec($update_command, $output, $return_var); if ($return_var !== 0) {