![](/img/trans.png)
[英]SVN export files changed since date or revision (Windows svn.exe)
[英]Export the changed files from visual svn on current commit visual svn server on windows (powershell script)
需要从Windows上当前提交的Visual SVN服务器上的Visual SVN导出更改的文件。
我尝试在提交后使用Windows Power Shell脚本和bat文件来实现此目的。
我是poswershell脚本的新手。
我得到了导出当前修订的代码。 如下。
# Store hook arguments into variables with mnemonic names
$repos = $args[0]
$rev = $args[1]
# Build path to svn.exe
$svn = "$env:VISUALSVN_SERVER\bin\svn.exe"
# Build url to repository
$urepos = $repos -replace "\\", "/"
$urepos
$url = "file:///$urepos/"
# Export repository revision $rev to the C:\test folder
&"$svn" export -r $rev --force "$url" F:\test_live
它将针对该提交( $rev
)的$rev
文件导出到F:\\test_live
但是我只需要导出更改的文件。 他们有什么办法吗?
我认为我们可以通过使用SVN diff和SVN log命令来实现。
我正在使用的蝙蝠文件是
@echo off
set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% -command $input ^| %1\hooks\post-commit.ps1 %1 %2
if errorlevel 1 exit %errorlevel%
$repos = "C:\Repositories\siterepo"
$rev = $args[1]
$prev_rev = $rev
$prev_rev -= 1
# Build path to svn.exe
$svn = "$env:VISUALSVN_SERVER\bin\svn.exe"
# Build url to repository
$urepos = $repos -replace "\\", "/"
$urepos
$url = "file:///$urepos/"
$url
$diff_var = &"$svn" diff --summarize -r $rev:$prev_rev $url
$dif_var
$check = "System.String".CompareTo($diff_var.GetType().FullName)
if ($check -eq 0)
{
#"single file"
$source_file = $diff_var.Substring(8)
$source_file
$destination_file = "C:\mywebroot\"+$diff_var.Remove(0,41)
$destination_file
#check directory
$dir_path = Split-Path $destination_file
$dir_path
if ((Test-Path $dir_path) -eq 0)
{
#"folder_not exist"
New-Item -Path $dir_path -Force -ItemType Directory
}
else
{
#"folder exist"
}
&"$svn" export --force $source_file $destination_file
}
else
{
#"multiple files"
$num_files = $diff_var.Length
#"loop"
for ($i=0; $i -lt $num_files; $i++)
{
$source_file = $diff_var[$i].Substring(8)
$source_file
$destination_file = "C:\mywebroot\"+$diff_var[$i].Remove(0,41)
$destination_file
#check directory
$dir_path = Split-Path $destination_file
$dir_path
if ((Test-Path $dir_path) -eq 0)
{
#"folder_not exist"
New-Item -Path $dir_path -Force -ItemType Directory
}
else
{
#"folder exist"
}
&"$svn" export --force $source_file $destination_file
}
}
已知的错误:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.