diff --git a/.gitea/workflows/gui-version-release.yml b/.gitea/workflows/gui-version-release.yml index bda11f4..7b21599 100644 --- a/.gitea/workflows/gui-version-release.yml +++ b/.gitea/workflows/gui-version-release.yml @@ -472,17 +472,22 @@ jobs: Write-Host "Remote: $REMOTE"; Write-Host ""; - # Unstage to avoid merge conflicts - git reset HEAD config.py version_history.json; - - # FIX: No longer backup files to avoid overwriting user code later - Write-Host "Preparing to pull remote changes..."; + # FIX: Stash local changes before pull to avoid conflicts + Write-Host "Stashing local version changes..."; + git stash push -m "CI-CD-temp-stash" config.py version_history.json; + Write-Host "Pulling remote changes..."; # Pull remote changes (use merge strategy to avoid rebase conflicts) git pull origin $BRANCH --no-rebase; - if ($LASTEXITCODE -ne 0) { - Write-Host "WARNING: Pull failed, attempting manual conflict resolution..."; + # Pop stashed changes back + Write-Host "Restoring version changes..."; + $stashPopResult = git stash pop 2>&1; + $stashPopExitCode = $LASTEXITCODE; + + if ($stashPopExitCode -ne 0) { + Write-Host "WARNING: Stash pop encountered conflicts, resolving..."; + Write-Host "$stashPopResult"; # Check conflict files $conflicts = git diff --name-only --diff-filter=U; @@ -508,16 +513,15 @@ jobs: Write-Host "OK: Resolved version_history.json (using CI/CD version)"; } - # Complete the merge - git commit -m "[skip ci] Merge and update version to v$VERSION" --no-edit --no-verify; + # Drop the stash after resolving + git stash drop 2>$null; } else { - Write-Host "OK: Pull successful"; + Write-Host "OK: Stash pop successful"; - # FIX: Do not overwrite entire file to avoid losing user's new code - # After pull, config.py already contains: - # 1. Version update from CI/CD (gui_version_creator.py) - # 2. User's new code (from remote repository) - # Just add current state, no need to overwrite + # FIX: After stash pop, files are automatically merged + # config.py now contains: + # 1. User's code from remote (from pull) + # 2. Version update from stash (from gui_version_creator.py) Write-Host "Checking if version update is preserved..."; @@ -539,9 +543,15 @@ jobs: # Add current files (includes user code + version update) git add config.py version_history.json; + + Write-Host "Files staged successfully"; } } else { Write-Host "No remote changes, proceeding with commit..."; + + # FIX: Ensure files are staged even if no remote changes + git add config.py version_history.json; + Write-Host "Files staged for commit"; } Write-Host "";