Skip to content

Instantly share code, notes, and snippets.

@hmemcpy
Created December 16, 2014 11:29
Show Gist options
  • Save hmemcpy/3ff5b99bc7886042fa4a to your computer and use it in GitHub Desktop.
Save hmemcpy/3ff5b99bc7886042fa4a to your computer and use it in GitHub Desktop.
Export-SvnDiff
function Export-SvnDiff($repo, $fromRevision, $toRevision, $outputDirectory)
{
$xpath = "/diff/paths/path[@kind='file' and (@item='added' or @item='modified')]"
[xml]$output = & svn diff -r $("{0}:{1}" -f $fromRevision, $toRevision) $repo --summarize --xml
$output | Select-Xml -XPath $xpath | % { $_.node."#text" } | % {
$targetFile = Resolve-FullPath (Join-Path $outputDirectory ($_ -replace $repo))
$targetDir = $targetFile | Split-Path
New-Item -Force -ItemType directory -Path $targetDir | Out-Null
& svn export -r $toRevision -q --force $_ $targetFile
Write-Host ("$_ -> $targetFile")
}
}
@nightroman
Copy link

I have a remark about the used Resolve-FullPath (I was wondering about it). I think it may get a wrong result for paths like \xyz*. In this case IsPathRooted gets true and the function just calls GetFullPath in order to convert \xyz*. Example (note that the second GetFullPath still gets C:\ though in PS the current drive is D:\):

0> [IO.Path]::GetFullPath('\x')
C:\x
0> cd d:
0> [IO.Path]::GetFullPath('\x')
C:\x
0> Get-Location

Path
----
D:\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment