简体   繁体   English

在Windows上的当前提交Visual SVN服务器上从Visual SVN导出更改的文件(PowerShell脚本)

[英]Export the changed files from visual svn on current commit visual svn server on windows (powershell script)

Need to export the changed files from visual svn on current commit visual svn server on windows. 需要从Windows上当前提交的Visual SVN服务器上的Visual SVN导出更改的文件。

I tried using windows power shell script and bat file on post-commit to achieve this. 我尝试在提交后使用Windows Power Shell脚本和bat文件来实现此目的。

I'm new to poswershell scripting. 我是poswershell脚本的新手。

I got the code to export current revision. 我得到了导出当前修订的代码。 It is as follows. 如下。

# 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

It will export the files on the revison on that commit ( $rev ) to F:\\test_live 它将针对该提交( $rev )的$rev文件导出到F:\\test_live

But I need to export only changed files. 但是我只需要导出更改的文件。 Is their any way to do? 他们有什么办法吗?

I think we can achieve thsi by using SVN diff, SVN log commands. 我认为我们可以通过使用SVN diff和SVN log命令来实现。

The bat file I'm using is 我正在使用的蝙蝠文件是

@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

    }
}

Known BUGS : 已知的错误:

  1. folders/file's name with "space" cannot work well 带有“空格”的文件夹/文件名不能正常工作
  2. Delete functionality is not included. 不包括删除功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM