Compare commits

...

2 commits

Author SHA1 Message Date
Christian Wedel
1a4a9c3c36
Merge pull request #7 from soulsites/claude/fix-git-merge-conflict-011CUdWarRj3LNfnRWMKhbWy
Fix git merge conflict by always discarding local changes during sync
2025-10-30 15:09:38 +01:00
Claude
3bbee760ce
Fix git merge conflict by always discarding local changes during sync
When updating plugins, the plugin now always overwrites local changes with the remote version from GitHub:
- Added `git reset --hard` to discard local modifications
- Added `git clean -fd` to remove untracked files
- Changed `git pull` to `git reset --hard @{u}` to avoid merge conflicts
- This ensures the WordPress installation always uses the exact GitHub version

Fixes the error: "Your local changes to the following files would be overwritten by merge"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 14:07:31 +00:00

View file

@ -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) {