Last active
June 14, 2025 03:52
-
-
Save HydrangeaPurple/22428425920674ea270b25f7aec99ff8 to your computer and use it in GitHub Desktop.
The SVN generates a diff file for the latest or a specified revision, making it convenient to apply the patch using svn apply. (svn生成最新版本号或者指定版本号的diff文件, 以便于svn apply patch)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Requires Subversion command-line tool (svn.exe) to be installed | |
| # Working directory must be the root of an SVN working copy | |
| param ( | |
| [int]$Revision | |
| ) | |
| # Ensure the current directory is the root of the SVN working copy | |
| try { | |
| # 1. Perform SVN update | |
| $updateResult = svn update 2>&1 | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "SVN update failed: $($updateResult -join "`n")" | |
| } | |
| Write-Host "SVN update successful" -ForegroundColor Green | |
| # 2. Get the latest revision number (if not provided) | |
| if (-not $Revision) { | |
| $log = svn log -l 1 2>&1 | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "Failed to retrieve SVN log: $($log -join "`n")" | |
| } | |
| # Safely extract revision number: match the first line | |
| $log -split "`n" | ForEach-Object { | |
| if (-not $Revision -and $_ -match '^r(?<rev>\d+)') { | |
| $Revision = [int]$matches['rev'] | |
| } | |
| } | |
| if ($Revision) { | |
| Write-Host "Detected latest revision: $Revision" -ForegroundColor Cyan | |
| } else { | |
| throw "No valid revision number found" | |
| } | |
| } else { | |
| Write-Host "Using specified revision: $Revision" -ForegroundColor Cyan | |
| } | |
| # 3. Generate diff file | |
| $diffFile = "diff_$Revision.diff" | |
| Start-Process -NoNewWindow -FilePath "svn" -ArgumentList "diff", "-c", $Revision ` | |
| -RedirectStandardOutput $diffFile -Wait | |
| if (Test-Path $diffFile) { | |
| Write-Host "Diff file generated: $diffFile" -ForegroundColor Green | |
| Invoke-Item $diffFile | |
| } else { | |
| throw "Failed to generate diff file" | |
| } | |
| } | |
| catch { | |
| Write-Host "Error: $_" -ForegroundColor Red | |
| exit 1 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment